squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

tree.php
Go to the documentation of this file.
1 <?php
2 
16 require_once(SM_PATH . 'functions/imap.php');
17 
26 function findParentForChild($value, $treeIndexToStart, $tree) {
27  // is $value in $tree[$treeIndexToStart]['value']
28  if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
29  // do I have children, if not then must be a childnode of the current node
30  if ($tree[$treeIndexToStart]['doIHaveChildren']) {
31  // loop through each subNode checking to see if we are a subNode of one of them
32  for ($i=0;$i< count($tree[$treeIndexToStart]['subNodes']);$i++) {
33  $result = findParentForChild($value, $tree[$treeIndexToStart]['subNodes'][$i], $tree);
34  if ($result > -1)
35  return $result;
36  }
37  // if we aren't a child of one of the subNodes, must be a child of current node
38  return $treeIndexToStart;
39  } else
40  return $treeIndexToStart;
41  } else {
42  // we aren't a child of this node at all
43  return -1;
44  }
45 }
46 
54 function addChildNodeToTree($comparisonValue, $value, &$tree) {
55  $parentNode = findParentForChild($comparisonValue, 0, $tree);
56 
57  // create a new subNode
58  $newNodeIndex = count($tree);
59  $tree[$newNodeIndex]['value'] = $value;
60  $tree[$newNodeIndex]['doIHaveChildren'] = false;
61 
62  if ($tree[$parentNode]['doIHaveChildren'] == false) {
63  // make sure the parent knows it has children
64  $tree[$parentNode]['subNodes'][0] = $newNodeIndex;
65  $tree[$parentNode]['doIHaveChildren'] = true;
66  } else {
67  $nextSubNode = count($tree[$parentNode]['subNodes']);
68  // make sure the parent knows it has children
69  $tree[$parentNode]['subNodes'][$nextSubNode] = $newNodeIndex;
70  }
71 }
72 
81 function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
82  global $trash_folder;
83  if ($tree[$index]['doIHaveChildren']) {
84  for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
85  walkTreeInPreOrderEmptyTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree);
86  }
87  if ($tree[$index]['value'] != $trash_folder) {
88  sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
89  } else {
91  if ($mbx_response['EXISTS'] > 0) {
92  sqimap_messages_flag ($imap_stream, 1, '*', 'Deleted', true);
93  // CLOSE === EXPUNGE and UNSELECT
94  sqimap_run_command($imap_stream,'CLOSE',false,$response,$message);
95  }
96  }
97  } else {
98  if ($tree[$index]['value'] != $trash_folder) {
99  sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
100  } else {
102  if ($mbx_response['EXISTS'] > 0) {
103  sqimap_messages_flag ($imap_stream, 1, '*', 'Deleted', true);
104  // CLOSE === EXPUNGE and UNSELECT
105  sqimap_run_command($imap_stream,'CLOSE',false,$response,$message);
106  }
107  }
108  }
109 }
110 
111 
121  if ($tree[$index]['doIHaveChildren']) {
122  for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
123  walkTreeInPreOrderDeleteFolders($tree[$index]['subNodes'][$j], $imap_stream, $tree);
124  }
125  sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
126  } else {
127  sqimap_mailbox_delete($imap_stream, $tree[$index]['value']);
128  }
129 }
130 
134 function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
135  global $trash_folder, $delimiter;
136 
137  $position = strrpos($topFolderName, $delimiter);
138  if ($position !== FALSE) {
139  $position++;
140  }
141  $subFolderName = substr($tree[$index]['value'], $position);
142 
143  if ($tree[$index]['doIHaveChildren']) {
144  sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
145  $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
146  $messageCount = $mbx_response['EXISTS'];
147  if ($messageCount > 0) {
148  sqimap_msgs_list_copy($imap_stream, '1:*', $trash_folder . $delimiter . $subFolderName);
149  }
150  // after copy close the mailbox to get in unselected state
151  sqimap_run_command($imap_stream,'CLOSE',false,$response,$message);
152  for ($j = 0;$j < count($tree[$index]['subNodes']); $j++)
153  walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
154  } else {
155  sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
156  $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
157  $messageCount = $mbx_response['EXISTS'];
158  if ($messageCount > 0) {
159  sqimap_msgs_list_copy($imap_stream, '1:*', $trash_folder . $delimiter . $subFolderName);
160  }
161  // after copy close the mailbox to get in unselected state
162  sqimap_run_command($imap_stream,'CLOSE',false,$response,$message);
163  }
164 }
165 
172 function simpleWalkTreePre($index, $tree) {
173  if ($tree[$index]['doIHaveChildren']) {
174  for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
175  simpleWalkTreePre($tree[$index]['subNodes'][$j], $tree);
176  }
177  echo $tree[$index]['value'] . '<br />';
178  } else {
179  echo $tree[$index]['value'] . '<br />';
180  }
181 }
findParentForChild
findParentForChild($value, $treeIndexToStart, $tree)
Definition: tree.php:26
$imap_stream
$imap_stream
Definition: bug_report.php:119
walkTreeInPreOrderDeleteFolders
walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree)
Definition: tree.php:120
$trash_folder
$trash_folder
Definition: config_default.php:394
sqimap_mailbox_create
sqimap_mailbox_create($imap_stream, $mailbox, $type)
Definition: imap_mailbox.php:296
walkTreeInPostOrderCreatingFoldersUnderTrash
walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName)
Definition: tree.php:134
walkTreeInPreOrderEmptyTrash
walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree)
Definition: tree.php:81
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$message
$message
Definition: download.php:54
simpleWalkTreePre
simpleWalkTreePre($index, $tree)
Definition: tree.php:172
sqimap_mailbox_delete
sqimap_mailbox_delete($imap_stream, $mailbox)
Definition: imap_mailbox.php:328
sqimap_messages_flag
sqimap_messages_flag($imap_stream, $start, $end, $flag, $handle_errors)
Definition: imap_messages.php:1160
$mbx_response
$mbx_response
Definition: download.php:52
sqimap_msgs_list_copy
sqimap_msgs_list_copy($imap_stream, $id, $mailbox)
Definition: imap_messages.php:30
$j
for($i=0; $i< $numboxes; $i++) $j
Definition: empty_trash.php:72
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
sqimap_run_command
sqimap_run_command($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id=false, $filter=false, $outputstream=false, $no_return=false)
Definition: imap_general.php:58
addChildNodeToTree
addChildNodeToTree($comparisonValue, $value, &$tree)
Definition: tree.php:54