tags:

views:

34

answers:

1

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.

+1  A: 

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 2359:

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.

Vasu