5 include("../functions/imap.php");
6 if (!isset($config_php))
7 include("../config/config.php");
9 // Recursive function to find the correct parent for a new node
10 function findParentForChild($value, $treeIndexToStart, $tree) {
11 // is $value in $tree[$treeIndexToStart]["value"]
12 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) {
13 // do I have children, if not then must be a childnode of the current node
14 if ($tree[$treeIndexToStart]["doIHaveChildren"]) {
15 // loop through each subNode checking to see if we are a subNode of one of them
16 for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++
) {
17 $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
21 // if we aren't a child of one of the subNodes, must be a child of current node
22 return $treeIndexToStart;
24 return $treeIndexToStart;
26 // we aren't a child of this node at all
31 function addChildNodeToTree($comparisonValue, $value, &$tree) {
32 $parentNode = findParentForChild($comparisonValue, 0, $tree);
34 // create a new subNode
35 $newNodeIndex = count($tree);
36 $tree[$newNodeIndex]["value"] = $value;
37 $tree[$newNodeIndex]["doIHaveChildren"] = false;
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;
44 $nextSubNode = count($tree[$parentNode]["subNodes"]);
45 // make sure the parent knows it has children
46 $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex;
50 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
52 if ($tree[$index]["doIHaveChildren"]) {
53 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
54 walkTreeInPreOrderEmptyTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree);
56 if ($tree[$index]["value"] != $trash_folder) {
57 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
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, true);
64 sqimap_mailbox_close($imap_stream);
68 if ($tree[$index]["value"] != $trash_folder) {
69 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
71 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
72 if ($numMessages > 0) {
73 sqimap_mailbox_select($imap_stream, $trash_folder);
74 sqimap_messages_flag ($imap_stream, 1, $numMessages, "Deleted");
75 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
76 sqimap_mailbox_close($imap_stream);
82 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
83 if ($tree[$index]["doIHaveChildren"]) {
84 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
85 walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree);
87 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
89 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
93 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) {
96 $position = strrpos($topFolderName, $dm) +
1;
97 $subFolderName = substr($tree[$index]["value"], $position);
99 if ($tree[$index]["doIHaveChildren"]) {
100 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
101 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
103 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
104 if ($messageCount > 0)
105 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
107 for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++
)
108 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName);
109 sqimap_mailbox_close($imap_stream);
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);
117 sqimap_mailbox_close($imap_stream);
121 function simpleWalkTreePre($index, $tree) {
122 if ($tree[$index]["doIHaveChildren"]) {
123 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++
) {
124 simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree);
126 echo $tree[$index]["value"] . "<br>";
128 echo $tree[$index]["value"] . "<br>";