How to determine the UID of a message in IMAP

Emanuel picture Emanuel · Mar 30, 2010 · Viewed 11.9k times · Source

I'm working in a mail client project using C#. I'm using both the POP and IMAP protocol to communicate with the server. The problem is than I can not figure out why when I want to get the UID for a message the result from the POP server and the IMAP server are different.

POP
C: UIDL 1
S: +OK 1 UID2-1269789826

and

IMAP
C: $ FETCH 1 (UID)
S: * 1 FETCH (UID 2)
S: $ OK Fetch completed.

Why the result for obtaining the UID is so different? In IMAP is another function for this? Any help is welcome. Thanks.

Answer

Lukas Pokorny picture Lukas Pokorny · Mar 30, 2010

POP3 and IMAP are two distinct protocols. The UIDs used by these two protocols are not related and are not supposed to be the same at all. In fact, a POP3 UID is an arbitrary string while an IMAP UID is a 32-bit number (transmitted as string).

In theory, it is possible to write a mailserver that supports both IMAP and POP3 use the same UID for both protocols, but I'm not aware of any server that would actually do this. In practice, you have to treat POP3 UIDs and IMAP UIDs as unrelated values.

RFC 1939 (POP3): 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.

RFC 3501 (IMAP): (Unique Identifier (UID) Message Attribute is) 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.