About the sequence sorting again.I've found that there's a significant speed improvement by preparing the sequence and then fetch them at once with large mailboxes. On small mailboxes wyou will not notice a speed difference.

But then there's the sorting problem. I've spent all night fiuring out how to do this myself. I found the solution!

Prepare an array of messages with imap_sort. Create a second array that maps the message numbers to the actuall place in the fetched array.You know it will be in numeric order so you can make an array map with the sort() function sorting it from high to low.Then you can proces the array fetched with imap_fetch_overview with the array_map and you will have them sorted. If you need an example look in the Group-Office code classes/imap.class.inc in a version later then 2.04.

Judging from the comments here, it appears like people are forgetting the basics to already-available PHP sorting functions. Use usort(); and the tiniest custom function ever to compare them all.

Change the arguments to imap_fetch_overview to your own, obviously.

<?php$result = imap_fetch_overview($imap_stream, '1:10', 0);

usort($result, function($a, $b) { return($b->udate-$a->udate);});?>

This usort function will look at each overview and order them in the exact latest to oldest message order as determined by the "udate" value for each message. This works. I'm using it. They're sorted in the exact order they appear in my actual inbox. Why obfuscate it any more?