1

是否可以获取未读消息并按日期对消息进行排序?我有

$messages = imap_search($imap,"UNSEEN");
  imap_sort($imap, SORTDATE, 1);

但我想知道它是否不应该

  imap_sort($imap, SORTDATE, 1);
$messages = imap_search($imap,"UNSEEN");

或者是其他东西 ?

4

4 回答 4

1

您可以使用

$messages = imap_search($imap,"UNSEEN");
$sorted = array_reverse($messages);
于 2013-05-21T20:02:28.260 回答
0

这是一个可以帮助您的代码:

$host = '{imap.gmail.com:993/imap/ssl}INBOX';

// Connect to the pop3 email inbox belonging to $user
$con = imap_open("$host", $user, $pass) or die("Can't connect: " . imap_last_error());

// after some sleeping
if (!imap_ping($con)) {
    // do some stuff to reconnect
die("The user is no longer logged in.");
} else {
    echo ('Connection Successful !');
}

$MC = imap_check($con);

// Get the number of emails in inbox
$range = "1:".$MC->Nmsgs; 

// Retrieve the email details of all emails from inbox
$response = imap_fetch_overview($con,$range); 
$response = array_reverse($response);

// displays basic email info such as from, to, date, subject etc...
foreach ($response as $msg) {
    // extra filters to show records which are Unread/Not seen  
    if($msg->seen == "0"  && $msg->recent == "0"){
        echo '<pre>';
        var_dump($msg);
        echo '</pre><br>-----------------------------------------------------<br>';
    }
}

ksort最终,您可以使用功能为日期智能排序或键智能排序设置条件

于 2013-08-15T10:26:39.090 回答
0

如果使用 imap_sort,则不需要使用 imap_search,因为 imap_sort 承认参数 $search_criteria 和 imap_search。假设 imap_sort 类似于 imap_search,但您也可以得到有序的结果。

$messages = imap_sort($imap, SORTDATE, 1, SE_UID, 'UNSEEN');
于 2019-08-28T10:12:07.913 回答
-1

U r 独立地对原始数据集执行两种不同的操作。一种可能的方法是从第一个命令(搜索)中获取所有数据,将其存储在某个变量中,然后实现您自己的排序功能。

于 2013-02-25T04:29:04.363 回答