简体   繁体   中英

Imap_fetch_overview and newest / oldest mail

I am struggling with sequence for imap_fetch_overview. Is the mail 1 the oldest or newest mail? If a new mail arrives does it get a higher id or not?

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,

Each mail will have different ID but there is no higher or lower. 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:

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

then compare this mails using returned dates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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