2014-12-06 64 views
1

我有一點點麻煩,排序在到達自我介紹的郵件,與IMAP類IMAP郵件排序

我有這樣的代碼讓我的郵箱:

$mailbox = new ImapMailbox($hostname,$row["user_email"],$row["user_mail_password"]) 

/* Count mails in $mbox */ 
$mail_count = $mailbox->countMails(); 

/* put the newest emails on top */ 
$mails_sort = $mailbox->sortMails(); 
var_dump($mails_sort); 
/* overview mails in $mbox */ 
$mailsIds = $mailbox->searchMailBox('ALL'); 
var_dump($mailsIds); 

/* get data of mails */ 
$mails = $mailbox->getMailsInfo($mails_sort); 

/* for every email... */ 
foreach ($mails as $mail) { 
    /* Put date result at DateTime constructor*/ 
    $message_date=new DateTime($mail->date); 

    /* output the email header information */ 
    $output.= '<tr class="'.($mail->seen ? 'read' : 'unread').'">'; 
    $output.= '<td class="small-col"><input type="checkbox" /></td>'; 
    $output.= '<td class="small-col"><i class="clickable fa fa-'.($mail->flagged ? 'star' : 'star-o').'"></i></td>'; 
    $output.= '<td class="name"><a href="?page=read-mail&folder='.$mbox.'&uid=' . $mail->uid . '" >' . $mail->from . '</a></td>'; 
    $output.= '<td class="subject"><a href="?page=read-mail&folder='.$mbox.'&uid=' . $mail->uid . '" >' . $mail->subject . '</a></td>'; 
    $output.= '<td class="time">'.$message_date->format("d-m-Y H:i").'</td>'; 
    $output.= '</tr>'; 
} 

當我運行這段代碼我的郵件顯示從舊到新,我想從新到舊的表現出來,

我使用IMAP類從:https://github.com/barbushin/php-imap

有一個函數:

public function sortMails($criteria = SORTARRIVAL, $reverse = true) { 
     return imap_sort($this->getImapStream(), $criteria, $reverse, SE_UID); 
    } 

輸出:$ mails_sort是正確的輸出,所有的UID從新到舊。

的輸出:$ mailsIds是當人的UID的是從舊到新的。

,但它不會顯示我的電子郵件以正確的順序,我覺得我失去了一些東西。

回答

0

只使用foreach循環rsort前一條線($郵件); (''無法連接到郵件服務器:')。print_r(imap_errors()));或者是不能連接到郵件服務器:'print_r(imap_errors())); /*搶電子郵件*/

$mails = imap_search($inbox,'ALL'); // UNSEEN = for unread mail, SEEN = READ mail , ALL = all mail READ as well as UNREAD mail 

    /* if emails are returned, cycle through each... */ 

    rsort($mails); 


    foreach($mails as $key => $value) { 

         // body 
     }