2016-02-26 99 views
1

我在爲imap_fetch_overview的序列掙扎。郵件1是最舊的還是最新的郵件?如果新郵件到達,它是否會得到更高的ID?Imap_fetch_overview和最新/最舊的郵件

解決方案:

$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; 
     } 
    } 
+0

不確定它們是否已排序,請參閱文檔中的'imap_sort()'和相關信息。 – Dave

+0

因此,基於imap_sort我建立一個字符串,我傳遞給imap_fetch_overview? –

+0

您的編輯可能會返回一堆最近的內容,但不一定是在該回報中的順序。這可能是性能折衷。請參閱http://php.net/manual/en/function.imap-fetch-overview.php#88235 – Dave

回答

1

對於問題的第二部分,

看到這個RFC

每封郵件都有不同的ID,但沒有更高或更低。這只是隨意選擇,但獨一無二。

對於你的問題的第一部分,

如果你想找到最老或最新的郵件,你必須使用date方法,如:

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

然後用返回的日期比較這郵件。

相關問題