开发者

Determining the uid of a message appended to a mailbox via 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 beforeha开发者_Go百科nd and I can SEARCH afterwards, but relying on these introduces a race condition as other messages might have been added between these commands.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜