8 include("../functions/imap.php");
9 if (!isset($config_php))
10 include("../config/config.php");
12 // Recursive function to find the correct parent for a new node
13 function findParentForChild($value, $treeIndexToStart, $tree) {
14 // is $value in $tree[$treeIndexToStart]["value"]
15 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) {
16 // do I have children, if not then must be a childnode of the current node
17 if ($tree[$treeIndexToStart]["doIHaveChildren"]) {
18 // loop through each subNode checking to see if we are a subNode of one of them
19 for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++
) {
20 $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
24 // if we aren't a child of one of the subNodes, must be a child of current node
25 return $treeIndexToStart;
27 return $treeIndexToStart;
29 // we aren't a child of this node at all
34 function addChildNodeToTree($comparisonValue, $value, &$tree) {
35 $parentNode = findParentForChild($comparisonValue, 0, $tree);
37 // create a new subNode
38 $newNodeIndex = count($tree);
39 $tree[$newNodeIndex]["value"] = $value;
40 $tree[$newNodeIndex]["doIHaveChildren"] = false;
42 if ($tree[$parentNode]["doIHaveChildren"] == false) {
43 // make sure the parent knows it has children
44 $tree[$parentNode]["subNodes"][0] = $newNodeIndex;
45 $tree[$parentNode]["doIHaveChildren"] = true;
47 $nextSubNode = count($tree[$parentNode]["subNodes"]);
48 // make sure the parent knows it has children
49 $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex;
53 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
55 if ($tree[$index]["doIHaveChildren"]) {
56 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
57 walkTreeInPreOrderEmptyTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree);
59 if ($tree[$index]["value"] != $trash_folder) {
60 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
62 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
63 if ($numMessages > 0) {
64 sqimap_mailbox_select($imap_stream, $trash_folder);
65 sqimap_messages_flag ($imap_stream, 1, $numMessages, "Deleted");
66 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
70 if ($tree[$index]["value"] != $trash_folder) {
71 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
73 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
74 if ($numMessages > 0) {
75 sqimap_mailbox_select($imap_stream, $trash_folder);
76 sqimap_messages_flag ($imap_stream, 1, $numMessages, "Deleted");
77 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
83 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
84 if ($tree[$index]["doIHaveChildren"]) {
85 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
86 walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree);
88 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
90 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
94 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) {
97 $position = strrpos($topFolderName, $dm) +
1;
98 $subFolderName = substr($tree[$index]["value"], $position);
100 if ($tree[$index]["doIHaveChildren"]) {
101 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
102 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
104 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
105 if ($messageCount > 0)
106 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
108 for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++
)
109 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName);
111 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
112 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
114 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
115 if ($messageCount > 0)
116 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
120 function simpleWalkTreePre($index, $tree) {
121 if ($tree[$index]["doIHaveChildren"]) {
122 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
123 simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree);
125 echo $tree[$index]["value"] . "<br>";
127 echo $tree[$index]["value"] . "<br>";