removed robust folder deletion. done
[squirrelmail.git] / functions / tree.php
CommitLineData
a4351446 1<?
2 $tree_php = true;
3
4 if (!isset($imap_php))
5 include("../functions/imap.php");
6
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]);
12 if ($result > -1)
13 return $result;
14 }
15 return $treeIndexToStart;
16 } else
17 return $treeIndexToStart;
18 } else {
19 return -1;
20 }
21 }
22
23 function addChildNodeToTree($value, &$tree) {
24 $parentNode = findParentForChild($value, 0, $tree);
25
26 // create a new subNode
27 $newNodeIndex = count($tree) + 1;
28 $tree[$newNodeIndex]["value"] = $value;
29 $tree[$newNodeIndex]["doIHaveChildren"] = false;
30
31 if ($tree[$parentNode]["doIHaveChildren"] == false) {
32 // make sure the parent knows it has children
33 $tree[$parentNode]["subNodes"][0] = $newNodeIndex;
34 $tree[$parentNode]["doIHaveChildren"] = true;
35 } else {
36 $nextSubNode = count($tree[$parentNode]["subNodes"]);
37 // make sure the parent knows it has children
38 $tree[$parentNode]["subNodes"][$nextSubNode] = $newNodeIndex;
39 }
40 }
41
42 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
43 if ($tree[$index]["doIHaveChildren"]) {
44 for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) {
45 walkTreeInPreOrderDeleteFolders($tree[$index]["subNodes"][$j], $imap_stream, $tree);
46 }
47 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
48 } else {
49 sqimap_mailbox_delete($imap_stream, $tree[$index]["value"]);
50 }
51 }
52
53 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $dm, $topFolderName) {
54 global $trash_folder;
55
56 $position = strrpos($topFolderName, $dm) + 1;
57 $subFolderName = substr($tree[$index]["value"], $position);
58
59 if ($tree[$index]["doIHaveChildren"]) {
60 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
61 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
62
63 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
64 if ($messageCount > 0)
65 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
66
67 for ($j = 0;$j < count($tree[$index]["subNodes"]); $j++)
68 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]["subNodes"][$j], $imap_stream, $tree, $dm, $topFolderName);
69 } else {
70 sqimap_mailbox_create($imap_stream, $trash_folder . $dm . $subFolderName, "");
71 sqimap_mailbox_select($imap_stream, $tree[$index]["value"]);
72
73 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]["value"]);
74 if ($messageCount > 0)
75 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
76 }
77 }
78?>