a4351446 |
1 | <? |
2 | $tree_php = true; |
3 | |
4 | if (!isset($imap_php)) |
5 | include("../functions/imap.php"); |
6 | |
7 | function findParentForChild($value, $treeIndexToStart, $tree) { |
8 | if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) { |
9 | if ($tree[$treeIndexToStart]["doIHaveChildren"]) { |
10 | for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++) { |
abddc974 |
11 | $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree); |
12 | if ($result > -1) { |
13 | echo "parent for $value is : " . $tree[$treeIndexToStart]["subNodes"][$i] . "<br>"; |
a4351446 |
14 | return $result; |
abddc974 |
15 | } |
a4351446 |
16 | } |
17 | return $treeIndexToStart; |
18 | } else |
19 | return $treeIndexToStart; |
20 | } else { |
21 | return -1; |
22 | } |
23 | } |
24 | |
abddc974 |
25 | function addChildNodeToTree($comparisonValue, $value, &$tree) { |
26 | $parentNode = findParentForChild($comparisonValue, 0, $tree); |
a4351446 |
27 | |
28 | // create a new subNode |
abddc974 |
29 | $newNodeIndex = count($tree); |
a4351446 |
30 | $tree[$newNodeIndex]["value"] = $value; |
31 | $tree[$newNodeIndex]["doIHaveChildren"] = false; |
32 | |
33 | if ($tree[$parentNode]["doIHaveChildren"] == false) { |
34 | // make sure the parent knows it has children |
35 | $tree[$parentNode]["subNodes"][0] = $newNodeIndex; |
36 | $tree[$parentNode]["doIHaveChildren"] = true; |
37 | } else { |
38 | $nextSubNode = count($tree[$parentNode]["subNodes"]); |
39 | // make sure the parent knows it has children |
40 | $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex; |
41 | } |
42 | } |
43 | |
44 | function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) { |
45 | if ($tree[$index]["doIHaveChildren"]) { |
46 | for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { |
47 | walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree); |
48 | } |
49 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
50 | } else { |
51 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
52 | } |
53 | } |
54 | |
55 | function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) { |
56 | global $trash_folder; |
57 | |
58 | $position = strrpos($topFolderName, $dm) + 1; |
59 | $subFolderName = substr($tree[$index]["value"], $position); |
60 | |
61 | if ($tree[$index]["doIHaveChildren"]) { |
62 | sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); |
63 | sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); |
64 | |
65 | $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); |
66 | if ($messageCount > 0) |
67 | sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); |
68 | |
69 | for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++) |
70 | walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName); |
71 | } else { |
72 | sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); |
73 | sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); |
74 | |
75 | $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); |
76 | if ($messageCount > 0) |
77 | sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); |
78 | } |
79 | } |
abddc974 |
80 | |
81 | function simpleWalkTreePre($index, $tree) { |
82 | if ($tree[$index]["doIHaveChildren"]) { |
83 | for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { |
84 | simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree); |
85 | } |
86 | echo $tree[$index]["value"] . "<br>"; |
87 | } else { |
88 | echo $tree[$index]["value"] . "<br>"; |
89 | } |
90 | } |
a4351446 |
91 | ?> |