Archived Forum Post

Index of archived forum posts

Question:

Syncing IMAP local copy with server

Jan 03 '13 at 04:00

This is more of a conceptual question.

When working with IMAP I want to be able to have an "offline version" (local copy). I also probably want to do all of the organizing of messages, folders etc locally and eventually "sync" with the server. There must be a standard way of dealing with this in IMAP.

Thanks


Answer

Jack,

Unfortunately, there isn't a standard way of doing what you described. Your app would need to select each folder one-by-one, get a list of local UID's and compare it with the UID's on the server, and then decide which emails to download, upload, or delete, depending on what behavior you desire.


Answer

Thanks for your reply, thought you might say that.

Since I havent really worked with IMAP before please tell me if this would be the correct approach:

I am going to create a local database file that mirrors the folder structure on the server (ie inbox.db) the DB will store the UID of the folder, and the UIDs, subject and body of all previously sync messages in that folder. While this local DB is displayed to the user and the user is working with it, I will download in the background FetchBundle ALL messages in the current folder. I will then update the server with any DB changes and vice-versa using the bundle as my reference. Also when the user changes folders or logs out, I will update the current folder with any changes to either side.

Assuming above is the best approach, then is there a function, or how do I tell if there has been an update to the server since I last cached the bundle?

Also, is there a full offline copy of the ActiveX reference for IMAP I can download (objects, properties, etc)?


Answer

Jack,

You will also need to check UIDValidity for each IMAP mailbox. If UIDValidity changes (it is a 32-bit number), then all server uids should be considered invalid.