Comments (22)
The uidnext value is currently a "private" variable, but you can access it via box._uidnext
after opening a mailbox (where 'box' is the value passed in to openBox()'s callback).
The value does not automatically update when new mail arrives because one cannot assume that the uid will necessarily increase by N if N new messages arrive. However, according to this post, it seems you will probably be safe making this assumption in most cases?
from node-imap.
thanks @mscdex ,
If it is updated automatically i guess on 'mail' event we can fetch new messages using Fetch UID currentUIDNext:* instead of search and then fetch.
from node-imap.
I think IMAP's STATUS command gives current UIDNext when we send it but it is not done yet in node-imap :)
from node-imap.
There are a couple of problems with using the STATUS command (especially every time new mail arrives):
- It can be slow
- According to the IMAP RFC 3501: "Note: The STATUS command is intended to access the status of mailboxes other than the currently selected mailbox. Because the STATUS command can cause the mailbox to be opened internally, and because this information is available by other means on the selected mailbox, the STATUS command SHOULD NOT be used on the currently selected mailbox."
Also, regarding fetching "currentUIDNext:*", you cannot assume that the UIDs are contiguous, only that they uniquely identify messages. A better way would be to use sequence numbers instead, which are contiguous where sequence number 1 is the first message in the mailbox. Example:
// var box === currently open mailbox
imap.on('mail', function(num) {
var fetcher = imap.seq.fetch((box.total-num) + ':*', { markSeen: false });
fetcher.on('message', function(msg) {
// do something with msg here
});
fetcher.on('end', function() {
// done obtaining new messages!
});
});
from node-imap.
I didnt know STATUS command has issues. Thanks @mscdex for informing me.
If we fetching using currentUIDNext:* client don't have to assume/worry about sequential of UIDs because of the end of UID range is * so we get any message that has UID larger than currentUIDNext.
Edit: I didnt read the code sample before posting. Thanks for the code I am more clear now. Is box.total updated automatically when new mail received ?
from node-imap.
I checked @imap._state.box.messages.total with a sample and it works as expected, Thanks @mscdex :)
from node-imap.
My mistake, it is box.messages.total
and yes it is updated when new mail arrives and when messages are deleted. Also there is box.messages.new
which always holds the current number of new messages.
from node-imap.
@mscdex, Thanks for your kind support :)
from node-imap.
The linked conversation about contiguous uids is now here: this post
from node-imap.
@mscdex the sequence id changes on move and delete, though, so if I wanted to get the messages that arrived after a specific message, what is the best way to do that ?
from node-imap.
@yoggikim search by date?
from node-imap.
@mscdex date is daily, might return prior emails, isn't it ?
from node-imap.
@yoggikim I'm not sure what you mean. You said you had a specific message, which would have an arrival date associated with it. To get messages that arrived afterwards, do a search for emails that arrived after that date? If your server supports the SORT capability then you could use 'ARRIVAL' criteria which takes time into account also.
from node-imap.
Suppose it doesn't support sort? I could do a search on the date but that would return all the emails after and on that DAY, including emails which arrived BEFORE my given email
from node-imap.
About uids: yahoo has not contiguous uids. What I will do is record the highest uid I know exists in the mailbox and do a search(['ALL', ['UID', '$knownUid:*']])
from node-imap.
On yahoo, if you search for a uid that does not exists, you will fail the server badly sometimes.. :D
from node-imap.
So.. whats the approach I should take? I need to support Yahoo as well.
from node-imap.
Record the highest uid you know exists in the mailbox and then everytime a new message arrives, do search(['ALL', ['UID', '$knownUid:*']])
.
This mean you need to search for all uid in mailbox first when you connect to the server (search(['ALL'])
)
from node-imap.
but @vvo that won't work on yahoo, wont it ?
from node-imap.
No no it will work, what will not work on yahoo is make assumptions that the next uid will be the box.uidnext + 1. It is not true, the next uid will be the highest real uid of the server (which can be different from box.uidnext - 1, don't use it) + *.
So:
Search all uids at connect, keep you local highestuid up to date (based on new message and expunges) and everytime a new mail arrives, do a search highestuidyouknow:*. You will get the new uids.
from node-imap.
My issue is on downtimes and disconnects, otherwise, when I receive an email I just do a search on the exists "total" imap.search([[''+seqno]] and fetch it right after by uid.
Only thing is, why do a search all and not just use uidnext?
from node-imap.
@vvo how to search a single latest uid for specific box?
from node-imap.
Related Issues (20)
- IMAP authentication - what does this error message mean? HOT 5
- Connection not closing after getBoxes execution.
- Error: null Parse command error - What does this error mean?
- German Umlauts or Emoji problem
- js_stream_socket error
- Recent and New not working for outlook account HOT 2
- Invalid credentials (Failure) - Gmail HOT 11
- ECONNREFUSED error while trying to use imap HOT 1
- Search by multiple Message-Id's HOT 1
- Twistlock finds semver CVE-2022-25883 (M)
- Upgrade to Node 18 breaks imap
- Fetch email during antivirus scanning fetches empty body HOT 2
- Examine unsafe login HOT 3
- Support for search criteria OLDER e YOUNGER
- Search getting stuck when new mail recieved
- Filter on history
- does not seem to work with bun HOT 1
- The note view doesn't update when the note has been shared HOT 1
- Issue on event "mail" with outlook only
- Microsoft Outlook 2019 ERROR MESSAGE 503 BAD SEQUESCE OF COMMANDS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-imap.