Deleting "last" message with $imp->sortdir==1

Scott Wallace scott@wallace.sh
Thu, 26 Jul 2001 19:07:05 +1000 (EST)


When in the message view mode (message.php3) and you delete a message AND the 
$imp->sortdir variable is set to 1 it deletes the message and then displays 
the "next" message.

Unforetunately, I read from "the bottom up".  Meaning I have my newer
messages towards the top, and read starting from the oldest messages.

I managed to hack the code to display the "prev" message after hitting
delete...

--- snip! ---
--- message.php3.orig   Thu Jul 26 00:49:50 2001
+++ message.php3        Thu Jul 26 00:47:42 2001
@@ -222,8 +222,13 @@
         if ($index && $imp->mailbox) {
             if (!(@imap_delete($imp->stream, imap_msgno($imp->stream, 
$index)))) {
                 $errormsg = $lang->delete_error;
-                $array_index++;
-                $msgindex++;
+                if ($imp->sortdir == 1) {
+                  $array_index--;
+                  $msgindex--;
+                } else {
+                  $array_index++;
+                  $msgindex++;
+                }
                 $index = $sorted[$array_index];
             } else {
                 if ($imp->servtype == 'pop3') {
@@ -240,8 +245,13 @@
                     $index = $sorted[$array_index];
                     $msgindex = $array_index + $imp->offset;
                 } else {
-                    $array_index++;
-                    $msgindex++;
+                    if ($imp->sortdir == 1) {
+                      $array_index--;
+                      $msgindex--;
+                    } else {
+                      $array_index++;
+                      $msgindex++;
+                    }
                     $index = $sorted[$array_index];
                 }
             }
--- snip! ---

But when you reach message 1 ($array_index=0) and hit delete, then the 
$index=$sorted[$array_index] dies, like it should, because $array_index=-1.

I want to catch it before this stage and simply return you to the inbox view 
(just like when you delete the last message with $imp->sort_dir set to 0).

Make any sense?

Any ideas?

--
Scott.