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');
20 * Recursive function to find the correct parent for a new node
22 * @copyright 1999-2001 The Squirrelmail Development Team
25 function findParentForChild($value, $treeIndexToStart, $tree) {
26 // is $value in $tree[$treeIndexToStart]['value']
27 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
28 // do I have children, if not then must be a childnode of the current node
29 if ($tree[$treeIndexToStart]['doIHaveChildren']) {
30 // loop through each subNode checking to see if we are a subNode of one of them
31 for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++
) {
32 $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
36 // if we aren't a child of one of the subNodes, must be a child of current node
37 return $treeIndexToStart;
39 return $treeIndexToStart;
41 // we aren't a child of this node at all
46 function addChildNodeToTree($comparisonValue, $value, &$tree) {
47 $parentNode = findParentForChild($comparisonValue, 0, $tree);
49 // create a new subNode
50 $newNodeIndex = count($tree);
51 $tree[$newNodeIndex]['value'] = $value;
52 $tree[$newNodeIndex]['doIHaveChildren'] = false;
54 if ($tree[$parentNode]['doIHaveChildren'] == false) {
55 // make sure the parent knows it has children
56 $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
57 $tree[$parentNode]['doIHaveChildren'] = true;
59 $nextSubNode = count($tree[$parentNode]['subNodes']);
60 // make sure the parent knows it has children
61 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
65 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
67 if ($tree[$index]['doIHaveChildren']) {
68 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
69 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
71 if ($tree[$index]['value'] != $trash_folder) {
72 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
74 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
75 if ($numMessages > 0) {
76 sqimap_mailbox_select($imap_stream, $trash_folder);
77 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
78 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
82 if ($tree[$index]['value'] != $trash_folder) {
83 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
85 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
86 if ($numMessages > 0) {
87 sqimap_mailbox_select($imap_stream, $trash_folder);
88 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
89 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
95 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
96 if ($tree[$index]['doIHaveChildren']) {
97 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
98 walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
100 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
102 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
106 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
107 global $trash_folder, $delimiter;
109 $position = strrpos($topFolderName, $delimiter) +
1;
110 $subFolderName = substr($tree[$index]['value'], $position);
112 if ($tree[$index]['doIHaveChildren']) {
113 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
114 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
116 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
117 if ($messageCount > 0)
118 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
120 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++
)
121 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
123 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
124 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
126 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
127 if ($messageCount > 0)
128 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
132 function simpleWalkTreePre($index, $tree) {
133 if ($tree[$index]['doIHaveChildren']) {
134 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++
) {
135 simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
137 echo $tree[$index]['value'] . '<br>';
139 echo $tree[$index]['value'] . '<br>';