2014-11-06 100 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