Patch to show first UNREAD then READ messages on mailbox view
Santiago Romero
sromero@servicom2000.com
Wed, 13 Jun 2001 15:55:12 +0200
Hi!
I needed to change the way the mailbox was displayed on IMP 2.2.5,
so I touched a bit the code to do it. This is supposed to show
first the Unread messages, and later the read messages. Both msg
blocks will be sorted by the current/selected sorting mode.
As it seems to work, I post it here so that people can benefit from
it if someone's looking for something similar under IMP 2.2.x .
Ok, just open horde/imp/mailbox.php3 and look for imap_sort. The
second entry found is:
if ($nummsgs != 0)
$sorted = imap_sort($imp->stream, $imp->sortby, $imp->sortdir, SE_UID);
else $sorted = array();
(etc).
Just change the above by:
if ($nummsgs != 0)
{
// get a sorted view of the imap folder
$sorted = imap_sort($imp->stream, $imp->sortby, $imp->sortdir, SE_UID);
// initialize the message indexes
$readidx = $unreadidx = 0;
// browse all the messages
for( $loop=0; $loop<$nummsgs; $loop++ )
{
// get the message header
$h = @imap_header($imp->stream, imap_msgno($imp->stream, $sorted[$loop]));
// put it on a vector depending on the read status
if( $h->Unseen == 'U' || $h->Recent == 'N' )
{
$unreadvector[$unreadidx] = $sorted[$loop];
$unreadidx++;
}
else
{
$readvector[$readidx] = $sorted[$loop];
$readidx++;
}
}
// merge the two vectors into the original one
for( $loop=0; $loop<$unreadidx; $loop++ )
$sorted[$loop] = $unreadvector[$loop];
for( $loop=0; $loop<$readidx; $loop++ )
$sorted[$loop+$unreadidx] = $readvector[$loop];
}
You must do this also on message.php3, by using num_msgs instead
of nummsgs after the imap_sort on that file (you don't need to
call it another time in the above "pasted" code).
Chuck... do you think I need to put that code too in the EXPUNGE
case of login.php3, or it's not needed? What do you think of the
above, it's compatible with IMP? (I mean, can cause any problem
later?).
PS: The above works, at least for me. Any bug or sugestion will be
welcome also! If someone is interested maybe I can make a patch
that uses a $default->wants_firsts_unread = true/false; and
some if statements...
CU all!
PPS: I know the above code is horribly, I just learnt PHP while
coding it :-)
--
Santiago Romero
Departamento de Sistemas
sromero@servicom2000.com
Av. Primado Reig 189, entlo
46020 Valencia - Spain
Telf. (+34) 96 332 12 00
Fax. (+34) 96 332 12 01
http://www.servicom2000.com