Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically will message number one stay number one under another IMAP session/location?

share|improve this question
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 1 '12 at 13:04
Here's what IMAP RFC has to say about numbering: – Janne Pikkarainen Jun 1 '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 1 '12 at 13:39

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.