瀏覽代碼

Deleting and creating folders works great!

Luke Ehresman 25 年之前
父節點
當前提交
ba5ed072a5
共有 4 個文件被更改,包括 61 次插入57 次删除
  1. 20 0
      functions/imap.php
  2. 8 31
      src/folders.php
  3. 1 6
      src/folders_create.php
  4. 32 20
      src/folders_delete.php

+ 20 - 0
functions/imap.php

@@ -62,4 +62,24 @@
    function removeFolder($imapConnection, $folder) {
       fputs($imapConnection, "1 delete \"$folder\"\n");
    }
+
+   /** Sends back two arrays, boxesFormatted and boxesUnformatted **/
+   function getFolderList($imapConnection, &$boxesFormatted, &$boxesUnformatted) {
+      fputs($imapConnection, "1 list \"\" *\n");
+      $str = imapReadData($imapConnection);
+
+      for ($i = 0;$i < count($str); $i++) {
+         $mailbox = chop($str[$i]);
+         $mailbox = findMailboxName($mailbox);
+         $periodCount = countCharInString($mailbox, ".");
+
+         // indent the correct number of spaces.
+         for ($j = 0;$j < $periodCount;$j++)
+            $boxesFormatted[$i] = "$boxesFormatted[$i]&nbsp;&nbsp;";
+
+         $boxesFormatted[$i] = $boxesFormatted[$i] . readShortMailboxName($mailbox, ".");
+         $boxesUnformatted[$i] = $mailbox;
+      }
+   }
+
 ?>

+ 8 - 31
src/folders.php

@@ -15,39 +15,19 @@
    echo "</TABLE>\n";
 
    $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
-
-   fputs($imapConnection, "1 list \"\" *\n");
-   $str = imapReadData($imapConnection);
-
-   for ($i = 0;$i < count($str); $i++) {
-      $mailbox = Chop($str[$i]);
-      // find the quote at the begining of the mailbox name.
-      //    i subtract 1 from the strlen so it doesn't find the quote at the end of the mailbox name.
-      $mailbox = findMailboxName($mailbox);
-      $periodCount = countCharInString($mailbox, ".");
-
-      // indent the correct number of spaces.
-      for ($j = 0;$j < $periodCount;$j++)
-         $boxes[$i] = "$boxes[$i]&nbsp;&nbsp;&nbsp;";
-
-      $boxes[$i] = $boxes[$i] . readShortMailboxName($mailbox, ".");
-      $long_name_boxes[$i] = $mailbox;
-   }
+   getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted);
 
    /** DELETING FOLDERS **/
-
    echo "<FORM ACTION=folders_delete.php METHOD=POST>\n";
    echo "<SELECT NAME=mailbox><FONT FACE=\"Arial,Helvetica\">\n";
-   for ($i = 0; $i < count($str); $i++) {
-      $thisbox = Chop($str[$i]);
-      $thisbox = findMailboxName($thisbox);
+   for ($i = 0; $i < count($boxesUnformatted); $i++) {
       $use_folder = true;
       for ($p = 0; $p < count($special_folders); $p++) {
-         if ($special_folders[$p] == $long_name_boxes[$i])
+         if ($special_folders[$p] == $boxesUnformatted[$i])
             $use_folder = false;
       }
       if ($use_folder == true)
-         echo "   <OPTION>$thisbox\n";
+         echo "   <OPTION>$boxesUnformatted[$i]\n";
    }
    echo "</SELECT>\n";
    echo "<INPUT TYPE=SUBMIT VALUE=Delete>\n";
@@ -58,11 +38,8 @@
    echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name>\n";
    echo "&nbsp;&nbsp;as a subfolder of&nbsp;&nbsp;";
    echo "<SELECT NAME=subfolder><FONT FACE=\"Arial,Helvetica\">\n";
-   for ($i = 0;$i < count($str); $i++) {
-      $thisbox = Chop($str[$i]);
-      $thisbox = findMailboxName($thisbox);
-      $thisbox = getFolderNameMinusINBOX($thisbox);
-      echo "<OPTION>$thisbox\n";
+   for ($i = 0;$i < count($boxesUnformatted); $i++) {
+      echo "<OPTION>$boxesUnformatted[$i]\n";
    }
    echo "</SELECT>\n";
    echo "<INPUT TYPE=SUBMIT VALUE=Create>\n";
@@ -71,14 +48,14 @@
    /** RENAMING FOLDERS **/
    echo "<FORM ACTION=folders_rename.php METHOD=POST>\n";
    echo "<SELECT NAME=folder_list><FONT FACE=\"Arial,Helvetica\">\n";
-   for ($i = 0; $i < count($str); $i++) {
+   for ($i = 0; $i < count($boxesUnformatted); $i++) {
       $use_folder = true;
       for ($p = 0; $p < count($special_folders); $p++) {
          if ($special_folders[$p] == $long_name_boxes[$i])
             $use_folder = false;
       }
       if ($use_folder == true)
-         echo "   <OPTION>$boxes[$i]\n";
+         echo "   <OPTION>$boxesUnformatted[$i]\n";
    }
    echo "</SELECT>\n";
    echo "<INPUT TYPE=TEXT SIZE=25 NAME=new_folder_name>\n";

+ 1 - 6
src/folders_create.php

@@ -5,12 +5,7 @@
    include("../functions/imap.php");
 
    $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
-
-   if ($subfolder == "INBOX")
-      fputs($imapConnection, "1 create \"user.$username.$folder_name\"\n");
-   else
-      fputs($imapConnection, "1 create \"user.$username.$subfolder.$folder_name\"\n");
-
+   fputs($imapConnection, "1 create \"$subfolder.$folder_name\"\n");
    fputs($imapConnection, "1 logout\n");
 
    echo "<BR><BR><A HREF=\"folders.php\">Return</A>";

+ 32 - 20
src/folders_delete.php

@@ -6,29 +6,41 @@
    include("../functions/mailbox.php");
 
    $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
-
-   // switch to the mailbox, and get the number of messages in it.
    selectMailbox($imapConnection, $mailbox, $numMessages);
-
-   $folder = getFolderNameMinusINBOX($mailbox);
-   $trash = getFolderNameMinusINBOX($trash_folder);
-
-   /** check if they would like to move it to the trash folder or not */
-   if ($move_to_trash == true) {
-      createFolder($imapConnection, "user.$username.$trash.$folder");
-      echo "CREATING FOLDER:  user.$username.$trash.$folder<BR>";
-      if ($numMessages > 0)
-         $success = copyMessages($imapConnection, 1, $numMessages, $trash_folder);
-      else
-         $success = true;
-
-      if ($success == true)
-         removeFolder($imapConnection, "user.$username.$folder");
-   } else {
-      removeFolder($imapConnection, "user.$username.$folder");
+   getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted);
+
+   /** Lets start removing the folders and messages **/
+   if ($move_to_trash == true) { /** if they wish to move messages to the trash **/
+      /** Creates the subfolders under $trash_folder **/
+      for ($i = 0; $i < count($boxesUnformatted); $i++) {
+         if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) {
+            $folderWithoutINBOX = getFolderNameMinusINBOX($boxesUnformatted[$i]);
+            createFolder($imapConnection, "$trash_folder.$folderWithoutINBOX");
+         }
+      }
+      for ($i = 0; $i < count($boxesUnformatted); $i++) {
+         if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) {
+            selectMailbox($imapConnection, $boxesUnformatted[$i], $numMessages);
+            $folder = getFolderNameMinusINBOX($boxesUnformatted[$i]);
+
+            if ($numMessages > 0)
+               $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder.$folder");
+            else
+               $success = true;
+
+            if ($success == true)
+               removeFolder($imapConnection, "$boxesUnformatted[$i]");
+         }
+      }
+   } else { /** if they do NOT wish to move messages to the trash **/
+      for ($i = 0; $i < count($boxesUnformatted); $i++) {
+         if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) {
+            removeFolder($imapConnection, "$boxesUnformatted[$i]");
+         }
+      }
    }
 
-   // Log out this session
+   /** Log out this session **/
    fputs($imapConnection, "1 logout");
 
    echo "<BR><BR><A HREF=\"folders.php\">Return</A>";