a4351446 |
1 | <? |
2 | $tree_php = true; |
3 | |
4 | if (!isset($imap_php)) |
5 | include("../functions/imap.php"); |
294bf31a |
6 | if (!isset($config_php)) |
7 | include("../config/config.php"); |
a4351446 |
8 | |
41fd4ed4 |
9 | // Recursive function to find the correct parent for a new node |
a4351446 |
10 | function findParentForChild($value, $treeIndexToStart, $tree) { |
41fd4ed4 |
11 | // is $value in $tree[$treeIndexToStart]["value"] |
a4351446 |
12 | if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) { |
41fd4ed4 |
13 | // do I have children, if not then must be a childnode of the current node |
a4351446 |
14 | if ($tree[$treeIndexToStart]["doIHaveChildren"]) { |
41fd4ed4 |
15 | // loop through each subNode checking to see if we are a subNode of one of them |
a4351446 |
16 | for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++) { |
abddc974 |
17 | $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree); |
8703e429 |
18 | if ($result > -1) |
a4351446 |
19 | return $result; |
20 | } |
41fd4ed4 |
21 | // if we aren't a child of one of the subNodes, must be a child of current node |
a4351446 |
22 | return $treeIndexToStart; |
23 | } else |
24 | return $treeIndexToStart; |
25 | } else { |
41fd4ed4 |
26 | // we aren't a child of this node at all |
a4351446 |
27 | return -1; |
28 | } |
29 | } |
30 | |
abddc974 |
31 | function addChildNodeToTree($comparisonValue, $value, &$tree) { |
32 | $parentNode = findParentForChild($comparisonValue, 0, $tree); |
a4351446 |
33 | |
34 | // create a new subNode |
abddc974 |
35 | $newNodeIndex = count($tree); |
a4351446 |
36 | $tree[$newNodeIndex]["value"] = $value; |
37 | $tree[$newNodeIndex]["doIHaveChildren"] = false; |
38 | |
39 | if ($tree[$parentNode]["doIHaveChildren"] == false) { |
40 | // make sure the parent knows it has children |
41 | $tree[$parentNode]["subNodes"][0] = $newNodeIndex; |
42 | $tree[$parentNode]["doIHaveChildren"] = true; |
43 | } else { |
44 | $nextSubNode = count($tree[$parentNode]["subNodes"]); |
45 | // make sure the parent knows it has children |
46 | $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex; |
47 | } |
48 | } |
49 | |
294bf31a |
50 | function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) { |
51 | global $trash_folder; |
52 | if ($tree[$index]["doIHaveChildren"]) { |
53 | for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { |
54 | walkTreeInPreOrderEmptyTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree); |
55 | } |
56 | if ($tree[$index]["value"] != $trash_folder) { |
57 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
58 | } else { |
59 | $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder); |
60 | if ($numMessages > 0) { |
61 | sqimap_mailbox_select($imap_stream, $trash_folder); |
62 | sqimap_messages_flag ($imap_stream, 1, $numMessages, "Deleted"); |
63 | sqimap_mailbox_expunge($imap_stream, $trash_folder); |
64 | } |
65 | } |
66 | } else { |
67 | if ($tree[$index]["value"] != $trash_folder) { |
68 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
69 | } else { |
70 | $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder); |
71 | if ($numMessages > 0) { |
72 | sqimap_mailbox_select($imap_stream, $trash_folder); |
73 | sqimap_messages_flag ($imap_stream, 1, $numMessages, "Deleted"); |
74 | sqimap_mailbox_expunge($imap_stream, $trash_folder); |
75 | } |
76 | } |
77 | } |
78 | } |
79 | |
a4351446 |
80 | function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) { |
81 | if ($tree[$index]["doIHaveChildren"]) { |
82 | for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { |
83 | walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree); |
84 | } |
85 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
86 | } else { |
87 | sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]); |
88 | } |
89 | } |
90 | |
91 | function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) { |
92 | global $trash_folder; |
93 | |
94 | $position = strrpos($topFolderName, $dm) + 1; |
95 | $subFolderName = substr($tree[$index]["value"], $position); |
96 | |
97 | if ($tree[$index]["doIHaveChildren"]) { |
98 | sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); |
99 | sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); |
100 | |
101 | $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); |
102 | if ($messageCount > 0) |
103 | sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); |
104 | |
105 | for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++) |
106 | walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName); |
107 | } else { |
108 | sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, ""); |
109 | sqimap_mailbox_select($imap_stream, $tree[$index]["value"]); |
110 | |
111 | $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]); |
112 | if ($messageCount > 0) |
113 | sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName); |
114 | } |
115 | } |
abddc974 |
116 | |
117 | function simpleWalkTreePre($index, $tree) { |
118 | if ($tree[$index]["doIHaveChildren"]) { |
119 | for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) { |
120 | simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree); |
121 | } |
122 | echo $tree[$index]["value"] . "<br>"; |
123 | } else { |
124 | echo $tree[$index]["value"] . "<br>"; |
125 | } |
126 | } |
a4351446 |
127 | ?> |