[dev] Problems with the new IMP_Message functions
Chuck Hagenbuch
chuck@horde.org
Wed, 19 Jun 2002 11:55:19 -0400
Quoting Michael M Slusarz <slusarz@bigworm.colorado.edu>:
> Hmmmmm. I really thought I was only copying/pasting the existing code
> from mailbox.php and message.php to the class. I didn't think I added
> any new calls to sort - the new code _should_ only resort when the old
> code did. But this is exactly one of the reasons why I tried to
> consolidate - so we can catch stuff like this. I will take a look at
> this some more.
If you look at the CVS history of message.php
(http://cvs.horde.org/diff.php/imp/message.php?r1=2.354&r2=2.355&ty=h for
the relevant diff), you'll see that the DELETE_MESSAGE case had a lot nits
accounted for in it.
Part of the problem with the new code is that you've lost the distinction
of the mailbox page and the message page; we don't want to resort on the
message page if we can avoid it, mainly because we might end up with a
message that just arrived showing up somewhere in the sort order that
throws us off. If you were using IMAP, didn't have a trash folder, and had
hide_deleted turned off, then this is the only code that was run after a
message was deleted:
$array_index++;
$index = $sorted[$array_index];
No re-sort. Also note that that's the _only_ case in which we incremented
$array_index; every other time it stays the same, because with either pop3,
a trash folder, or deleted messages hidden, the message you just deleted
has disappeared out of the message set, leaving the array index actually
pointing at the correct next message.
However, with the new code, you call $this->setRange($this->getSortedIndex
()) for every case except the trash folder one. $this->getSortedIndex()
_always_ calls a sorting function.
So, just having thought through all of this, the pseudocode for that bottom
bit of IMP_Message::delete() ought to look something like this:
If we're updating indices:
If things were successful:
If using a trash folder:
remove current message
If using pop3 or hide_deleted:
re-sort (this was in the old code; guess it's needed, but don't
remember why), keep old array index
Otherwise:
increment array index
DON'T re-sort.
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
"What was and what may be, lie, like children whose faces we cannot see, in
the arms of silence. All we ever have is here, now." - Ursula K. Le Guin