How do I determine the UID of a message which is added via APPEND
to a mailbox? Through STATUS
I can get a prediction of the next value beforehand and I can SEARCH
afterwards, but relying on these introduces a race condition as other messages might have been added between these commands.
An UID is a unique identifier that will not change over time while a message sequence number may change whenever the content of the mailbox changes.
Internally, each IMAP message is assigned a unique ID (UID). MigrationWiz retrieves UIDs from the Source server as a way to implement fast data retrieval. As per RFC 3501 (which defines how the IMAP protocol works), all UIDs must be greater or equal to 1.
Message-ID is a unique identifier for a digital message, most commonly a globally unique identifier used in email and Usenet newsgroups. Message-IDs are required to have a specific format which is a subset of an email address and be globally unique. No two different messages must ever have the same Message-ID.
If you IMAP server supports UIDPLUS, you will always get an APPENDUID
response. This will contain the UID and the validity period for the UID.
Sample syntax from RFC 4315:
S: A003 OK [APPENDUID 38505 3955] APPEND completed
If your mailserver doesnt support UIDPLUS
, you will have to do a FETCH
for the UID, once your append operation is finished. If you are sure that no message was added after the append, go look for the last message in the FETCH
response.
FETCH 1:* (UID)
If you are worried about other messages getting added, you can save an IMAP header like Message-ID before the APPEND
and later use it in the FETCH
operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With