Floris
Floris

Reputation: 309

IMAP mailbox identifier

I'm writing a script that fetches all e-mails from an e-mail address via IMAP.

Currently I'm fetching every folder (mailbox) and saving the highest (fetched) UID from every folder so I start fetching at the highest UID+1 next time I sync. But what if a single folder gets deleted and someone creates a new folder with the same name. The UID is just for a single folder and will be reset.

I can't seem to find any way to find any unique identifier of a mailbox (folder).

Upvotes: 1

Views: 497

Answers (2)

Anshul
Anshul

Reputation: 1436

I would recommend you to store the mail size also corresponding to uids. In case when the max uid stored on your cient is larger than the one returned by server(folder delete case) compare the uid and corresponding mail size.

the idea of fetching the mails from UID+1 itself has got soo many flaws.... What if a certain set of mails has been deleted from server through some other interface(web/pop) or through other client, then how are you going to synchronize it on the imap client??? i assume you would be calling a uid fetch command for that... and if you are doing that then u can compare the uids and mail size for cross verification.

and for better results you can use the concept of UIDVALIDITY also. But you cant rely much on that since i have seen some of imap servers who are not using it to correctly.

Upvotes: 0

Max
Max

Reputation: 10985

This is exactly what UIDVALIDITY is for. This is a 'cookie' which identifies an incarnation of a folder name. It is sent to you when you SELECT a folder. You should save it, and if it changes, you throw out everything you know about that folder.

See RFC 3501 for more detail if you need it.

Upvotes: 2

Related Questions