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