简体   繁体   English

imap Mail与imap类一起排序

[英]Imap Mail sort with imap class

I have a little trouble for sorting mij mails on Arrival, 我在到达时对mij邮件进行排序时遇到了一些麻烦,

i have this code to get my mail : 我有以下代码来获取我的邮件:

$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>';
}

when i run this code my mail is showing from old to new, i want to show it from new to old, 当我运行此代码时,我的邮件从旧到新显示,我想从新到旧显示它,

i am using imap class from : https://github.com/barbushin/php-imap 我正在从以下位置使用imap类: https : //github.com/barbushin/php-imap

there is a function : 有一个功能:

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

The output from : $mails_sort is the correct output, all UID's from new to old. :$ mails_sort的输出是正确的输出,所有UID从新到旧。

The output from : $mailsIds is when al the UID's are from old to new. :$ mailsIds的输出是UID从旧到新的时间。

But it wont show my mails in the correct order, i think i am missing something here. 但是它不会以正确的顺序显示我的邮件,我想我在这里遗漏了一些东西。

just use one line before foreach loop rsort($mails); 仅在foreach循环rsort($ mails)之前使用一行;

$inbox = imap_open($hostname,$username,$password,NULL,1) or die('Cannot connect to Mail Server: ' . print_r(imap_errors())); $ inbox = imap_open($ hostname,$ username,$ password,NULL,1)或die('无法连接到邮件服务器:'。print_r(imap_errors())); /* grab emails */ / *抓电子邮件* /

    $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
      }

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

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