-// 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"], $dm);
-// }
-// }
-
- // lets remove the trash folder
-// sqimap_mailbox_delete($imapConnection, $mailbox, $dm);
- sqimap_mailbox_create($imapConnection, "$trash_folder", "");
+ /** 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))) {
+ $foldersTree[0]["value"] = $mailbox;
+ $foldersTree[0]["doIHaveChildren"] = false;
+ continue;
+ }
+ }
+ // Now create the nodes for subfolders of the parent folder
+ // You can tell that it is a subfolder by tacking the mailbox delimiter
+ // 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"], $boxes[$i]["unformatted-dm"], $foldersTree);
+ }
+ }
+
+ // now lets go through the tree and delete the folders
+ walkTreeInPreOrderDeleteFolders(0, $imap_stream, $foldersTree);
+ // now lets create a new, fresh trash folder
+ sqimap_mailbox_create($imap_stream, "$trash_folder", "");