使用ImapMailbox.php按日期对Imap邮箱进行排序 [英] Sorting Imap mailbox by date using ImapMailbox.php

查看:152
本文介绍了使用ImapMailbox.php按日期对Imap邮箱进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户支持系统,该系统会在收到电子邮件时创建电子邮件.我曾经使用postfix和一种特殊的配置来保留电子邮件以添加其他功能.

I have a customer support system which creates emails when an email is received. I used to postfix and a special configuration to get a hold of the emails to add extra features.

例如,我要包含从电子邮件发送的附件.系统不会执行此操作,但是会创建带有主题的电子邮件,因此我可以通过匹配主题来包含附件.

For example I want to include attachments that were sent from an email. The system doesnt do this , but creates an email with the subject , so I can include the attachments by matching the subjects.

我使用ImapMailBox.php来阅读电子邮件内容. 一切正常,但是获取最后一封电子邮件时遇到问题,因此我从其他任何具有相同主题的电子邮件中获取内容,因此我需要获取最新的电子邮件.

I used ImapMailBox.php to read through the email contents. It all works fine but I am getting an issue fetching the last email, so I am gettign contents from any other email with the same subject , so I need to fetch the latest email.

 $mailboxP = new ImapMailbox('{127.0.0.1:143/novalidate-cert}',POSTFIX_EMAIL,POSTFIX_PASSWORD,ATTACHMENT_DIR, 'utf-8');
 foreach($mailbox->searchMails('ALL') as $mailId)
 $mail = $mailbox->getMail($mailId);
 $mailx=(array)$mail;
 $att=$mailx['attachments'];

我尝试对对象$ mail使用usort,具有这样的功能

I have tried using usort to the object $mail , with a function like this

      function 
     mysort($a,$b) {
    return strtotime($a->date)-strtotime($b->date);

     }

并使用这样的函数添加到数组

and to the array with a function like this

       function mysort($a,$b) {
       return strtotime($a['date'])-strtotime($b['date']);

         }

我也尝试过将imap_sort用于$ mail和$ mailx,但是这些都不起作用. 我遇到的错误

I have also tried using imap_sort to $mail and $mailx , but none of this works. errors I am getting

 imap_sort() expects parameter 1 to be resource, array given
 imap_sort() expects parameter 1 to be resource, object given
 usort() expects parameter 1 to be array, object given
 when passing an array I get undefined index date but it defined ..

任何人都可以请我指出正确的方向吗?

Can anyone please be kind enough to point me in the right direction.

推荐答案

您可以在ImapMailbox.php上添加类似的功能:

You can add a function like this on ImapMailbox.php :

public function searchMailsSorted($imapCriteria = 'ALL') {
            $this->checkConnection();
            $mailsIds =imap_sort($this->mbox,SORTDATE,1,SE_UID,$imapCriteria,$this->serverEncoding);


            return $mailsIds ? $mailsIds : array();
    }      

然后像下面这样在您的代码中使用它:

And then use it in your code like this:

 foreach($mailbox->searchMailsSorted('ALL') as $mailId)
{
 ///insert code here
}

这篇关于使用ImapMailbox.php按日期对Imap邮箱进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆