douzhangshao6369 2011-01-01 13:07
浏览 91
已采纳

IMAP:PHP:如何获取和存储用于删除特定邮件的消息号

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

  • 写回答

1条回答 默认 最新

  • dongnao2048 2011-01-01 19:40
    关注

    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:

    1. Identify messages by unique identifier (e.g. by using them as value-attributes on checkboxes that are used to select messages.).
    2. Store the unique identifier validity value of the mailbox as a hidden field in the form.
    3. When processing form submissions, check whether the unique identifier validity value submitted via the form is the same as the current one.
    4. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi