note 87694 modified in function.imap-sort by danbrown

From: Date: Wed, 17 Dec 2008 16:39:57 +0000
Subject: note 87694 modified in function.imap-sort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148272@lists.php.net to get a copy of this message
One thing worth mentioning about imap_sort is that the unique id and message no. changes with the order of the message, so the ids are different if sorted differently and have difficulties to track, the way to get it is using the message->id property: <?php $imap_server = "{mail.netfriending.co.cc/novalidate-cert}"; $imap_user = "user"; $imap_pass = "pass"; $mbox = imap_open("{$imap_server}INBOX", $imap_user, $imap_pass); $original_order = $mbox; //this is important line to add before reordering the messages. $sorted_mbox = imap_sort($mbox, "SORTDATE", 0); $totalrows = imap_num_msg($mbox); $startvalue = 0; while ($startvalue < $totalrows) { $header = imap_header($mbox, $sorted_mbox[$startvalue]); $mid_1 = $header->message_id; $i = 0; while ($i < ($totalrows + 1)) { $header1 = imap_header($original_order, $i); $mid_2 = $header1->message_id; if ($mid_1 == $mid_2) { $id = $i; } $i ++; } // now the ids are store truely & uniquely in the $id variable to call out $startvalue++; } ?> --was-- One thing worth mentioning about imap_sort is that the unique id and message no. changes with the order of the message, so the ids are different if sorted differently and have difficulties to track, the way to get it is using the message->id property: [code]<?php $imap_server = "{mail.netfriending.co.cc/novalidate-cert}"; $imap_user = "user"; $imap_pass = "pass"; $mbox = imap_open("{$imap_server}INBOX", $imap_user, $imap_pass); $original_order = $mbox;//this is important line to add before reordering the messages. $sorted_mbox = imap_sort($mbox, "SORTDATE", 0); $totalrows = imap_num_msg($mbox); $startvalue = 0; while ($startvalue < $totalrows) { $header = imap_header($mbox, $sorted_mbox[$startvalue]); $mid_1 = $header->message_id; $i = 0; while ($i < ($totalrows + 1)) {$header1 = imap_header($original_order, $i); $mid_2 = $header1->message_id; if ($mid_1 == $mid_2) {$id = $i;} $i ++;}//now the ids are store truely & uniquely in the $id variable to call out $startvalue ++;} ?> [/code] http://php.net/manual/en/function.imap-sort.php

« previous php.notes (#148272) next »