1
votes

I'm working about an email manager that can manage more than one mailboxes. This is my scenario: I get the mails by a mailbox and I store their properties in a database, uid included. The mailbox can be configured to be downloaded with imap or pop3 protocol, it depends on the mailbox itself.

POP3 uids: The unique-id of a message is an arbitrary server-determined string, consisting of one to 70 characters in the range 0x21 to 0x7E, which uniquely identifies a message within a maildrop and which persists across sessions.

IMAP uids: a 32-bit value assigned to each message, which when used with the unique identifier validity value (see below) forms a 64-bit value that MUST NOT refer to any other message in the mailbox or any subsequent mailbox with the same name forever.

So, it is almost impossible to find two equal POP3 uids, although between different mailboxes. But is more likely to happen with IMAP uids.

So, I need the certainty that the uids are all different. I don't need the code to do it, I need only to know if it is possible to do it, and how to do it, the need for a correct reasoning do.

1
Why not store the uid alongside an id that identifies the correction/server/user/etc.Rowland Shaw
The problem is that I can't change the table structure, that it is: timestamp,from,to,cc,subject,body,attachment. Otherwise it would be a good idea. @RowlandShawSamDroid
SO, concatenate an accountid to the UID. <acct #>-<uidvalidity>-<uid>Max

1 Answers

3
votes

The POP3 standard does not guarantee the UIDs to be unique -- you can see different messages with a common UID.

IMAP has no persistent UIDs which would work in the way you want them to work. The UIDs are guaranteed to be unique within a single mailbox, but under certain circumstances they might get changed (see RFC 3501 and the UIDVALIDITY response). In short, the only guarantee that IMAP provides is that a triplet of (mailbox name, UIDVALIDITY, UID) will ever refer to a single message, no matter what happens. This is useful for e.g. caching message parts, because they are guaranteed to be immutable. Please take care to realize that this does not mean that a single message will be always assigned the same triplet -- not at all, even if it remains in the same mailbox.

There are non-standard extensions which attempt to provide some kind of a GUID for you, but these differ between the IMAP server implementations and are not available everywhere.