Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMAP synchronization

Tags:

imap

I'm implementing a IMAP client, and I have a problem with IMAP mailbox synchronization.

First, it is okay to fetch new mails from IMAP server, but I don't know how to find deleted messages from a mailbox.

Should I fetch all messages from the server and compare it with local data to synchronize?

like image 816
Brian Avatar asked Mar 31 '12 13:03

Brian


People also ask

What is IMAP synchronization?

IMAP, which is short for Internet Message Access Protocol, is an email protocol that keeps your email in sync across multiple devices, and lets you access your messages from any computer or mobile device. It's a lot more flexible than POP (Post Office Protocol), which essentially ties you to a single device.

Why is my IMAP not syncing?

Method 1: Check Network Connection An unreliable and poor network connection or firewall settings can obstruct Outlook from synchronizing the mail items stored in the IMAP OST file to the mailbox server. Similarly, if the mailbox server is down, it can prevent Outlook from synchronizing the mail items.

Does IMAP sync with server?

The IMAP protocol supports both online and offline activity. Therefore, messages can be stored both on the local machine and on the server, enabling numerous benefits: Multiple clients can be used to access messages.

Does IMAP sync all folders?

When using an IMAP email account, an IMAP folder list can be downloaded that displays all the folders contained in your account on the mail server. You can then select which folders that you want to subscribe to or view on your computer. In Mail, in the Navigation Pane, right-click the top folder for your IMAP account.


1 Answers

The usual approach is to execute the following two IMAP commands for each folder:

. EXAMINE "<foldername>"
. FETCH 1:* (UID FLAGS)

The first command selects a folder and returns the UIDVALIDITY of this folder. If this value matches the previously returned UIDVALIDITY for this folder, you can rely on the UIDs. The second command returns (at least) the UID and all FLAGS for each mail in the selected folder.

  • You should use the UID to detect which mails have been added or removed. Note that the content of an email can not be changed without also changing the UID.
  • In basic IMAP, the FLAGS are the only attributes that can be changed for an email. The flags contain information about read mails (\Seen) and deleted mails (\Deleted).

This approach is used by many IMAP clients, and most IMAP servers are optimized for them. The limiting factor is usually the available network bandwidth between client and server.

The following situations are a bit more complicated:

  • What should be done if UIDVALIDITY does not match? The IMAP specification requires that servers do their best to avoid unnecessary changes to this value.
  • Should there be an optimization for moved mails (actually copied mails)? In basic IMAP, you can not detect that an email is a copy of another email - regardless whether the email in the source folder still exists or whether it has already been deleted and expunged.
like image 92
nosid Avatar answered Dec 19 '22 21:12

nosid