Changed default value for SpamFilters_YourHop
[squirrelmail.git] / functions / tree.php
... / ...
CommitLineData
1<?php
2
3 /**
4 * tree.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This code provides various string manipulation functions that are
10 * used by the rest of the Squirrelmail code.
11 *
12 * $Id$
13 */
14
15 require_once('../functions/imap.php');
16
17 /**
18 * findParentForChild
19 *
20 * Recursive function to find the correct parent for a new node
21 *
22 * @copyright 1999-2001 The Squirrelmail Development Team
23 */
24
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);
33 if ($result > -1)
34 return $result;
35 }
36 // if we aren't a child of one of the subNodes, must be a child of current node
37 return $treeIndexToStart;
38 } else
39 return $treeIndexToStart;
40 } else {
41 // we aren't a child of this node at all
42 return -1;
43 }
44 }
45
46 function addChildNodeToTree($comparisonValue, $value, &$tree) {
47 $parentNode = findParentForChild($comparisonValue, 0, $tree);
48
49 // create a new subNode
50 $newNodeIndex = count($tree);
51 $tree[$newNodeIndex]['value'] = $value;
52 $tree[$newNodeIndex]['doIHaveChildren'] = false;
53
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;
58 } else {
59 $nextSubNode = count($tree[$parentNode]['subNodes']);
60 // make sure the parent knows it has children
61 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
62 }
63 }
64
65 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
66 global $trash_folder;
67 if ($tree[$index]['doIHaveChildren']) {
68 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
69 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
70 }
71 if ($tree[$index]['value'] != $trash_folder) {
72 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
73 } else {
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);
79 }
80 }
81 } else {
82 if ($tree[$index]['value'] != $trash_folder) {
83 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
84 } else {
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);
90 }
91 }
92 }
93 }
94
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);
99 }
100 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
101 } else {
102 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
103 }
104 }
105
106 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
107 global $trash_folder, $delimiter;
108
109 $position = strrpos($topFolderName, $delimiter) + 1;
110 $subFolderName = substr($tree[$index]['value'], $position);
111
112 if ($tree[$index]['doIHaveChildren']) {
113 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
114 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
115
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);
119
120 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++)
121 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
122 } else {
123 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
124 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
125
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);
129 }
130 }
131
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);
136 }
137 echo $tree[$index]['value'] . '<br>';
138 } else {
139 echo $tree[$index]['value'] . '<br>';
140 }
141 }
142?>