Fast check if IMAP-Folder has changes

0 votes
asked Dec 21, 2012 by chmav (120 points)
edited Dec 24, 2012

Hi What is the fastest method to check, if there are changes on a mail folder? Is there a hash values over all Messages and when the last hash value is the same like the current, there are no changes to sync. When I load the messages with GetMessageList and check every mail with the local mails in database, it's taking a lot of time. Thunderbird eg is doing that very fast.

Best regards Christoph

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Dec 21, 2012 by Lukas Pokorny (124,970 points)
edited Dec 24, 2012

Most IMAP servers support "next unique ID" feature which makes it possible to retrieve a unique ID to be assigned to the next message to arrive. When a message arrives, this value changes, which makes it possible to use it to determine whether or not to synchronize new messages.

    string nextUniqueId = imap.CurrentFolder.NextUniqueId;

However, this value doesn't change when there are any other changes on the folder, such as messages being deleted. To detect this, the fastest way is to retrieve a list of unique IDs of all messages currently in the folder and check with the local database:

    ImapMessageCollection messageUids = imap.GetMessageList(ImapListFields.UniqueId);

This only retrieves unique IDs of the messages and nothing more, which is usually quite fast (took about 1 second to retrieve 15000 message UIDs from our Exchange server).

commented Dec 21, 2012 by chmav (120 points)
edited Dec 21, 2012

I'm using the fast-Parameter to get also the flags like seen. With this data, i've to check each mail with the database to see, if there are deleted and seen messages. When I would get a folder unique ID, I could check it with the last folder unique ID and when they are equal, nothing has do be done.

commented Dec 24, 2012 by Lukas Pokorny (124,970 points)
edited Dec 24, 2012

The standard IMAP protocol doesn't have such feature. A Quick Mailbox Resynchronization extension exists, but it's not yet supported by Rebex IMAP because the majority of IMAP servers don't support it either. Which IMAP serve do you use? Does it support this extension?