浏览代码

Fixed some bugs in folder deleting

Luke Ehresman 25 年之前
父节点
当前提交
2fe25cf047
共有 4 个文件被更改,包括 31 次插入11 次删除
  1. 2 1
      functions/imap_mailbox.php
  2. 18 5
      functions/tree.php
  3. 2 2
      src/folders.php
  4. 9 3
      src/folders_delete.php

+ 2 - 1
functions/imap_mailbox.php

@@ -82,9 +82,9 @@
     **  This function simply deletes the given folder
     ******************************************************************************/
    function sqimap_mailbox_delete ($imap_stream, $mailbox) {
-      sqimap_unsubscribe ($imap_stream, $mailbox);
       fputs ($imap_stream, "a001 DELETE \"$mailbox\"\n");
       $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      sqimap_unsubscribe ($imap_stream, $mailbox);
    }
 
 
@@ -118,6 +118,7 @@
                $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . "  ";
             $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
                
+            $boxes[$g]["unformatted-dm"] = $mailbox;
             if (substr($mailbox, -1) == $dm)
                $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
             $boxes[$g]["unformatted"] = $mailbox;

+ 18 - 5
functions/tree.php

@@ -8,9 +8,11 @@
       if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) {
          if ($tree[$treeIndexToStart]["doIHaveChildren"]) {
             for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++) {
-               $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i]);
-               if ($result > -1)
+               $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
+               if ($result > -1) {
+                  echo "parent for $value is : " . $tree[$treeIndexToStart]["subNodes"][$i] . "<br>";
                   return $result;
+               }
             }
             return $treeIndexToStart;
          } else
@@ -20,11 +22,11 @@
       }
    }  
 
-   function addChildNodeToTree($value, &$tree) {
-      $parentNode = findParentForChild($value, 0, $tree);
+   function addChildNodeToTree($comparisonValue, $value, &$tree) {
+      $parentNode = findParentForChild($comparisonValue, 0, $tree);
 
       // create a new subNode
-      $newNodeIndex = count($tree) + 1;
+      $newNodeIndex = count($tree);
       $tree[$newNodeIndex]["value"] = $value;
       $tree[$newNodeIndex]["doIHaveChildren"] = false;
 
@@ -75,4 +77,15 @@
             sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
       }
    }
+
+   function simpleWalkTreePre($index, $tree) {
+      if ($tree[$index]["doIHaveChildren"]) {
+         for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) {
+            simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree);
+         }
+         echo $tree[$index]["value"] . "<br>";
+      } else {
+         echo $tree[$index]["value"] . "<br>";
+      }
+   }
 ?>

+ 2 - 2
src/folders.php

@@ -45,7 +45,7 @@
          }
       }
       if ($use_folder == true) {
-         $box = $boxes[$i]["unformatted"];
+         $box = $boxes[$i]["unformatted-dm"];
          $box2 = replace_spaces($boxes[$i]["formatted"]);
          echo "         <OPTION VALUE=\"$box\">$box2\n";
       }
@@ -75,7 +75,7 @@
 
    for ($i = 0; $i < count($boxes); $i++) {
       for ($j = 0; $j < count($boxes[$i]["flags"]); $j++) {
-         if ($boxes[$i]["flags"][$j] == "noinferiors") {
+         if ($boxes[$i]["flags"][$j] != "noinferiors") {
             if (($boxes[$i]["unformatted"] == $special_folders[0]) && ($default_sub_of_inbox == true)) {
                $box = $boxes[$i]["unformatted"];
                $box2 = replace_spaces($boxes[$i]["formatted"]);

+ 9 - 3
src/folders_delete.php

@@ -27,6 +27,10 @@
    $imap_stream = sqimap_login($username, $key, $imapServerAddress, 0);
    $boxes = sqimap_mailbox_list ($imap_stream);
    $dm = sqimap_get_delimiter($imap_stream);
+   if (substr($mailbox, -1) == $dm)
+      $mailbox_no_dm = substr($mailbox, 0, strlen($mailbox) - 1); 
+   else
+      $mailbox_no_dm = $mailbox;
 
    /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/
    for ($i = 0; $i < count($boxes); $i++) {
@@ -42,7 +46,7 @@
 
    /** First create the top node in the tree **/
    for ($i = 0;$i < count($boxes);$i++) {
-      if (($boxes[$i]["unformatted"] == $mailbox) && (strlen($boxes[$i]["unformatted"]) == strlen($mailbox))) {
+      if (($boxes[$i]["unformatted-dm"] == $mailbox) && (strlen($boxes[$i]["unformatted-dm"]) == strlen($mailbox))) {
          $foldersTree[0]["value"] = $mailbox;
          $foldersTree[0]["doIHaveChildren"] = false;
          continue;
@@ -53,10 +57,12 @@
    //    on the end of the $mailbox string, and compare to that.
    $j = 0;
    for ($i = 0;$i < count($boxes);$i++) {
-      if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox . $dm)) == ($mailbox . $dm)) {
-         addChildNodeToTree($boxes[$i]["unformatted"], $foldersTree);
+      if (substr($boxes[$i]["unformatted"], 0, strlen($mailbox_no_dm . $dm)) == ($mailbox_no_dm . $dm)) {
+//         echo "<B>".$boxes[$i]["unformatted-dm"] . "</b><BR>";
+         addChildNodeToTree($boxes[$i]["unformatted"], $boxes[$i]["unformatted-dm"], $foldersTree);
       }
    }
+//   simpleWalkTreePre(0, $foldersTree);
 
    /** Lets start removing the folders and messages **/
    if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/