我正在使用 PHP imap_search 来获取自给定日期以来未看到的消息列表,如下所示:
imap_search($stream, 'UNSEEN SINCE 20-Sep-2015');
这工作正常。但是,我会每隔几分钟定期检查新电子邮件,然后将上次检查时间存储在 session 中。我希望能够使用 UNSEEN SINCE 日期(包括时间)运行 imap_search。但这似乎行不通。我试过:
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');
似乎没有任何效果。如果可以做到,有什么想法吗?
最佳答案
查看RFC 3501 中SINCE
的定义| :
SINCE <date>
Messages whose internal date (disregarding time and timezone)
is within or later than the specified date.
date
被定义为只是一个日期,没有时间:
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
根据比一天更具体的时间搜索消息。
另一种方法是记住您最近看到的消息的 UID,然后搜索在其之上的消息:
imap_search($stream, 'UID ' . $latest_uid . ':*', SE_UID);
要使 imap_search
返回 UID 而不是消息序列号,需要 SE_UID
选项。
要首先获取最新消息的 UID,请搜索 *
,它代表邮箱中编号最大的消息:
imap_search($stream, 'UID *', SE_UID);
关于PHP imap_search UNSEEN SINCE 日期与时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32698415/