Basically will message number one stay number one under another IMAP session/location?
-
What are you trying to achieve? Generally yes (at least if I look this at from Cyrus IMAP server standpoint...), but if there's lots of message deletion/addition activity, I would not count on it. – Janne Pikkarainen Jun 01 '12 at 13:04
-
Here's what IMAP RFC has to say about numbering: http://tools.ietf.org/html/rfc3501#section-2.3.1 – Janne Pikkarainen Jun 01 '12 at 13:06
-
Thanks for the link to the rfc. It's clearer now and the fact that the numbers are not generated out of the thin air helps with my case. – tkane Jun 01 '12 at 13:39
1 Answers
The UID will stay the same forever, so long as the UIDVALIDITY doesn't change (it's very rare for UIDVALIDITY to change)
The MSGNO (sequence from 1 to "EXISTS") is local to this specific connection. If you client opens multiple connections, the MSGNO can actually be different in each one.
That said, MSGNO and UID are always both sorted the same way. A higher MSGNO will always map to a higher UID.
Some IMAP commands can cause MSGNO to change - but you will always see an EXPUNGE result telling you which one got removed - all higher numbers decrease by 1 at that point. If new messages get added, you'll get an updated EXISTS as well to tell you how many.
(all this changes if you "ENABLE QRESYNC" and the server supports it - but that's the rules of basic IMAP).
As Janne pointed out in the comments - RFC3501 contains all the gory details about which commands are allowed to change MSGNO, and which have to preserve it, even if some MSGNOs now point to expunged messages.
In short - if you're interacting across different sessions or different connections within the same session, use the UID variants of the commands and you'll be safe.

- 1,738
- 3
- 12
- 15