3e139252a3b261827406b9b9208fa6aac3026768
5 * Copyright (c) 1999-2001 The Squirrelmail Development Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This code provides various string manipulation functions that are
9 * used by the rest of the Squirrelmail code.
14 require_once('../functions/imap.php');
16 // Recursive function to find the correct parent for a new node
17 function findParentForChild($value, $treeIndexToStart, $tree) {
18 // is $value in $tree[$treeIndexToStart]['value']
19 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
20 // do I have children, if not then must be a childnode of the current node
21 if ($tree[$treeIndexToStart]['doIHaveChildren']) {
22 // loop through each subNode checking to see if we are a subNode of one of them
23 for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++
) {
24 $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
28 // if we aren't a child of one of the subNodes, must be a child of current node
29 return $treeIndexToStart;
31 return $treeIndexToStart;
33 // we aren't a child of this node at all
38 function addChildNodeToTree($comparisonValue, $value, &$tree) {
39 $parentNode = findParentForChild($comparisonValue, 0, $tree);
41 // create a new subNode
42 $newNodeIndex = count($tree);
43 $tree[$newNodeIndex]['value'] = $value;
44 $tree[$newNodeIndex]['doIHaveChildren'] = false;
46 if ($tree[$parentNode]['doIHaveChildren'] == false) {
47 // make sure the parent knows it has children
48 $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
49 $tree[$parentNode]['doIHaveChildren'] = true;
51 $nextSubNode = count($tree[$parentNode]['subNodes']);
52 // make sure the parent knows it has children
53 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
57 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
59 if ($tree[$index]['doIHaveChildren']) {
60 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
61 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
63 if ($tree[$index]['value'] != $trash_folder) {
64 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
66 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
67 if ($numMessages > 0) {
68 sqimap_mailbox_select($imap_stream, $trash_folder);
69 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
70 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
74 if ($tree[$index]['value'] != $trash_folder) {
75 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
77 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
78 if ($numMessages > 0) {
79 sqimap_mailbox_select($imap_stream, $trash_folder);
80 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
81 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
87 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
88 if ($tree[$index]['doIHaveChildren']) {
89 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
90 walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
92 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
94 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
98 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
99 global $trash_folder, $delimiter;
101 $position = strrpos($topFolderName, $delimiter) +
1;
102 $subFolderName = substr($tree[$index]['value'], $position);
104 if ($tree[$index]['doIHaveChildren']) {
105 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
106 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
108 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
109 if ($messageCount > 0)
110 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
112 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++
)
113 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
115 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
116 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
118 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
119 if ($messageCount > 0)
120 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
124 function simpleWalkTreePre($index, $tree) {
125 if ($tree[$index]['doIHaveChildren']) {
126 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
127 simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
129 echo $tree[$index]['value'] . '<br>';
131 echo $tree[$index]['value'] . '<br>';