There's no such thing as a store message number in IMAP, so I assume you used that term colloquially for any number that uniquely identifies a message. If I'm correct with that assumption, you're out of luck: there's no such number either, at least not across IMAP sessions.
Here's what you can try: the IMAP protocol requires that each message has a unique identifier and each mailbox has a unique identifier validity value. The combination of a unique identifier and the unique identifier validity value of the message's mailbox is guaranteed to never refer to different messages. So if you use that to identify messages, you are at least guaranteed not to accidentally delete the wrong message.
The problem is, the unique identifier validity value is guaranteed to stay the same only for the duration of the IMAP session. PHP usually creates a new IMAP session with every page request and closes the session at the end of the request. On the other hand, the IMAP specification suggests, that unique identifiers stay the same even across sessions. This makes the following approach seem practical:
- Identify messages by unique identifier (e.g. by using them as value-attributes on checkboxes that are used to select messages.).
- Store the unique identifier validity value of the mailbox as a hidden field in the form.
- When processing form submissions, check whether the unique identifier validity value submitted via the form is the same as the current one.
-
Beware: there are IMAP servers, that use a different unique identifier validity value for every session. You won't be able to do anything useful if you happen to have such an implementation.
You can get the current unique identifier validity value by calling imap_mailboxmsginfo. Most other functions from PHP's IMAP extension have a parameter $options
, that you can use specify that you are using the unique identifier instead of the message sequence number (an other means to identify messages, that is even more volatile than the unique identifier).
See RFC 3501 for details about the IMAP protocol, especially 2.3.1 Message Numbers.