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) {
$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] . "<BR>";
fputs($imapConnection, "1 delete \"$folder\"\n");
$data = imapReadData($imapConnection, "1", false, $response, $message);
if ($response == "NO") {
fputs($imapConnection, "1 LIST \"$mailbox\" *\n");
$data = imapReadData($imapConnection , "1", false, $response, $message);
- echo "DEBUG - data from IMAP \"LIST\" : " . $data[0] . "<BR>\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.
// 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"] . "<BR>";
- }
- }
- // 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", "");
$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)**/
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");
echo "</BODY></HTML>";
?>
-
-