From a4351446aa18de718f1db519155807decf17d088 Mon Sep 17 00:00:00 2001 From: nehresma Date: Sat, 4 Mar 2000 21:24:13 +0000 Subject: [PATCH] tree functionality git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@263 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/tree.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 functions/tree.php diff --git a/functions/tree.php b/functions/tree.php new file mode 100644 index 00000000..680b0d04 --- /dev/null +++ b/functions/tree.php @@ -0,0 +1,78 @@ + -1) + return $result; + } + return $treeIndexToStart; + } else + return $treeIndexToStart; + } else { + return -1; + } + } + + function addChildNodeToTree($value, &$tree) { + $parentNode = findParentForChild($value, 0, $tree); + + // create a new subNode + $newNodeIndex = count($tree) + 1; + $tree[$newNodeIndex]["value"] = $value; + $tree[$newNodeIndex]["doIHaveChildren"] = false; + + if ($tree[$parentNode]["doIHaveChildren"] == false) { + // make sure the parent knows it has children + $tree[$parentNode]["subNodes"][0] = $newNodeIndex; + $tree[$parentNode]["doIHaveChildren"] = true; + } else { + $nextSubNode = count($tree[$parentNode]["subNodes"]); + // make sure the parent knows it has children + $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex; + } + } + + function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) { + if ($tree[$index]["doIHaveChildren"]) { + for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { + walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree); + } + sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); + } else { + sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); + } + } + + function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) { + global $trash_folder; + + $position = strrpos($topFolderName, $dm) + 1; + $subFolderName = substr($tree[$index]["value"], $position); + + if ($tree[$index]["doIHaveChildren"]) { + sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); + sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); + + $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); + if ($messageCount > 0) + sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); + + for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++) + walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName); + } else { + sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); + sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); + + $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); + if ($messageCount > 0) + sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); + } + } +?> -- 2.25.1