6 ** Copyright (c) 1999-2001 The Squirrelmail Development Team
7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
9 ** This code provides various string manipulation functions that are
10 ** used by the rest of the Squirrelmail code.
15 require_once('../functions/imap.php');
17 // Recursive function to find the correct parent for a new node
18 function findParentForChild($value, $treeIndexToStart, $tree) {
19 // is $value in $tree[$treeIndexToStart]['value']
20 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
21 // do I have children, if not then must be a childnode of the current node
22 if ($tree[$treeIndexToStart]['doIHaveChildren']) {
23 // loop through each subNode checking to see if we are a subNode of one of them
24 for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++
) {
25 $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
29 // if we aren't a child of one of the subNodes, must be a child of current node
30 return $treeIndexToStart;
32 return $treeIndexToStart;
34 // we aren't a child of this node at all
39 function addChildNodeToTree($comparisonValue, $value, &$tree) {
40 $parentNode = findParentForChild($comparisonValue, 0, $tree);
42 // create a new subNode
43 $newNodeIndex = count($tree);
44 $tree[$newNodeIndex]['value'] = $value;
45 $tree[$newNodeIndex]['doIHaveChildren'] = false;
47 if ($tree[$parentNode]['doIHaveChildren'] == false) {
48 // make sure the parent knows it has children
49 $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
50 $tree[$parentNode]['doIHaveChildren'] = true;
52 $nextSubNode = count($tree[$parentNode]['subNodes']);
53 // make sure the parent knows it has children
54 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
58 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
60 if ($tree[$index]['doIHaveChildren']) {
61 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
62 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
64 if ($tree[$index]['value'] != $trash_folder) {
65 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
67 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
68 if ($numMessages > 0) {
69 sqimap_mailbox_select($imap_stream, $trash_folder);
70 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
71 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
75 if ($tree[$index]['value'] != $trash_folder) {
76 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
78 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
79 if ($numMessages > 0) {
80 sqimap_mailbox_select($imap_stream, $trash_folder);
81 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
82 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
88 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
89 if ($tree[$index]['doIHaveChildren']) {
90 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
91 walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
93 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
95 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
99 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
100 global $trash_folder, $delimiter;
102 $position = strrpos($topFolderName, $delimiter) +
1;
103 $subFolderName = substr($tree[$index]['value'], $position);
105 if ($tree[$index]['doIHaveChildren']) {
106 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
107 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
109 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
110 if ($messageCount > 0)
111 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
113 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++
)
114 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
116 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
117 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
119 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
120 if ($messageCount > 0)
121 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
125 function simpleWalkTreePre($index, $tree) {
126 if ($tree[$index]['doIHaveChildren']) {
127 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
128 simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
130 echo $tree[$index]['value'] . '<br>';
132 echo $tree[$index]['value'] . '<br>';