IMAP:PHP:如何获取和存储用于删除特定邮件的邮件号 [英] IMAP : PHP : How can I get and store message number for deleting a particular mail

查看:92
本文介绍了IMAP:PHP:如何获取和存储用于删除特定邮件的邮件号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用IMAP读取服务器邮件收件箱,然后必须在网站上为管理员显示一些邮件(具有预定义内容的邮件),稍后管理员可以从管理面板中删除或转移邮件,但是如何删除还是从管理面板转移特定的邮件?有什么方法可以在邮件中存储消息ID?如何在收件箱中获取特定邮件的ID?

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 ?

非常感谢您的时间

推荐答案

在IMAP中没有存储消息号之类的东西,因此我假设您用通俗的方式将该术语用于唯一标识的数字一个消息.如果我对这个假设是正确的,那您就不走运了:也没有这样的数字,至少在整个IMAP会话中也没有.

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.

这是您可以尝试的方法:IMAP协议要求每个邮件都具有一个唯一标识符,并且每个邮箱都具有一个唯一标识符有效性值.邮件邮箱的唯一标识符唯一标识符有效性值的组合保证不会引用不同的消息.因此,如果使用它来标识消息,则至少可以保证不会意外删除错误的消息.

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.

问题在于,唯一标识符有效性值只能在IMAP会话期间保持不变. PHP通常会为每个页面请求创建一个新的IMAP会话,并在请求结束时关闭该会话.另一方面,IMAP规范建议,即使在会话之间,唯一标识符也保持不变.这使以下方法显得可行:

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. 通过唯一标识符来标识消息(例如,将其用作用于选择消息的复选框的值属性).
  2. 将邮箱的唯一标识符有效性值存储为表单中的隐藏字段.
  3. 在处理表单提交时,请检查通过表单提交的唯一标识符有效性值是否与当前表单相同.
  4. 当心:有些IMAP服务器对每个会话使用不同的唯一标识符有效性值.如果碰巧有这样的实现,您将无法做任何有用的事情.
  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.

您可以通过调用唯一标识符有效性值. "nofollow"> imap_mailboxmsginfo . PHP的IMAP扩展中的大多数其他函数都有一个参数$options,您可以使用该参数指定使用的是唯一标识符,而不是消息序列号(另一种方法来标识消息,它比唯一标识符更易变.)

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).

有关IMAP协议(尤其是)的详细信息,请参见 RFC 3501 . 2.3.1消息编号.

See RFC 3501 for details about the IMAP protocol, especially 2.3.1 Message Numbers.

这篇关于IMAP:PHP:如何获取和存储用于删除特定邮件的邮件号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆