I have to read my server mail inbox using IMAP, then I have to show some mails (mails with predefined contents) in the site for administrator, Later the admin can delete or shift mails from the admin panel, but how can delete or shift a particular mail from the admin panel ? Is there any way to store the message id in the mail ? How can I get the id of a particular mail in the inbox ?
Thanks a lot for your time
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:
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.