Changed default value for SpamFilters_YourHop
[squirrelmail.git] / functions / tree.php
CommitLineData
59177427 1<?php
245a6892 2
2d367c68 3 /**
7350889b 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$
2d367c68 13 */
a4351446 14
0fc2aca0 15 require_once('../functions/imap.php');
a4351446 16
7350889b 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
a4351446 25 function findParentForChild($value, $treeIndexToStart, $tree) {
8a549df2 26 // is $value in $tree[$treeIndexToStart]['value']
27 if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
41fd4ed4 28 // do I have children, if not then must be a childnode of the current node
8a549df2 29 if ($tree[$treeIndexToStart]['doIHaveChildren']) {
41fd4ed4 30 // loop through each subNode checking to see if we are a subNode of one of them
8a549df2 31 for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++) {
32 $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
8703e429 33 if ($result > -1)
a4351446 34 return $result;
35 }
41fd4ed4 36 // if we aren't a child of one of the subNodes, must be a child of current node
a4351446 37 return $treeIndexToStart;
38 } else
39 return $treeIndexToStart;
40 } else {
41fd4ed4 41 // we aren't a child of this node at all
a4351446 42 return -1;
43 }
44 }
45
abddc974 46 function addChildNodeToTree($comparisonValue, $value, &$tree) {
47 $parentNode = findParentForChild($comparisonValue, 0, $tree);
a4351446 48
49 // create a new subNode
abddc974 50 $newNodeIndex = count($tree);
8a549df2 51 $tree[$newNodeIndex]['value'] = $value;
52 $tree[$newNodeIndex]['doIHaveChildren'] = false;
a4351446 53
8a549df2 54 if ($tree[$parentNode]['doIHaveChildren'] == false) {
a4351446 55 // make sure the parent knows it has children
8a549df2 56 $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
57 $tree[$parentNode]['doIHaveChildren'] = true;
a4351446 58 } else {
8a549df2 59 $nextSubNode = count($tree[$parentNode]['subNodes']);
a4351446 60 // make sure the parent knows it has children
8a549df2 61 $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
a4351446 62 }
63 }
64
294bf31a 65 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
66 global $trash_folder;
8a549df2 67 if ($tree[$index]['doIHaveChildren']) {
68 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
69 walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
294bf31a 70 }
8a549df2 71 if ($tree[$index]['value'] != $trash_folder) {
72 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
294bf31a 73 } else {
74 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
75 if ($numMessages > 0) {
76 sqimap_mailbox_select($imap_stream, $trash_folder);
8a549df2 77 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
8cf653ad 78 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
294bf31a 79 }
80 }
81 } else {
8a549df2 82 if ($tree[$index]['value'] != $trash_folder) {
83 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
294bf31a 84 } else {
85 $numMessages = sqimap_get_num_messages($imap_stream, $trash_folder);
86 if ($numMessages > 0) {
87 sqimap_mailbox_select($imap_stream, $trash_folder);
8a549df2 88 sqimap_messages_flag ($imap_stream, 1, $numMessages, 'Deleted');
8cf653ad 89 sqimap_mailbox_expunge($imap_stream, $trash_folder, true);
294bf31a 90 }
91 }
92 }
93 }
94
a4351446 95 function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
8a549df2 96 if ($tree[$index]['doIHaveChildren']) {
97 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
98 walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
a4351446 99 }
8a549df2 100 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
a4351446 101 } else {
8a549df2 102 sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
a4351446 103 }
104 }
105
525b7ae6 106 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
107 global $trash_folder, $delimiter;
a4351446 108
525b7ae6 109 $position = strrpos($topFolderName, $delimiter) + 1;
8a549df2 110 $subFolderName = substr($tree[$index]['value'], $position);
a4351446 111
8a549df2 112 if ($tree[$index]['doIHaveChildren']) {
525b7ae6 113 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
8a549df2 114 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
a4351446 115
8a549df2 116 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
a4351446 117 if ($messageCount > 0)
525b7ae6 118 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
a4351446 119
8a549df2 120 for ($j = 0;$j < count($tree[$index]['subNodes']); $j++)
525b7ae6 121 walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
a4351446 122 } else {
525b7ae6 123 sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
8a549df2 124 sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
a4351446 125
8a549df2 126 $messageCount = sqimap_get_num_messages($imap_stream, $tree[$index]['value']);
a4351446 127 if ($messageCount > 0)
525b7ae6 128 sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $delimiter . $subFolderName);
a4351446 129 }
130 }
abddc974 131
132 function simpleWalkTreePre($index, $tree) {
8a549df2 133 if ($tree[$index]['doIHaveChildren']) {
134 for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
135 simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
abddc974 136 }
8a549df2 137 echo $tree[$index]['value'] . '<br>';
abddc974 138 } else {
8a549df2 139 echo $tree[$index]['value'] . '<br>';
abddc974 140 }
141 }
525b7ae6 142?>