5 include("../functions/imap.php");
7 // Recursive function to find the correct parent for a new node
8 function findParentForChild($value, $treeIndexToStart, $tree) {
9 // is $value in $tree[$treeIndexToStart]["value"]
10 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) {
11 // do I have children, if not then must be a childnode of the current node
12 if ($tree[$treeIndexToStart]["doIHaveChildren"]) {
13 // loop through each subNode checking to see if we are a subNode of one of them
14 for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++
) {
15 $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
19 // if we aren't a child of one of the subNodes, must be a child of current node
20 return $treeIndexToStart;
22 return $treeIndexToStart;
24 // we aren't a child of this node at all
29 function addChildNodeToTree($comparisonValue, $value, &$tree) {
30 $parentNode = findParentForChild($comparisonValue, 0, $tree);
32 // create a new subNode
33 $newNodeIndex = count($tree);
34 $tree[$newNodeIndex]["value"] = $value;
35 $tree[$newNodeIndex]["doIHaveChildren"] = false;
37 if ($tree[$parentNode]["doIHaveChildren"] == false) {
38 // make sure the parent knows it has children
39 $tree[$parentNode]["subNodes"][0] = $newNodeIndex;
40 $tree[$parentNode]["doIHaveChildren"] = true;
42 $nextSubNode = count($tree[$parentNode]["subNodes"]);
43 // make sure the parent knows it has children
44 $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex;
48 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
49 if ($tree[$index]["doIHaveChildren"]) {
50 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
51 walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree);
53 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
55 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
59 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) {
62 $position = strrpos($topFolderName, $dm) +
1;
63 $subFolderName = substr($tree[$index]["value"], $position);
65 if ($tree[$index]["doIHaveChildren"]) {
66 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
67 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
69 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
70 if ($messageCount > 0)
71 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
73 for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++
)
74 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName);
76 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
77 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
79 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
80 if ($messageCount > 0)
81 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
85 function simpleWalkTreePre($index, $tree) {
86 if ($tree[$index]["doIHaveChildren"]) {
87 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
88 simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree);
90 echo $tree[$index]["value"] . "<br>";
92 echo $tree[$index]["value"] . "<br>";