Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In our internal webmail system, we'd like to attach notes and contacts to certain mails. In order to do this, we have to keep track of every mail on our IMAP server.

Unfortunately the IMAP standard doesn't enforce the uniqueness of the UID of a mail in a mailbox (just in subfolders). Is there any tool/IMAP server which generates UIDs which are truly unique? Or is there any other way how we can identify each mail? (the Message-ID header field is not unique as some mails do not contain such a field).

Additional resources: Unique ID in IMAP protocol - Limilabs.com

share|improve this question

1 Answer 1

I don't know what you mean when you say UIDs are not unique in a mailbox, just in subfolders. By subfolders, do you mean anything other than INBOX? In any case, it sounds wrong. UIDs are in fact unique within each folder and it doesn't matter it it's INBOX or any other folder.

What can happen is that UIDs can change between sessions. Generally this happens if the IMAP server loses its indexes and has to rebuild them or if the mail is migrated from one IMAP server to another, etc... If this happens then you will of course lose all of the associations between emails and extra data (notes or contacts).

You can rely on this: a UID will never suddenly refer to a different message. Either it will remain valid and refer to the same message it always referred to, or else it will become invalid.

You might want to check out how your particular IMAP server generates and maintains UIDs. Different IMAP servers make different promises about the persistency of UID values. Even within one IMAP server, it may vary depending on which mailbox format is in use. For example, with Dovecot, expect less fragile UIDs with mdbox than with mbox or Maildir because the metadata are more tightly integrated with the actual emails with mdbox.

I suggest using UIDs to refer to messages on the IMAP server, with Message-ID as a backup. Message-ID is not as good because duplicates are possible and (for most IMAP servers) searching by Message-ID might be slower, but it's better than losing track of the messages completely.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.