5 include("../functions/imap.php");
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++
) {
11 $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
13 echo "parent for $value is : " . $tree[$treeIndexToStart]["subNodes"][$i] . "<br>";
17 return $treeIndexToStart;
19 return $treeIndexToStart;
25 function addChildNodeToTree($comparisonValue, $value, &$tree) {
26 $parentNode = findParentForChild($comparisonValue, 0, $tree);
28 // create a new subNode
29 $newNodeIndex = count($tree);
30 $tree[$newNodeIndex]["value"] = $value;
31 $tree[$newNodeIndex]["doIHaveChildren"] = false;
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;
38 $nextSubNode = count($tree[$parentNode]["subNodes"]);
39 // make sure the parent knows it has children
40 $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex;
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);
49 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
51 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
55 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) {
58 $position = strrpos($topFolderName, $dm) +
1;
59 $subFolderName = substr($tree[$index]["value"], $position);
61 if ($tree[$index]["doIHaveChildren"]) {
62 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
63 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
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);
69 for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++
)
70 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName);
72 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
73 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
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);
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);
86 echo $tree[$index]["value"] . "<br>";
88 echo $tree[$index]["value"] . "<br>";