reconstructed the left folder list
[squirrelmail.git] / src / empty_trash.php
index ee460ba4e0b37d93aeaf46246b9c0a22960e90eb..ea38697ef29e2de6bcfaa7a7acb3829eef94c51b 100644 (file)
@@ -4,23 +4,9 @@
    include("../functions/strings.php");
    include("../functions/page_header.php");
    include("../functions/display_messages.php");
+   include("../functions/imap.php");
 
-   $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
-   if (!$imapConnection) {
-      echo "Error connecting to IMAP Server.<br>";
-      echo "$errorNumber : $errorString<br>";
-      exit;
-   }
-   $serverInfo = fgets($imapConnection, 256);
-
-   // login
-   fputs($imapConnection, "1 login $username $key\n");
-   $read = fgets($imapConnection, 1024);
-
-   if (strpos($read, "NO")) {
-      error_username_password_incorrect();
-      exit;
-   }
+   $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
 
    // switch to the mailbox, and get the number of messages in it.
    selectMailbox($imapConnection, $mailbox, $numMessages);
       exit;
    }
 
+
+   /** GET FOLDER ARRAY OF TRASH SUBFOLDERS **/
+   fputs($imapConnection, "1 list \"\" *\n");
+   $str = imapReadData($imapConnection);
+
+   for ($i = 0;$i < count($str); $i++) {
+      $box = Chop($str[$i]);
+      $mailbox = findMailboxName($box);
+
+      if (strpos($box, $trash_folder) > 0) {
+         $folders[$i] = $mailbox;
+      } else {
+         $folders[$i] = "NOPE";
+      }
+   }
+
    // mark them as deleted
    setMessageFlag($imapConnection, 1, $numMessages, "Deleted");
    expungeBox($imapConnection, $mailbox);
 
-   // Log out this session
-   fputs($imapConnection, "1 logout");
+   // remove subfolders
+   for ($i = 0; $i < count($folders); $i++) {
+      if (($folders[$i] == "NOPE") || ($folders[$i] == "$trash_folder")) {
+      } else {
+         $thisfolder = getFolderNameMinusINBOX($folders[$i]);
+         $thisfolder = "user.$username.$thisfolder";
+         removeFolder($imapConnection, $thisfolder);
+      }
+   }
 
+   selectMailbox($imapConnection, $trash_folder, $numMessages);
    echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">";
    displayPageHeader($mailbox);
-
-   messages_deleted_message($mailbox, $sort, $startMessage);
-?>
\ No newline at end of file
+   messages_deleted_message($trash_folder, $sort, $startMessage);
+   fputs($imapConnection, "1 logout");
+?>