PHP imap_search based on message UID

冷暖自知 提交于 2021-01-28 01:53:03

问题


Is there any way to search messages on IMAP server, using imap_search function. According to php manual, imap_search allow only limited number of search option, and search by UID is not between them: http://us.php.net/manual/en/function.imap-search.php

So, is there a way around, to get messages based on UID(higher then provided UID). This should be supported since IMAP4 protocol revision(i think since year 2003).


回答1:


I am sure you have gone thru an extensive search and finally landed here. Lets face it, its not possible; but there can be workaround for the feature.

Maybe you can utilise code similar to this:

$imap_stream = imap_open($mailbox, $username, $password);
$msg_no = 1212; //lets say momentarily
while(imap_fetchheader($imap_stream, $msg_no)){
    //do some processing
    $msg_no++;
}// loop will continue till there is no more of newer messages

Be aware that this can cause Maximum Execution Time so you can take in a for loop to do the job with specific number of iteration.

$imap_stream = imap_open($mailbox, $username, $password);
$msg_no = 1212; //lets say
for($i=0;$i<=50;$i++){
if(imap_fetchheader($imap_stream, $msg_no)){
    //do some processing
}
$msg_no++;
} // this will go for 50 times


来源:https://stackoverflow.com/questions/10173041/php-imap-search-based-on-message-uid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!