PHP imap_search UNSEEN SINCE日期和时间 [英] PHP imap_search UNSEEN SINCE date with time

查看:568
本文介绍了PHP imap_search UNSEEN SINCE日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自给定日期以来,我正在使用PHP imap_search来获取未见消息的列表:

I am using PHP imap_search to fetch list of unseen messages since a given date like this:

imap_search($stream, 'UNSEEN SINCE 20-Sep-2015');

这很好.但是,我定期每隔几分钟检查一次新的电子邮件,然后将最后一次检查时间存储在会话中.我希望能够以未知的日期(包括时间)运行imap_search.但这似乎不起作用.我尝试过:

This is working fine. However, I am periodically every few minutes checking for new emails and then storing the last check time in a session. I want to be able to run the imap_search with the UNSEEN SINCE date including time. But it just does not seem to work. I've tried:

imap_search($stream, 'UNSEEN SINCE 20-Sep-2015 12:35:03 +0000 (UTC)');
imap_search($stream, 'UNSEEN SINCE 20-Sep-2015 12:35:03 +0000');
imap_search($stream, 'UNSEEN SINCE 20-Sep-2015 12:35:03');

似乎没有任何作用.有什么想法可以做到吗?

Nothing seems to work. Any ideas if this can be done?

推荐答案

查看SINCE的定义> RFC 3501 :

Looking at the definition of SINCE in RFC 3501:

  SINCE <date>
     Messages whose internal date (disregarding time and timezone)
     is within or later than the specified date.

date被定义为仅一个日期,没有时间:

And a date is defined as just a date, without a time:

date            = date-text / DQUOTE date-text DQUOTE

date-day        = 1*2DIGIT
                    ; Day of month

date-month      = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
                  "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"

date-text       = date-day "-" date-month "-" date-year

date-year       = 4DIGIT

因此,您不能使用SINCE根据比一天更具体的时间来搜索邮件.

So you can't use SINCE to search for messages based on a time more specific than a day.

另一种方法是记住您所看到的最新消息的UID,然后搜索该消息之上的消息:

Another way to do this is to remember the UID of the latest message you've seen, and then search for messages above that:

imap_search($stream, 'UID ' . $latest_uid . ':*', SE_UID);

SE_UID选项是必需的,以使imap_search返回UID而不是消息序列号.

The SE_UID option is required to make imap_search return UIDs instead of message sequence numbers.

要首先获取最新消息的UID,请搜索*,它代表邮箱中编号最高的消息:

To get the UID of the latest message in the first place, search for *, which represents the highest-numbered message in the mailbox:

imap_search($stream, 'UID *', SE_UID);

这篇关于PHP imap_search UNSEEN SINCE日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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