简体   繁体   English

Imap_fetch_overview和最新/最旧的邮件

[英]Imap_fetch_overview and newest / oldest mail

I am struggling with sequence for imap_fetch_overview. 我正在为imap_fetch_overview的序列苦苦挣扎。 Is the mail 1 the oldest or newest mail? 邮件1是最早的邮件还是最新的邮件? If a new mail arrives does it get a higher id or not? 如果收到新邮件,它是否会获得更高的ID?

Solution: 解:

   $check = imap_check($connection);
   $result = array();   

   if($check->Nmsgs > 0){

        $sort = imap_sort($connection, SORTARRIVAL, 0);

        $msgs = '';

        $i = 1;

        foreach($sort as $id)
        {
            if($i > 200) break;
            $msgs = $msgs . $id . ',';
            $i++;
        }

        $response = imap_fetch_overview($connection, rtrim($msgs,','));
        foreach ($response as $msg){
            $result[] = $msg;
        } 
    }

For the second part of the question, 对于问题的第二部分,

see this RFC . 请参阅此RFC

Each mail will have different ID but there is no higher or lower. 每个邮件将具有不同的ID,但没有更高或更低。 It is just rendomly selected but unique. 它只是很少选择,但独特。

For the first part of your question, 对于您的问题的第一部分,

If you want to find oldest or newest mail, you have to use date method like: 如果要查找最早或最新的邮件,则必须使用date方法,例如:

$overview = imap_fetch_overview($connection,$email_number,0);
echo $overview[0]->date;

then compare this mails using returned dates. 然后使用返回的日期比较此邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM