2014-11-06 99 views
0

我正在写一个小的imap类,想要获取在过去一小时内收到的邮件,但找不到解决方案。PHP imap - 获取最近一小时收到的邮件

我发现的imap_search()这是工作,但仅限于日期的可能性:

$date = date ("d M Y", strToTime ("- 1 days")); 
    $this->date = imap_search ($connection, "SINCE \"$date\""); 

在做

$date = date ("d M Y h:i", strToTime ("- 1 hours")); 
    $this->date = imap_search ($connection, "SINCE \"$date\""); 

它给我的examt相同的结果与第一种方法,但不仅仅是过去一小时收到的消息。对于

g 12-hour format of an hour without leading zeros 1 through 12 
G 24-hour format of an hour without leading zeros 0 through 23 
h 12-hour format of an hour with leading zeros 01 through 12 
H 24-hour format of an hour with leading zeros 00 through 23 
i Minutes with leading zeros 00 to 59 
s Seconds, with leading zeros 00 through 59 

同样的结果是否有人知道我能试试吗?

回答

1

IMAP协议不支持基于时间的搜索,只有几天。

你可以做一个基于日期的搜索,然后获取INTERNALDATE,然后选择你想要的。

或者,如果这是一个您每小时都在做的过程,只需跟踪您拥有的最新消息的UID,并获取具有更高UID的任何消息。

+0

谢谢!我也想过UID。我一直在寻找获得它们的最简单方法,你能说出它的名字吗? – baao 2014-11-06 23:50:18

+0

UID搜索UID(lastuidyouhave):* – Max 2014-11-06 23:56:03

+0

太棒了,再次感谢! – baao 2014-11-06 23:56:52