From 7cad62058cda43c39bbdc4ad9b902153bf6148a8 Mon Sep 17 00:00:00 2001 From: nehresma Date: Thu, 17 Feb 2000 17:13:18 +0000 Subject: [PATCH] deleting folders is now recursive and should work more reliably git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@221 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/array.php | 11 ++++++++++ functions/imap.php | 50 ++++++++++++++++++++++-------------------- src/empty_trash.php | 20 ++++++++--------- src/folders_delete.php | 6 ++--- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/functions/array.php b/functions/array.php index 65498fc1..adccf776 100644 --- a/functions/array.php +++ b/functions/array.php @@ -38,4 +38,15 @@ } return $r; } + + function removeElement($array, $element) { + $j = 0; + for ($i = 0;$i < count($array);$i++) + if ($i != $element) { + $newArray[$j] = $array[$i]; + $j++; + } + + return $newArray; + } ?> diff --git a/functions/imap.php b/functions/imap.php index 7d6eb9a4..f2b192ef 100644 --- a/functions/imap.php +++ b/functions/imap.php @@ -56,30 +56,17 @@ return $box; } - /** Finds the delimeter between mailboxes **/ + /** + Finds the delimeter between mailboxes. This should now be more compliant across + different server types that vary in their RFC2060 compliance. + **/ function findMailboxDelimeter($imapConnection) { - fputs($imapConnection, ". list \"\" \"\"\n"); - $read = fgets($imapConnection, 1024); - - if (strrpos($read, "\"") == strlen($read)) { - $pos = strrpos($read, "\""); - $read = substr($read, 0, $pos); - - $pos = strrpos($read, "\""); - $read = substr($read, 0, $pos); - } else { - $pos = strrpos($read, " "); - $read = substr($read, 0, $pos); - } - - $pos = strrpos($read, "\""); - $read = substr($read, 0, $pos); + fputs($imapConnection, ". list \"\" *\n"); + $read = imapReadData($imapConnection, ".", true, $a, $b); + $quotePosition = strpos($read[0], "\""); + $delim = substr($read[0], $quotePosition+1, 1); - $pos = strrpos($read, "\""); - $read = substr($read, $pos+1, strlen($read)); - - $tmp = fgets($imapConnection, 1024); - return $read; + return $delim; } function getMailboxFlags($imapConnection, $mailbox) { @@ -173,10 +160,25 @@ $data = imapReadData($imapConnection, "1", true, $response, $message); } - function removeFolder($imapConnection, $folder) { + /** + This is a recursive function that checks to see if the folder has any subfolders, + and if so, it calls removeFolder on the subfolders first, then removes the parent + folder. + **/ + function removeFolder($imapConnection, $folder, $delimiter) { + global $boxes; + + // bug if there are 2 subfolders of a folder, it won't get to the second one + for ($i = 0; $i < count($boxes); $i++) { + if (strstr($boxes[$i]["UNFORMATTED"], $folder . $delimiter)) { + $newDelete = $boxes[$i]["UNFORMATTED"]; + $boxes = removeElement($boxes, $i); + removeFolder($imapConnection, $newDelete, $boxes, $delimiter); + } + } + fputs ($imapConnection, "1 unsubscribe \"$folder\"\n"); $data = imapReadData($imapConnection, "1", true, $response, $message); - echo $data[0] . "
"; fputs($imapConnection, "1 delete \"$folder\"\n"); $data = imapReadData($imapConnection, "1", false, $response, $message); if ($response == "NO") { diff --git a/src/empty_trash.php b/src/empty_trash.php index d67d7514..4e63c856 100644 --- a/src/empty_trash.php +++ b/src/empty_trash.php @@ -17,8 +17,8 @@ fputs($imapConnection, "1 LIST \"$mailbox\" *\n"); $data = imapReadData($imapConnection , "1", false, $response, $message); - echo "DEBUG - data from IMAP \"LIST\" : " . $data[0] . "
\n"; - + $dm = findMailboxDelimeter($imapConnection); + // According to RFC2060, a DELETE command should NOT remove inferiors (sub folders) // so lets go through the list of subfolders and remove them before removing the // parent. @@ -26,16 +26,16 @@ // and work up. - for ($i = 0; $i < count($boxes); $i++) { +// for ($i = 0; $i < count($boxes); $i++) { // if (($boxes[$i]["UNFORMATTED"] == $mailbox) || // (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { - if (($boxes[$i]["UNFORMATTED"] != $mailbox) && (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { - removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]); - echo "removing " . $boxes[$i]["UNFORMATTED"] . "
"; - } - } - // now lets remove the top level trash folder - removeFolder($imapConnection, $mailbox); +// if (($boxes[$i]["UNFORMATTED"] != $mailbox) && (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { +// removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"], $dm); +// } +// } + + // lets remove the trash folder + removeFolder($imapConnection, $mailbox, $dm); createFolder($imapConnection, "$trash_folder", ""); diff --git a/src/folders_delete.php b/src/folders_delete.php index 812b3352..43ef5ade 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -55,7 +55,7 @@ $success = true; if ($success == true) - removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]); + removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"], $dm); } } } else { /** if they do NOT wish to move messages to the trash (or cannot)**/ @@ -65,7 +65,7 @@ for ($i = 0; $i < count($boxes); $i++) { if (($boxes[$i]["UNFORMATTED"] == $mailbox) || (substr($boxes[$i]["UNFORMATTED"], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { - removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"]); + removeFolder($imapConnection, $boxes[$i]["UNFORMATTED"], $dm); } } fputs($imapConnection, "1 LIST \"$mailbox\" *\n"); @@ -89,5 +89,3 @@ echo ""; ?> - - -- 2.25.1