* Removed sqimap_mailbox_close() function -- automatically expunges mailbox
[squirrelmail.git] / src / move_messages.php
index 8b6a5f543e6d829e4dc15b24480ae77f7754c8f6..cd1056e4e5f06f5fe2023747d4320567a4bdcfbd 100644 (file)
    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
    sqimap_mailbox_select($imapConnection, $mailbox);
 
+   // expunge-on-demand if user isn't using move_to_trash or auto_expunge
+   if($expungeButton) {
+     sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+     $location = get_location();
+     if ($where && $what)
+       header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
+     else   
+       header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
+   }
+   // undelete messages if user isn't using move_to_trash or auto_expunge
+   elseif($undeleteButton) {
+      if (is_array($msg) == 1) {
+         // Removes \Deleted flag from selected messages
+         $j = 0;
+         $i = 0;
+      
+         // If they have selected nothing msg is size one still, but will be an infinite
+         //    loop because we never increment j.  so check to see if msg[0] is set or not to fix this.
+         while ($j < count($msg)) {
+            if ($msg[$i]) {
+              sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
+               $j++;
+            }
+            $i++;
+         }
+         $location = get_location();
+
+         if ($where && $what)
+            header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
+         else   
+            header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
+      } else {
+         displayPageHeader($color, $mailbox);
+         error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
+      }
+   }
    // If the delete button was pressed, the moveButton variable will not be set.
-   if (!$moveButton) {
+   elseif (!$moveButton) {
       if (is_array($msg) == 1) {
          // Marks the selected messages ad 'Deleted'
          $j = 0;
             $i++;
          }
          if ($auto_expunge) {
-            sqimap_mailbox_expunge($imapConnection, $mailbox);
+            sqimap_mailbox_expunge($imapConnection, $mailbox, true);
          }
          $location = get_location();
          if ($where && $what)
             $i++;
          }
          if ($auto_expunge == true)
-            sqimap_mailbox_expunge($imapConnection, $mailbox);
+            sqimap_mailbox_expunge($imapConnection, $mailbox, true);
 
          $location = get_location();
          if ($where && $what)
    }
 
    // Log out this session
-   sqimap_mailbox_close($imapConnection);
    sqimap_logout($imapConnection);
 
 ?>