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

Scott Wallace scott@wallace.sh
Fri, 27 Jul 2001 00:41:19 +1000 (EST)


Okay, so I've got it doing what I want it to do... I will post the diff here 
and you guys can check to make sure it's fine.  I'm no hacker/programmer so I 
may be doing something bad... but it seems to work okay.

You may want to incorporate it into the main tree (after some nice mods by the 
gurus) ... have fun!

BTW... this is from 2.2.4.  I haven't upgraded it yet.  It's a remote server on 
the other side of the planet and too many people use it to have it go down 
because I don't have the right version of Apache (or something).

--- snip! ---

--- message.php3.orig   Thu Jul 26 00:49:50 2001
+++ message.php3        Thu Jul 26 21:16:47 2001
@@ -222,9 +222,14 @@
         if ($index && $imp->mailbox) {
             if (!(@imap_delete($imp->stream, imap_msgno($imp->stream, 
$index)))) {
                 $errormsg = $lang->delete_error;
-                $array_index++;
-                $msgindex++;
-                $index = $sorted[$array_index];
+                if ($imp->sortdir == 1) {
+                  $array_index--;
+                  $msgindex--;
+                } else {
+                  $array_index++;
+                  $msgindex++;
+                }
+                if ($array_index >= 0) $index = $sorted[$array_index];
             } else {
                 if ($imp->servtype == 'pop3') {
                     // expunge the mailbox to actually delete the message, and 
then recalculate the message list
@@ -240,9 +245,14 @@
                     $index = $sorted[$array_index];
                     $msgindex = $array_index + $imp->offset;
                 } else {
-                    $array_index++;
-                    $msgindex++;
-                    $index = $sorted[$array_index];
+                    if ($imp->sortdir == 1) {
+                      $array_index--;
+                      $msgindex--;
+                    } else {
+                      $array_index++;
+                      $msgindex++;
+                    }
+                    if ($array_index >= 0) $index = $sorted[$array_index];
                 }
             }
         }
@@ -305,6 +315,12 @@
   if (isset($structure->parts) && is_array($structure->parts))
     $num_parts = count($structure->parts);
 } else {
+  header('Location: ' . $sess->url('mailbox.php3'));
+  exit;
+}
+
+# Display the INBOX if we delete "off the edge"
+if ($array_index < 0) {
   header('Location: ' . $sess->url('mailbox.php3'));
   exit;
 }

--- snip! ---






> 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! ---
>
> ... blah ...
>
> --- 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.