e9de9f00893502092d39f8a42797a3060298b97d
6 * Copyright (c) 1999-2002 The SquirrelMail Project 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');
20 * Recursive function to find the correct parent for a new node
23 function findParentForChild($value, $treeIndexToStart, $tree) {
24 // is $value in $tree[$treeIndexToStart]['value']
25 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
26 // do I have children, if not then must be a childnode of the current node
27 if ($tree[$treeIndexToStart]['doIHaveChildren']) {
28 // loop through each subNode checking to see if we are a subNode of one of them
29 for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++
) {
30 $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
34 // if we aren't a child of one of the subNodes, must be a child of current node
35 return $treeIndexToStart;
37 return $treeIndexToStart;
39 // we aren't a child of this node at all
44 function addChildNodeToTree($comparisonValue, $value, &$tree) {
45 $parentNode = findParentForChild($comparisonValue, 0, $tree);
47 // create a new subNode
48 $newNodeIndex = count($tree);
49 $tree[$newNodeIndex]['value'] = $value;
50 $tree[$newNodeIndex]['doIHaveChildren'] = false;
52 if ($tree[$parentNode]['doIHaveChildren'] == false) {
53 // make sure the parent knows it has children
54 $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
55 $tree[$parentNode]['doIHaveChildren'] = true;
57 $nextSubNode = count($tree[$parentNode]['subNodes']);
58 // make sure the parent knows it has children
59 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
63 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
65 if ($tree[$index]['doIHaveChildren']) {
66 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
67 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
69 if ($tree[$index]['value'] != $trash_folder) {
70 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
72 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
73 if ($numMessages > 0) {
74 sqimap_mailbox_select($imap_stream, $trash_folder);
75 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
76 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
80 if ($tree[$index]['value'] != $trash_folder) {
81 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
83 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
84 if ($numMessages > 0) {
85 sqimap_mailbox_select($imap_stream, $trash_folder);
86 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
87 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
93 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
94 if ($tree[$index]['doIHaveChildren']) {
95 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
96 walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
98 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
100 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
104 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
105 global $trash_folder, $delimiter;
107 $position = strrpos($topFolderName, $delimiter) +
1;
108 $subFolderName = substr($tree[$index]['value'], $position);
110 if ($tree[$index]['doIHaveChildren']) {
111 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $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 . $delimiter . $subFolderName);
118 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++
)
119 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
121 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
122 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
124 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
125 if ($messageCount > 0)
126 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
130 function simpleWalkTreePre($index, $tree) {
131 if ($tree[$index]['doIHaveChildren']) {
132 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
133 simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
135 echo $tree[$index]['value'] . '<br>';
137 echo $tree[$index]['value'] . '<br>';