Preparation to begin using phpdocumentor.
[squirrelmail.git] / functions / imap_mailbox.php
CommitLineData
59177427 1<?php
bccadd02 2
35586184 3/**
4 * imap_mailbox.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This impliments all functions that manipulate mailboxes
10 *
11 * $Id$
d6c32258 12 * @package squirrelmail
35586184 13 */
d6c32258 14
15/** UTF7 support */
334a77f8 16require_once(SM_PATH . 'functions/imap_utf7_local.php');
17
3411d4ec 18global $boxesnew;
1da22cda 19
d6c32258 20/**
21 * Mailboxes class
22 *
23 * FIXME. This class should be extracted and placed in a separate file that
24 * can be included before we start the session. That makes caching of the tree
25 * possible. On a refresh mailboxes from left_main.php the only function that
26 * should be called is the sqimap_get_status_mbx_tree. In case of subscribe
27 * / rename / delete / new we have to create methods for adding/changing the
28 * mailbox in the mbx_tree without the need for a refresh.
29 * @package squirrelmail
1eb028a9 30*/
31
60b5724d 32class mailboxes {
86c2763d 33 var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false, $is_noinferiors = false,
ff245fbd 34 $is_special = false, $is_root = false, $is_inbox = false, $is_sent = false,
35 $is_trash = false, $is_draft = false, $mbxs = array(),
36 $unseen = false, $total = false;
37
38 function addMbx($mbx, $delimiter, $start, $specialfirst) {
39 $ary = explode($delimiter, $mbx->mailboxname_full);
ae7df16e 40 $mbx_parent =& $this;
ff245fbd 41 for ($i = $start, $c = count($ary)-1; $i < $c; $i++) {
ae7df16e 42 $mbx_childs =& $mbx_parent->mbxs;
ff245fbd 43 $found = false;
44 if ($mbx_childs) {
45 foreach ($mbx_childs as $key => $parent) {
46 if ($parent->mailboxname_sub == $ary[$i]) {
ae7df16e 47 $mbx_parent =& $mbx_parent->mbxs[$key];
ff245fbd 48 $found = true;
ae7df16e 49 break;
ff245fbd 50 }
51 }
52 }
53 if (!$found) {
54 $no_select_mbx = new mailboxes();
55 if (isset($mbx_parent->mailboxname_full) && $mbx_parent->mailboxname_full != '') {
56 $no_select_mbx->mailboxname_full = $mbx_parent->mailboxname_full.$delimiter.$ary[$i];
57 } else {
58 $no_select_mbx->mailboxname_full = $ary[$i];
59 }
587ec647 60 $no_select_mbx->mailboxname_sub = $ary[$i];
ff245fbd 61 $no_select_mbx->is_noselect = true;
62 $mbx_parent->mbxs[] = $no_select_mbx;
63 $i--;
64 }
65 }
66 $mbx_parent->mbxs[] = $mbx;
67 if ($mbx->is_special && $specialfirst) {
68 usort($mbx_parent->mbxs, 'sortSpecialMbx');
69 }
70 }
60b5724d 71}
72
73function sortSpecialMbx($a, $b) {
74 if ($a->is_inbox) {
ff245fbd 75 $acmp = '0'. $a->mailboxname_full;
60b5724d 76 } else if ($a->is_special) {
ff245fbd 77 $acmp = '1'. $a->mailboxname_full;
60b5724d 78 } else {
ff245fbd 79 $acmp = '2' . $a->mailboxname_full;
80 }
60b5724d 81 if ($b->is_inbox) {
ff245fbd 82 $bcmp = '0'. $b->mailboxname_full;
60b5724d 83 }else if ($b->is_special) {
ff245fbd 84 $bcmp = '1' . $b->mailboxname_full;
60b5724d 85 } else {
ff245fbd 86 $bcmp = '2' . $b->mailboxname_full;
60b5724d 87 }
8edc9f31 88 return user_strcasecmp($acmp, $bcmp);
ff245fbd 89}
60b5724d 90
86c2763d 91function compact_mailboxes_response($ary)
92{
93 /*
94 * Workaround for mailboxes returned as literal
95 * FIXME : Doesn't work if the mailbox name is multiple lines
96 * (larger then fgets buffer)
97 */
98 for ($i = 0, $iCnt=count($ary); $i < $iCnt; $i++) {
99 if (isset($ary[$i + 1]) && substr($ary[$i], -3) == "}\r\n") {
100 if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
101 $ary[$i], $regs)) {
102 $ary[$i] = $regs[1] . '"' . addslashes(trim($ary[$i+1])) . '"' . $regs[2];
103 array_splice($ary, $i+1, 2);
104 }
105 }
106 }
107 /* remove duplicates and ensure array is contiguous */
108 return array_values(array_unique($ary));
109}
110
bac13dd7 111/*
79e07c7e 112function find_mailbox_name ($mailbox) {
d42310bd 113 if (preg_match('/\*.+\"([^\r\n\"]*)\"[\s\r\n]*$/', $mailbox, $regs))
114 return $regs[1];
79e07c7e 115 if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
116 return $regs[1];
117 ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
118 return $regs[1];
f73348a3 119}
bac13dd7 120*/
121
122// Extract the mailbox name from an untagged LIST (7.2.2) or LSUB (7.2.3) answer
123// * (LIST|LSUB) (<Flags list>) (NIL|"<separator atom>") <mailbox name string>\r\n
124// mailbox name in quoted string MUST be unquoted and stripslashed (sm API)
125function find_mailbox_name($line)
126{
127 if (preg_match('/^\* (?:LIST|LSUB) \([^\)]*\) (?:NIL|\"[^\"]*\") ([^\r\n]*)[\r\n]*$/i', $line, $regs)) {
128 if (substr($regs[1], 0, 1) == '"')
129 return stripslashes(substr($regs[1], 1, -1));
130 return $regs[1];
131 }
132 return '';
133}
134
f73348a3 135function check_is_noselect ($lsub_line) {
3698bd49 136 return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noselect[^\)]*\)/i", $lsub_line);
79e07c7e 137}
138
86c2763d 139function check_is_noinferiors ($lsub_line) {
140 return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noinferiors[^\)]*\)/i", $lsub_line);
141}
142
97b1248c 143/**
144 * If $haystack is a full mailbox name, and $needle is the mailbox
145 * separator character, returns the second last part of the full
146 * mailbox name (i.e. the mailbox's parent mailbox)
147 */
148function readMailboxParent($haystack, $needle) {
97b1248c 149 if ($needle == '') {
150 $ret = '';
151 } else {
152 $parts = explode($needle, $haystack);
153 $elem = array_pop($parts);
154 while ($elem == '' && count($parts)) {
155 $elem = array_pop($parts);
156 }
157 $ret = join($needle, $parts);
158 }
159 return( $ret );
160}
161
6a8e7cae 162/**
163 * Check if $subbox is below the specified $parentbox
164 */
165function isBoxBelow( $subbox, $parentbox ) {
cef054e4 166 global $delimiter;
6a8e7cae 167 /*
168 * Eliminate the obvious mismatch, where the
169 * subfolder path is shorter than that of the potential parent
170 */
171 if ( strlen($subbox) < strlen($parentbox) ) {
172 return false;
173 }
cef054e4 174 /* check for delimiter */
175 if (!substr($parentbox,-1) == $delimiter) {
176 $parentbox.=$delimiter;
177 }
178 if (substr($subbox,0,strlen($parentbox)) == $parentbox) {
179 return true;
180 } else {
181 return false;
182 }
1e18bf95 183}
184
3411d4ec 185/* Defines special mailboxes */
1e18bf95 186function isSpecialMailbox( $box ) {
90de1755 187 $ret = ( (strtolower($box) == 'inbox') ||
6a8e7cae 188 isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) );
90de1755 189
2586d588 190 if ( !$ret ) {
5576644b 191 $ret = boolean_hook_function('special_mailbox',$box,1);
2586d588 192 }
3411d4ec 193 return $ret;
90de1755 194}
195
6a8e7cae 196function isTrashMailbox ($box) {
197 global $trash_folder, $move_to_trash;
198 return $move_to_trash && $trash_folder &&
199 ( $box == $trash_folder || isBoxBelow($box, $trash_folder) );
200}
201
202function isSentMailbox($box) {
203 global $sent_folder, $move_to_sent;
204 return $move_to_sent && $sent_folder &&
205 ( $box == $sent_folder || isBoxBelow($box, $sent_folder) );
206}
207
208function isDraftMailbox($box) {
209 global $draft_folder, $save_as_draft;
210 return $save_as_draft &&
211 ( $box == $draft_folder || isBoxBelow($box, $draft_folder) );
212}
213
3411d4ec 214/* Expunges a mailbox */
8f6505f6 215function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
63240b90 216 global $uid_support;
06b5c3ff 217 if ($id) {
ff245fbd 218 if (is_array($id)) {
219 $id = sqimap_message_list_squisher($id);
220 }
221 $id = ' '.$id;
222 $uid = $uid_support;
06b5c3ff 223 } else {
ff245fbd 224 $uid = false;
8f6505f6 225 }
06b5c3ff 226 $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
227 $response, $message, $uid);
63240b90 228 $cnt = 0;
ff245fbd 229
230 if (is_array($read)) {
63240b90 231 foreach ($read as $r) {
ff245fbd 232 if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
233 $cnt++;
234 }
63240b90 235 }
8f6505f6 236 }
ff245fbd 237 return $cnt;
43b698c7 238}
239
3411d4ec 240/* Checks whether or not the specified mailbox exists */
1da22cda 241function sqimap_mailbox_exists ($imap_stream, $mailbox) {
247f700e 242 if (!isset($mailbox) || empty($mailbox)) {
43b698c7 243 return false;
244 }
568cb884 245 $mbx = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 246 true, $response, $message);
43b698c7 247 return isset($mbx[0]);
248}
249
3411d4ec 250/* Selects a mailbox */
e4c6fe41 251function sqimap_mailbox_select ($imap_stream, $mailbox) {
43b698c7 252 global $auto_expunge;
f69feefe 253
ff245fbd 254 if ($mailbox == 'None') {
43b698c7 255 return;
256 }
f69feefe 257
568cb884 258 $read = sqimap_run_command($imap_stream, 'SELECT ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 259 true, $response, $message);
e4c6fe41 260 $result = array();
ff245fbd 261 for ($i = 0, $cnt = count($read); $i < $cnt; $i++) {
e4c6fe41 262 if (preg_match('/^\*\s+OK\s\[(\w+)\s(\w+)\]/',$read[$i], $regs)) {
ff245fbd 263 $result[strtoupper($regs[1])] = $regs[2];
264 } else if (preg_match('/^\*\s([0-9]+)\s(\w+)/',$read[$i], $regs)) {
265 $result[strtoupper($regs[2])] = $regs[1];
266 } else {
267 if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
268 $regs[1]=trim(preg_replace ( array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
269 $result['PERMANENTFLAGS'] = $regs[1];
270 } else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
271 $regs[1]=trim(preg_replace ( array ("/\(/","/\)/") ,'', $regs[1])) ;
272 $result['FLAGS'] = $regs[1];
273 }
274 }
e4c6fe41 275 }
276 if (preg_match('/^\[(.+)\]/',$message, $regs)) {
ff245fbd 277 $result['RIGHTS']=$regs[1];
e4c6fe41 278 }
f69feefe 279
e4c6fe41 280 if ($auto_expunge) {
ff245fbd 281 $tmp = sqimap_run_command($imap_stream, 'EXPUNGE', false, $a, $b);
43b698c7 282 }
e4c6fe41 283 return $result;
43b698c7 284}
285
3411d4ec 286/* Creates a folder */
287function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
43b698c7 288 global $delimiter;
289 if (strtolower($type) == 'noselect') {
3411d4ec 290 $mailbox .= $delimiter;
43b698c7 291 }
e429f014 292
568cb884 293 $read_ary = sqimap_run_command($imap_stream, 'CREATE ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 294 true, $response, $message);
43b698c7 295 sqimap_subscribe ($imap_stream, $mailbox);
296}
297
3411d4ec 298/* Subscribes to an existing folder */
299function sqimap_subscribe ($imap_stream, $mailbox) {
568cb884 300 $read_ary = sqimap_run_command($imap_stream, 'SUBSCRIBE ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 301 true, $response, $message);
43b698c7 302}
303
3411d4ec 304/* Unsubscribes to an existing folder */
305function sqimap_unsubscribe ($imap_stream, $mailbox) {
568cb884 306 $read_ary = sqimap_run_command($imap_stream, 'UNSUBSCRIBE ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 307 true, $response, $message);
43b698c7 308}
309
3411d4ec 310/* Deletes the given folder */
311function sqimap_mailbox_delete ($imap_stream, $mailbox) {
78cc4b12 312 global $data_dir, $username;
568cb884 313 $read_ary = sqimap_run_command($imap_stream, 'DELETE ' . sqimap_encode_mailbox_name($mailbox),
3411d4ec 314 true, $response, $message);
43b698c7 315 sqimap_unsubscribe ($imap_stream, $mailbox);
e429f014 316 do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
78cc4b12 317 removePref($data_dir, $username, "thread_$mailbox");
43b698c7 318}
319
3411d4ec 320/* Determines if the user is subscribed to the folder or not */
1da22cda 321function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
1da22cda 322 $boxesall = sqimap_mailbox_list ($imap_stream);
323 foreach ($boxesall as $ref) {
43b698c7 324 if ($ref['unformatted'] == $folder) {
3411d4ec 325 return true;
43b698c7 326 }
327 }
328 return false;
329}
330
3411d4ec 331/* Renames a mailbox */
1c52ba77 332function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
3411d4ec 333 if ( $old_name != $new_name ) {
78cc4b12 334 global $delimiter, $imap_server_type, $data_dir, $username;
1c52ba77 335 if ( substr( $old_name, -1 ) == $delimiter ) {
336 $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
337 $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 );
338 $postfix = $delimiter;
1c52ba77 339 } else {
340 $postfix = '';
1c52ba77 341 }
68f2ce7a 342
648713af 343 $boxesall = sqimap_mailbox_list($imap_stream);
568cb884 344 $cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) . ' ' . sqimap_encode_mailbox_name($new_name);
3411d4ec 345 $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
1c52ba77 346 sqimap_unsubscribe($imap_stream, $old_name.$postfix);
68f2ce7a 347 $oldpref = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
348 removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
1c52ba77 349 sqimap_subscribe($imap_stream, $new_name.$postfix);
68f2ce7a 350 setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref);
e429f014 351 do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
648713af 352 $l = strlen( $old_name ) + 1;
353 $p = 'unformatted';
68f2ce7a 354
ff245fbd 355 foreach ($boxesall as $box) {
356 if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
648713af 357 $new_sub = $new_name . $delimiter . substr($box[$p], $l);
358 if ($imap_server_type == 'cyrus') {
68f2ce7a 359 $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
3411d4ec 360 $data = sqimap_run_command($imap_stream, $cmd, true,
648713af 361 $response, $message);
1c52ba77 362 }
648713af 363 sqimap_unsubscribe($imap_stream, $box[$p]);
68f2ce7a 364 $oldpref = getPref($data_dir, $username, 'thread_'.$box[$p]);
365 removePref($data_dir, $username, 'thread_'.$box[$p]);
648713af 366 sqimap_subscribe($imap_stream, $new_sub);
68f2ce7a 367 setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref);
368 do_hook_function('rename_or_delete_folder',
3411d4ec 369 $args = array($box[$p], 'rename', $new_sub));
1c52ba77 370 }
371 }
1c52ba77 372 }
1c52ba77 373}
43b698c7 374
3411d4ec 375/*
86c2763d 376 * Formats a mailbox into parts for the $boxesall array
3411d4ec 377 *
86c2763d 378 * The parts are:
3411d4ec 379 *
380 * raw - Raw LIST/LSUB response from the IMAP server
381 * formatted - nicely formatted folder name
382 * unformatted - unformatted, but with delimiter at end removed
383 * unformatted-dm - folder name as it appears in raw response
384 * unformatted-disp - unformatted without $folder_prefix
385 */
386function sqimap_mailbox_parse ($line, $line_lsub) {
43b698c7 387 global $folder_prefix, $delimiter;
3411d4ec 388
43b698c7 389 /* Process each folder line */
cef054e4 390 for ($g = 0, $cnt = count($line); $g < $cnt; ++$g) {
43b698c7 391 /* Store the raw IMAP reply */
392 if (isset($line[$g])) {
e429f014 393 $boxesall[$g]['raw'] = $line[$g];
ff245fbd 394 } else {
e429f014 395 $boxesall[$g]['raw'] = '';
43b698c7 396 }
3411d4ec 397
43b698c7 398 /* Count number of delimiters ($delimiter) in folder name */
86c2763d 399 $mailbox = /*trim(*/$line_lsub[$g]/*)*/;
ff245fbd 400 $dm_count = substr_count($mailbox, $delimiter);
43b698c7 401 if (substr($mailbox, -1) == $delimiter) {
3411d4ec 402 /* If name ends in delimiter, decrement count by one */
403 $dm_count--;
43b698c7 404 }
3411d4ec 405
406 /* Format folder name, but only if it's a INBOX.* or has a parent. */
1da22cda 407 $boxesallbyname[$mailbox] = $g;
43b698c7 408 $parentfolder = readMailboxParent($mailbox, $delimiter);
409 if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
410 (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
ff245fbd 411 (isset($boxesallbyname[$parentfolder]) &&
412 (strlen($parentfolder) > 0) ) ) {
413 $indent = $dm_count - (substr_count($folder_prefix, $delimiter));
43b698c7 414 if ($indent > 0) {
ff245fbd 415 $boxesall[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $indent);
416 } else {
1da22cda 417 $boxesall[$g]['formatted'] = '';
43b698c7 418 }
447b2166 419 $boxesall[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
ff245fbd 420 } else {
447b2166 421 $boxesall[$g]['formatted'] = imap_utf7_decode_local($mailbox);
43b698c7 422 }
90de1755 423
1da22cda 424 $boxesall[$g]['unformatted-dm'] = $mailbox;
43b698c7 425 if (substr($mailbox, -1) == $delimiter) {
8e9e8afa 426 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
43b698c7 427 }
1da22cda 428 $boxesall[$g]['unformatted'] = $mailbox;
43b698c7 429 if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix) {
631b9da3 430 $mailbox = substr($mailbox, strlen($folder_prefix));
43b698c7 431 }
1da22cda 432 $boxesall[$g]['unformatted-disp'] = $mailbox;
433 $boxesall[$g]['id'] = $g;
90de1755 434
1da22cda 435 $boxesall[$g]['flags'] = array();
43b698c7 436 if (isset($line[$g])) {
36dfb0c9 437 ereg("\(([^)]*)\)",$line[$g],$regs);
5c300c60 438 // FIXME Flags do contain the \ character. \NoSelect \NoInferiors
439 // and $MDNSent <= last one doesn't have the \
440 // It's better to follow RFC3501 instead of using our own naming.
1a7e1e97 441 $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
43b698c7 442 if ($flags) {
1da22cda 443 $boxesall[$g]['flags'] = explode(' ', $flags);
43b698c7 444 }
445 }
446 }
1da22cda 447 return $boxesall;
43b698c7 448}
449
3411d4ec 450/*
a3439b27 451 * Sorting function used to sort mailbox names.
3411d4ec 452 * + Original patch from dave_michmerhuizen@yahoo.com
453 * + Allows case insensitivity when sorting folders
454 * + Takes care of the delimiter being sorted to the end, causing
455 * subfolders to be listed in below folders that are prefixed
456 * with their parent folders name.
457 *
458 * For example: INBOX.foo, INBOX.foobar, and INBOX.foo.bar
459 * Without special sort function: foobar between foo and foo.bar
460 * With special sort function: foobar AFTER foo and foo.bar :)
43b698c7 461 */
a3439b27 462function user_strcasecmp($a, $b) {
d42310bd 463 return strnatcasecmp($a, $b);
43b698c7 464}
465
be2d5495 466/*
467 * Returns list of options (to be echoed into select statement
468 * based on available mailboxes and separators
469 * Caller should surround options with <SELECT..> </SELECT> and
470 * any formatting.
471 * $imap_stream - $imapConnection to query for mailboxes
472 * $show_selected - array containing list of mailboxes to pre-select (0 if none)
473 * $folder_skip - array of folders to keep out of option list (compared in lower)
474 * $boxes - list of already fetched boxes (for places like folder panel, where
475 * you know these options will be shown 3 times in a row.. (most often unset).
59a8e3e8 476 * $flag - flag to check for in mailbox flags, used to filter out mailboxes.
477 * 'noselect' by default to remove unselectable mailboxes.
478 * 'noinferiors' used to filter out folders that can not contain subfolders.
479 * NULL to avoid flag check entirely.
d0928dd5 480 * NOTE: noselect and noiferiors are used internally. The IMAP representation is
481 * \NoSelect and \NoInferiors
59a8e3e8 482 * $use_long_format - override folder display preference and always show full folder name.
be2d5495 483 */
59a8e3e8 484function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0,
485 $flag = 'noselect', $use_long_format = false ) {
be2d5495 486 global $username, $data_dir;
487 $mbox_options = '';
45f836eb 488 if ( $use_long_format ) {
489 $shorten_box_names = 0;
490 } else {
491 $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF);
492 }
ff245fbd 493
494 if ($boxes == 0) {
be2d5495 495 $boxes = sqimap_mailbox_list($imap_stream);
ff245fbd 496 }
59a8e3e8 497
be2d5495 498 foreach ($boxes as $boxes_part) {
59a8e3e8 499 if ($flag == NULL || !in_array($flag, $boxes_part['flags'])) {
be2d5495 500 $box = $boxes_part['unformatted'];
be2d5495 501
d0928dd5 502 if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
be2d5495 503 continue;
504 }
d0928dd5 505 $lowerbox = strtolower($box);
5c300c60 506 // mailboxes are casesensitive => inbox.sent != inbox.Sent
507 // nevermind, to many dependencies this should be fixed!
508
d0928dd5 509 if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
be2d5495 510 $box2 = _("INBOX");
d0928dd5 511 } else {
5c300c60 512 switch ($shorten_box_names)
513 {
514 case 2: /* delimited, style = 2 */
d0928dd5 515 $box2 = str_replace('&nbsp;&nbsp;', '.&nbsp;', $boxes_part['formatted']);
5c300c60 516 break;
d0928dd5 517 case 1: /* indent, style = 1 */
518 $box2 = $boxes_part['formatted'];
5c300c60 519 break;
d0928dd5 520 default: /* default, long names, style = 0 */
6c4f0fa1 521 $box2 = str_replace(' ', '&nbsp;', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
5c300c60 522 break;
523 }
be2d5495 524 }
525 if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
86c2763d 526 $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'" SELECTED>'.$box2.'</OPTION>' . "\n";
be2d5495 527 } else {
86c2763d 528 $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'">'.$box2.'</OPTION>' . "\n";
be2d5495 529 }
530 }
531 }
532 return $mbox_options;
533}
43b698c7 534
3411d4ec 535/*
536 * Returns sorted mailbox lists in several different ways.
537 * See comment on sqimap_mailbox_parse() for info about the returned array.
538 */
1da22cda 539function sqimap_mailbox_list($imap_stream) {
4b2fe13a 540 global $default_folder_prefix;
7e235a1a 541
ff245fbd 542 if (!isset($boxesnew)) {
3411d4ec 543 global $data_dir, $username, $list_special_folders_first,
7e235a1a 544 $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
545 $move_to_trash, $move_to_sent, $save_as_draft,
ca85aabe 546 $delimiter, $noselect_fix_enable;
7e235a1a 547
3411d4ec 548 $inbox_in_list = false;
549 $inbox_subscribed = false;
7e235a1a 550
08185f2a 551 require_once(SM_PATH . 'include/load_prefs.php');
7e235a1a 552
ff245fbd 553 if ($noselect_fix_enable) {
554 $lsub_args = "LSUB \"$folder_prefix\" \"*%\"";
555 } else {
556 $lsub_args = "LSUB \"$folder_prefix\" \"*\"";
557 }
3411d4ec 558 /* LSUB array */
ca85aabe 559 $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
3411d4ec 560 true, $response, $message);
bac13dd7 561 $lsub_ary = compact_mailboxes_response($lsub_ary);
7e235a1a 562
7e235a1a 563 $sorted_lsub_ary = array();
ff245fbd 564 for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
7e235a1a 565 $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
566 $sorted_lsub_ary[] = $temp_mailbox_name;
cef054e4 567 if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
3411d4ec 568 $inbox_subscribed = true;
7e235a1a 569 }
570 }
cef054e4 571
5c300c60 572 /* natural sort mailboxes */
7e235a1a 573 if (isset($sorted_lsub_ary)) {
574 usort($sorted_lsub_ary, 'user_strcasecmp');
575 }
5c300c60 576 /*
577 * The LSUB response doesn't provide us information about \Noselect
578 * mail boxes. The LIST response does, that's why we need to do a LIST
579 * call to retrieve the flags for the mailbox
cef054e4 580 * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
581 * in other words, we cannot rely on it.
5c300c60 582 */
cef054e4 583 $sorted_list_ary = array();
ff245fbd 584 for ($i=0; $i < count($sorted_lsub_ary); $i++) {
7e235a1a 585 if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
586 $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
587 }
588 else {
589 $mbx = $sorted_lsub_ary[$i];
590 }
bac13dd7 591 $mbx = stripslashes($mbx);
568cb884 592 $read = sqimap_run_command ($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx),
3411d4ec 593 true, $response, $message);
bac13dd7 594 $read = compact_mailboxes_response($read);
7e235a1a 595 if (isset($read[0])) {
596 $sorted_list_ary[$i] = $read[0];
cef054e4 597 } else {
7e235a1a 598 $sorted_list_ary[$i] = '';
599 }
7e235a1a 600 }
3411d4ec 601 /*
7e235a1a 602 * Just in case they're not subscribed to their inbox,
603 * we'll get it for them anyway
604 */
cef054e4 605 if (!$inbox_subscribed) {
568cb884 606 $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
3411d4ec 607 true, $response, $message);
bac13dd7 608 $sorted_list_ary[] = implode('', compact_mailboxes_response($inbox_ary));
7e235a1a 609 $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
610 }
611
612 $boxesall = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary);
613
3411d4ec 614 /* Now, lets sort for special folders */
7e235a1a 615 $boxesnew = $used = array();
616
617 /* Find INBOX */
ff245fbd 618 $cnt = count($boxesall);
5c300c60 619 $used = array_pad($used,$cnt,false);
cef054e4 620 for($k = 0; $k < $cnt; ++$k) {
ff245fbd 621 if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
622 $boxesnew[] = $boxesall[$k];
3411d4ec 623 $used[$k] = true;
5c300c60 624 break;
7e235a1a 625 }
626 }
7e235a1a 627 /* List special folders and their subfolders, if requested. */
3411d4ec 628 if ($list_special_folders_first) {
cef054e4 629 for($k = 0; $k < $cnt; ++$k) {
ff245fbd 630 if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
631 $boxesnew[] = $boxesall[$k];
632 $used[$k] = true;
7e235a1a 633 }
5c300c60 634 }
635 }
7e235a1a 636
7e235a1a 637 /* Rest of the folders */
ff245fbd 638 for($k = 0; $k < $cnt; $k++) {
639 if (!$used[$k]) {
640 $boxesnew[] = $boxesall[$k];
7e235a1a 641 }
642 }
43b698c7 643 }
86c2763d 644
3411d4ec 645 return $boxesnew;
43b698c7 646}
647
90de1755 648/*
649 * Returns a list of all folders, subscribed or not
650 */
1da22cda 651function sqimap_mailbox_list_all($imap_stream) {
3411d4ec 652 global $list_special_folders_first, $folder_prefix, $delimiter;
bac13dd7 653
654 $read_ary = sqimap_run_command($imap_stream,"LIST \"$folder_prefix\" *",true,$response, $message,false);
655 $read_ary = compact_mailboxes_response($read_ary);
656
43b698c7 657 $g = 0;
90de1755 658 $phase = 'inbox';
7d82bceb 659 $fld_pre_length = strlen($folder_prefix);
ff245fbd 660 for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
780dd344 661 /* Store the raw IMAP reply */
662 $boxes[$g]['raw'] = $read_ary[$i];
90de1755 663
780dd344 664 /* Count number of delimiters ($delimiter) in folder name */
665 $mailbox = find_mailbox_name($read_ary[$i]);
666 $dm_count = substr_count($mailbox, $delimiter);
667 if (substr($mailbox, -1) == $delimiter) {
668 /* If name ends in delimiter - decrement count by one */
669 $dm_count--;
670 }
90de1755 671
780dd344 672 /* Format folder name, but only if it's a INBOX.* or has a parent. */
673 $boxesallbyname[$mailbox] = $g;
674 $parentfolder = readMailboxParent($mailbox, $delimiter);
675 if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
676 (ereg('^'.$folder_prefix, $mailbox)) ||
677 ( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
678 if ($dm_count) {
679 $boxes[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $dm_count);
90de1755 680 } else {
780dd344 681 $boxes[$g]['formatted'] = '';
12d61439 682 }
780dd344 683 $boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
684 } else {
685 $boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
686 }
687
688 $boxes[$g]['unformatted-dm'] = $mailbox;
689 if (substr($mailbox, -1) == $delimiter) {
690 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
691 }
692 $boxes[$g]['unformatted'] = $mailbox;
693 $boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
694
695 $boxes[$g]['id'] = $g;
696
697 /* Now lets get the flags for this mailbox */
698 $read_mlbx = $read_ary[$i];
699 $flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
700 $flags = substr($flags, 0, strpos($flags, ')'));
701 $flags = str_replace('\\', '', $flags);
702 $flags = trim(strtolower($flags));
703 if ($flags) {
704 $boxes[$g]['flags'] = explode(' ', $flags);
705 } else {
706 $boxes[$g]['flags'] = array();
43b698c7 707 }
708 $g++;
709 }
710 if(is_array($boxes)) {
e429f014 711 sort ($boxes);
43b698c7 712 }
90de1755 713
43b698c7 714 return $boxes;
715}
5bdd7223 716
60b5724d 717function sqimap_mailbox_tree($imap_stream) {
718 global $boxesnew, $default_folder_prefix, $unseen_notify, $unseen_type;
ff245fbd 719 if (!isset($boxesnew)) {
60b5724d 720
721 global $data_dir, $username, $list_special_folders_first,
a2e66c6d 722 $folder_prefix, $delimiter, $trash_folder, $move_to_trash,
723 $imap_server_type;
60b5724d 724
725
726 $inbox_in_list = false;
727 $inbox_subscribed = false;
f08ba804 728 $noselect = false;
86c2763d 729 $noinferiors = false;
60b5724d 730
08185f2a 731 require_once(SM_PATH . 'include/load_prefs.php');
60b5724d 732
733 /* LSUB array */
34c7eef3 734 $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
60b5724d 735 true, $response, $message);
bac13dd7 736 $lsub_ary = compact_mailboxes_response($lsub_ary);
60b5724d 737
9871bdaa 738 /* Check to see if we have an INBOX */
78bc908d 739 $has_inbox = false;
740
741 for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
49774174 742 if (preg_match("/^\*\s+LSUB\s+(.*)\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
743 $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
78bc908d 744 $has_inbox = true;
745 break;
746 }
747 }
748
749 if ($has_inbox == false) {
568cb884 750 $lsub_ary[] = '* LSUB () NIL INBOX';
78bc908d 751 }
752
60b5724d 753 /*
754 * Section about removing the last element was removed
755 * We don't return "* OK" anymore from sqimap_read_data
756 */
bac13dd7 757
60b5724d 758 $sorted_lsub_ary = array();
e4c6fe41 759 $cnt = count($lsub_ary);
ff245fbd 760 for ($i = 0; $i < $cnt; $i++) {
ff245fbd 761 $mbx = find_mailbox_name($lsub_ary[$i]);
a2e66c6d 762
483f9ef9 763 // only do the noselect test if !uw, is checked later. FIX ME see conf.pl setting
764 if ($imap_server_type != "uw") {
765 $noselect = check_is_noselect($lsub_ary[$i]);
86c2763d 766 $noinferiors = check_is_noinferiors($lsub_ary[$i]);
a2e66c6d 767 }
ff245fbd 768 if (substr($mbx, -1) == $delimiter) {
769 $mbx = substr($mbx, 0, strlen($mbx) - 1);
770 }
86c2763d 771 $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
60b5724d 772 }
5c300c60 773 // FIX ME this requires a config setting inside conf.pl instead of checking on server type
483f9ef9 774 if ($imap_server_type == "uw") {
5c300c60 775 $aQuery = array();
776 $aTag = array();
777 // prepare an array with queries
778 foreach ($sorted_lsub_ary as $aMbx) {
bac13dd7 779 $mbx = stripslashes($aMbx['mbx']);
568cb884 780 sqimap_prepare_pipelined_query('LIST "" ' . sqimap_encode_mailbox_name($mbx), $tag, $aQuery, false);
5c300c60 781 $aTag[$tag] = $mbx;
782 }
783 $sorted_lsub_ary = array();
784 // execute all the queries at once
785 $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
786 foreach($aTag as $tag => $mbx) {
787 if ($aServerResponse[$tag] == 'OK') {
788 $sResponse = implode('', $aResponse[$tag]);
789 $noselect = check_is_noselect($sResponse);
86c2763d 790 $noinferiors = check_is_noinferiors($sResponse);
791 $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
5c300c60 792 }
793 }
794 $cnt = count($sorted_lsub_ary);
483f9ef9 795 }
bac13dd7 796 $sorted_lsub_ary = array_values($sorted_lsub_ary);
483f9ef9 797 array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
798 $boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
799 return $boxesnew;
60b5724d 800 }
801}
802
483f9ef9 803function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
60b5724d 804 global $data_dir, $username, $list_special_folders_first,
805 $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
806 $move_to_trash, $move_to_sent, $save_as_draft,
43a31298 807 $delimiter, $imap_server_type;
60b5724d 808
809 $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
ff245fbd 810
60b5724d 811 /* create virtual root node */
812 $mailboxes= new mailboxes();
813 $mailboxes->is_root = true;
ff245fbd 814 $trail_del = false;
78bc908d 815 $start = 0;
816
587ec647 817
43a31298 818 if (isset($folder_prefix) && ($folder_prefix != '')) {
ff245fbd 819 $start = substr_count($folder_prefix,$delimiter);
820 if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
821 $trail_del = true;
822 $mailboxes->mailboxname_full = substr($folder_prefix,0, (strlen($folder_prefix)-1));
823 } else {
824 $mailboxes->mailboxname_full = $folder_prefix;
825 $start++;
826 }
827 $mailboxes->mailboxname_sub = $mailboxes->mailboxname_full;
828 } else {
829 $start = 0;
830 }
78bc908d 831
e4c6fe41 832 $cnt = count($mbx_ary);
833 for ($i=0; $i < $cnt; $i++) {
ff245fbd 834 if ($mbx_ary[$i]['mbx'] !='' ) {
835 $mbx = new mailboxes();
836 $mailbox = $mbx_ary[$i]['mbx'];
cc82c2b7 837
97a5e85f 838 /*
cc82c2b7 839 sent subfolders messes up using existing code as subfolders
840 were marked, but the parents were ordered somewhere else in
841 the list, despite having "special folders at top" option set.
842 Need a better method than this.
97a5e85f 843 */
8edc9f31 844/*
97a5e85f 845 if ($mailbox == 'INBOX') {
846 $mbx->is_special = true;
847 } elseif (stristr($trash_folder , $mailbox)) {
848 $mbx->is_special = true;
849 } elseif (stristr($sent_folder , $mailbox)) {
850 $mbx->is_special = true;
851 } elseif (stristr($draft_folder , $mailbox)) {
852 $mbx->is_special = true;
853 }
cc82c2b7 854
ff245fbd 855 switch ($mailbox) {
856 case 'INBOX':
857 $mbx->is_inbox = true;
858 $mbx->is_special = true;
8edc9f31 859 $mbx_ary[$i]['noselect'] = false;
ff245fbd 860 break;
861 case $trash_folder:
862 $mbx->is_trash = true;
863 $mbx->is_special = true;
864 break;
865 case $sent_folder:
866 $mbx->is_sent = true;
867 $mbx->is_special = true;
868 break;
869 case $draft_folder:
870 $mbx->is_draft = true;
871 $mbx->is_special = true;
872 break;
873 }
8edc9f31 874*/
875 $mbx->is_special |= ($mbx->is_inbox = (strtoupper($mailbox) == 'INBOX'));
876 $mbx->is_special |= ($mbx->is_trash = isTrashMailbox($mailbox));
877 $mbx->is_special |= ($mbx->is_sent = isSentMailbox($mailbox));
878 $mbx->is_special |= ($mbx->is_draft = isDraftMailbox($mailbox));
879 if (!$mbx->is_special)
880 $mbx->is_special = do_hook_function('special_mailbox', $mailbox);
cc82c2b7 881
ff245fbd 882 if (isset($mbx_ary[$i]['unseen'])) {
883 $mbx->unseen = $mbx_ary[$i]['unseen'];
884 }
885 if (isset($mbx_ary[$i]['nummessages'])) {
886 $mbx->total = $mbx_ary[$i]['nummessages'];
887 }
888
889 $mbx->is_noselect = $mbx_ary[$i]['noselect'];
86c2763d 890 $mbx->is_noinferiors = $mbx_ary[$i]['noinferiors'];
ff245fbd 891
60b5724d 892 $r_del_pos = strrpos($mbx_ary[$i]['mbx'], $delimiter);
ff245fbd 893 if ($r_del_pos) {
587ec647 894 $mbx->mailboxname_sub = substr($mbx_ary[$i]['mbx'],$r_del_pos+1);
ff245fbd 895 } else { /* mailbox is root folder */
587ec647 896 $mbx->mailboxname_sub = $mbx_ary[$i]['mbx'];
ff245fbd 897 }
898 $mbx->mailboxname_full = $mbx_ary[$i]['mbx'];
38068e69 899
9871bdaa 900 $mailboxes->addMbx($mbx, $delimiter, $start, $list_special_folders_first);
ff245fbd 901 }
60b5724d 902 }
587ec647 903 sqimap_utf7_decode_mbx_tree($mailboxes);
483f9ef9 904 sqimap_get_status_mbx_tree($imap_stream,$mailboxes);
60b5724d 905 return $mailboxes;
906}
259faa39 907
587ec647 908function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
d94c8d61 909 if (strtoupper($mbx_tree->mailboxname_sub) == 'INBOX')
910 $mbx_tree->mailboxname_sub = _("INBOX");
911 else
912 $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);
587ec647 913 if ($mbx_tree->mbxs) {
914 $iCnt = count($mbx_tree->mbxs);
915 for ($i=0;$i<$iCnt;++$i) {
d94c8d61 916 $mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
587ec647 917 }
918 }
483f9ef9 919}
920
921
922function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
5c300c60 923 if ($mbx_tree)
483f9ef9 924 $aMbxs[] =& $mbx_tree;
925 if ($mbx_tree->mbxs) {
926 $iCnt = count($mbx_tree->mbxs);
927 for ($i=0;$i<$iCnt;++$i) {
5c300c60 928 sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
483f9ef9 929 }
930 }
931}
932
933
934/* Define preferences for folder settings. */
935/* FIXME, we should load constants.php
936unseen_notify
937define('SMPREF_UNSEEN_NONE', 1);
938define('SMPREF_UNSEEN_INBOX', 2);
939define('SMPREF_UNSEEN_ALL', 3);
940
941define('SMPREF_UNSEEN_SPECIAL', 4); // Only special folders
942define('SMPREF_UNSEEN_NORMAL', 5); // Only normal folders
943
944unseen_type
945define('SMPREF_UNSEEN_ONLY', 1);
946define('SMPREF_UNSEEN_TOTAL', 2);
947*/
948
949function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
950 global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
951 $aMbxs = $aQuery = $aTag = array();
952 sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
953 // remove the root node
954 array_shift($aMbxs);
955
956 if($unseen_notify == 3) {
957 $cnt = count($aMbxs);
958 for($i=0;$i<$cnt;++$i) {
5c300c60 959 $oMbx =& $aMbxs[$i];
960 if (!$oMbx->is_noselect) {
483f9ef9 961 $mbx = $oMbx->mailboxname_full;
5c300c60 962 if ($unseen_type == 2 ||
963 ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
568cb884 964 $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN)';
5c300c60 965 } else {
568cb884 966 $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN)';
5c300c60 967 }
483f9ef9 968 sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
5c300c60 969 } else {
970 $oMbx->unseen = $oMbx->total = false;
971 $tag = false;
972 }
973 $oMbx->tag = $tag;
974 $aMbxs[$i] =& $oMbx;
483f9ef9 975 }
976 // execute all the queries at once
977 $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
978 $cnt = count($aMbxs);
979 for($i=0;$i<$cnt;++$i) {
5c300c60 980 $oMbx =& $aMbxs[$i];
981 $tag = $oMbx->tag;
982 if ($tag && $aServerResponse[$tag] == 'OK') {
983 $sResponse = implode('', $aResponse[$tag]);
483f9ef9 984 if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
985 $oMbx->unseen = $regs[1];
986 }
987 if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
988 $oMbx->total = $regs[1];
5c300c60 989 }
990 }
991 unset($oMbx->tag);
992 }
483f9ef9 993 } else if ($unseen_notify == 2) { // INBOX only
994 $cnt = count($aMbxs);
995 for($i=0;$i<$cnt;++$i) {
5c300c60 996 $oMbx =& $aMbxs[$i];
997 if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
998 ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
999 if ($unseen_type == 2 ||
1000 ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
1001 $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
1002 $oMbx->unseen = $aStatus['UNSEEN'];
1003 $oMbx->total = $aStatus['MESSAGES'];
1004 } else {
1005 $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
1006 }
1007 $aMbxs[$i] =& $oMbx;
1008 if (!$move_to_trash && $trash_folder) {
1009 break;
1010 } else {
1011 // trash comes after INBOX
1012 if ($oMbx->mailboxname_full == $trash_folder) {
1013 break;
1014 }
1015 }
1016 }
1017 }
1018 }
483f9ef9 1019}
587ec647 1020
648713af 1021?>