Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the uid of a message appended to a mailbox via IMAP

Tags:

imap

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.

like image 259
pysnake Avatar asked Jan 16 '10 16:01

pysnake


People also ask

What is UID in IMAP?

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.

Is IMAP UID unique?

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.

What is an email UID?

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.


1 Answers

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.

like image 153
Vasu Avatar answered Sep 27 '22 16:09

Vasu