6 * This implements all functions that manipulate mailboxes
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
16 require_once(SM_PATH
. 'functions/imap_utf7_local.php');
22 * FIXME. This class should be extracted and placed in a separate file that
23 * can be included before we start the session. That makes caching of the tree
24 * possible. On a refresh mailboxes from left_main.php the only function that
25 * should be called is the sqimap_get_status_mbx_tree. In case of subscribe
26 * / rename / delete / new we have to create methods for adding/changing the
27 * mailbox in the mbx_tree without the need for a refresh.
29 * Some code fragments are present in 1.3.0 - 1.4.4.
30 * @package squirrelmail
35 var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false, $is_noinferiors = false,
36 $is_special = false, $is_root = false, $is_inbox = false, $is_sent = false,
37 $is_trash = false, $is_draft = false, $mbxs = array(),
38 $unseen = false, $total = false, $recent = false;
40 function addMbx($mbx, $delimiter, $start, $specialfirst) {
41 $ary = explode($delimiter, $mbx->mailboxname_full
);
43 for ($i = $start, $c = count($ary)-1; $i < $c; $i++
) {
44 $mbx_childs =& $mbx_parent->mbxs
;
47 foreach ($mbx_childs as $key => $parent) {
48 if ($parent->mailboxname_sub
== $ary[$i]) {
49 $mbx_parent =& $mbx_parent->mbxs
[$key];
56 $no_select_mbx = new mailboxes();
57 if (isset($mbx_parent->mailboxname_full
) && $mbx_parent->mailboxname_full
!= '') {
58 $no_select_mbx->mailboxname_full
= $mbx_parent->mailboxname_full
.$delimiter.$ary[$i];
60 $no_select_mbx->mailboxname_full
= $ary[$i];
62 $no_select_mbx->mailboxname_sub
= $ary[$i];
63 $no_select_mbx->is_noselect
= true;
64 $mbx_parent->mbxs
[] = $no_select_mbx;
68 $mbx_parent->mbxs
[] = $mbx;
69 if ($mbx->is_special
&& $specialfirst) {
70 usort($mbx_parent->mbxs
, 'sortSpecialMbx');
76 * array callback used for sorting in mailboxes class
79 * @return integer see php strnatcasecmp()
82 function sortSpecialMbx($a, $b) {
84 $acmp = '0'. $a->mailboxname_full
;
85 } else if ($a->is_special
) {
86 $acmp = '1'. $a->mailboxname_full
;
88 $acmp = '2' . $a->mailboxname_full
;
91 $bcmp = '0'. $b->mailboxname_full
;
92 }else if ($b->is_special
) {
93 $bcmp = '1' . $b->mailboxname_full
;
95 $bcmp = '2' . $b->mailboxname_full
;
97 return strnatcasecmp($acmp, $bcmp);
105 function compact_mailboxes_response($ary) {
107 * Workaround for mailboxes returned as literal
108 * FIXME : Doesn't work if the mailbox name is multiple lines
109 * (larger then fgets buffer)
111 for ($i = 0, $iCnt=count($ary); $i < $iCnt; $i++
) {
112 if (isset($ary[$i +
1]) && substr($ary[$i], -3) == "}\r\n") {
113 if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
115 $ary[$i] = $regs[1] . '"' . addslashes(trim($ary[$i+
1])) . '"' . $regs[2];
116 array_splice($ary, $i+
1, 2);
120 /* remove duplicates and ensure array is contiguous */
121 return array_values(array_unique($ary));
125 * Extract the mailbox name from an untagged LIST (7.2.2) or LSUB (7.2.3) answer
126 * (LIST|LSUB) (<Flags list>) (NIL|"<separator atom>") <mailbox name string>\r\n
127 * mailbox name in quoted string MUST be unquoted and stripslashed (sm API)
129 * Originally stored in functions/strings.php. Since 1.2.6 stored in
130 * functions/imap_mailbox.php
131 * @param string $line imap LIST/LSUB response line
132 * @return string mailbox name
134 function find_mailbox_name($line) {
135 if (preg_match('/^\* (?:LIST|LSUB) \([^\)]*\) (?:NIL|\"[^\"]*\") ([^\r\n]*)[\r\n]*$/i', $line, $regs)) {
136 if (substr($regs[1], 0, 1) == '"')
137 return stripslashes(substr($regs[1], 1, -1));
144 * Detects if mailbox has noselect flag (can't store messages)
145 * In versions older than 1.4.5 function checks only LSUB responses
146 * and can produce pcre warnings.
147 * @param string $lsub_line mailbox line from untagged LIST or LSUB response
148 * @return bool whether this is a Noselect mailbox.
151 function check_is_noselect ($lsub_line) {
152 return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noselect[^\)]*\)/i", $lsub_line);
156 * Detects if mailbox has noinferiors flag (can't store subfolders)
157 * @param string $lsub_line mailbox line from untagged LIST or LSUB response
158 * @return bool whether this is a Noinferiors mailbox.
161 function check_is_noinferiors ($lsub_line) {
162 return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noinferiors[^\)]*\)/i", $lsub_line);
166 * Detects mailbox's parent folder
168 * If $haystack is a full mailbox name, and $needle is the mailbox
169 * separator character, returns the second last part of the full
170 * mailbox name (i.e. the mailbox's parent mailbox)
172 * Originally stored in functions/strings.php. Since 1.2.6 stored in
173 * functions/imap_mailbox.php
174 * @param string $haystack full mailbox name
175 * @param string $needle delimiter
176 * @return string parent mailbox
178 function readMailboxParent($haystack, $needle) {
182 $parts = explode($needle, $haystack);
183 $elem = array_pop($parts);
184 while ($elem == '' && count($parts)) {
185 $elem = array_pop($parts);
187 $ret = join($needle, $parts);
193 * Check if $subbox is below the specified $parentbox
194 * @param string $subbox potential sub folder
195 * @param string $parentbox potential parent
199 function isBoxBelow( $subbox, $parentbox ) {
202 * Eliminate the obvious mismatch, where the
203 * subfolder path is shorter than that of the potential parent
205 if ( strlen($subbox) < strlen($parentbox) ) {
208 /* check for delimiter */
209 if (substr($parentbox,-1) != $delimiter) {
210 $parentbox .= $delimiter;
213 return (substr($subbox,0,strlen($parentbox)) == $parentbox);
217 * Defines special mailboxes: given a mailbox name, it checks if this is a
218 * "special" one: INBOX, Trash, Sent or Draft.
220 * Since 1.2.5 function includes special_mailbox hook.<br>
221 * Since 1.4.3 hook supports more than one plugin.
222 * @param string $box mailbox name
223 * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
224 * folders are special. if false, subfolders are not special mailboxes
225 * unless they are tagged as special in 'special_mailbox' hook.
229 function isSpecialMailbox($box,$include_subs=true) {
230 $ret = ( (strtolower($box) == 'inbox') ||
231 isTrashMailbox($box,$include_subs) ||
232 isSentMailbox($box,$include_subs) ||
233 isDraftMailbox($box,$include_subs) );
236 $ret = boolean_hook_function('special_mailbox',$box,1);
242 * Detects if mailbox is a Trash folder or subfolder of Trash
243 * @param string $box mailbox name
244 * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
245 * folders are special. if false, subfolders are not special mailboxes.
246 * @return bool whether this is a Trash folder
249 function isTrashMailbox ($box,$include_subs=true) {
250 global $trash_folder, $move_to_trash;
251 return $move_to_trash && $trash_folder &&
252 ( $box == $trash_folder ||
253 ($include_subs && isBoxBelow($box, $trash_folder)) );
257 * Detects if mailbox is a Sent folder or subfolder of Sent
258 * @param string $box mailbox name
259 * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
260 * folders are special. if false, subfolders are not special mailboxes.
261 * @return bool whether this is a Sent folder
264 function isSentMailbox($box,$include_subs=true) {
265 global $sent_folder, $move_to_sent;
266 return $move_to_sent && $sent_folder &&
267 ( $box == $sent_folder ||
268 ($include_subs && isBoxBelow($box, $sent_folder)) );
272 * Detects if mailbox is a Drafts folder or subfolder of Drafts
273 * @param string $box mailbox name
274 * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
275 * folders are special. if false, subfolders are not special mailboxes.
276 * @return bool whether this is a Draft folder
279 function isDraftMailbox($box,$include_subs=true) {
280 global $draft_folder, $save_as_draft;
281 return $save_as_draft &&
282 ( $box == $draft_folder ||
283 ($include_subs && isBoxBelow($box, $draft_folder)) );
289 * WARNING: Select mailbox before calling this function.
291 * permanently removes all messages that have the \Deleted flag
292 * set from the selected mailbox. See EXPUNGE command chapter in
294 * @param stream $imap_stream imap connection resource
295 * @param string $mailbox mailbox name (unused since 1.1.3).
296 * @param boolean $handle_errors error handling control (displays error_box on error).
297 * @param mixed $id (since 1.3.0) integer message id or array with integer ids
298 * @return integer number of expunged messages
299 * @since 1.0 or older
301 function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
304 $id = sqimap_message_list_squisher($id);
311 $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
312 $response, $message, $uid);
315 if (is_array($read)) {
316 foreach ($read as $r) {
317 if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
326 * Checks whether or not the specified mailbox exists
328 * @param stream $imap_stream imap connection resource
329 * @param string $mailbox mailbox name
330 * @param array $mailboxlist (since 1.5.1) optional array of mailboxes from
331 * sqimap_get_mailboxes() (to avoid having to talk to imap server)
333 * @since 1.0 or older
335 function sqimap_mailbox_exists ($imap_stream, $mailbox, $mailboxlist=null) {
336 if (!isset($mailbox) ||
empty($mailbox)) {
340 if (is_array($mailboxlist)) {
341 // use previously retrieved mailbox list
342 foreach ($mailboxlist as $mbox) {
343 if ($mbox['unformatted-dm'] == $mailbox) { return true; }
348 $mbx = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mailbox),
349 true, $response, $message);
350 return isset($mbx[0]);
356 * Before 1.3.0 used more arguments and returned data depended on those arguments.
357 * @param stream $imap_stream imap connection resource
358 * @param string $mailbox mailbox name
359 * @return array results of select command (on success - permanentflags, flags and rights)
360 * @since 1.0 or older
362 function sqimap_mailbox_select ($imap_stream, $mailbox) {
363 // FIX ME: WHAAAA DO NOT USE "None" for something that does not exist. Use false or NULL instead
364 if ($mailbox == 'None') {
367 // cleanup $mailbox in order to prevent IMAP injection attacks
368 $mailbox = str_replace(array("\r","\n"), array("",""),$mailbox);
369 $read = sqimap_run_command($imap_stream, 'SELECT ' . sqimap_encode_mailbox_name($mailbox),
370 true, $response, $message);
372 for ($i = 0, $cnt = count($read); $i < $cnt; $i++
) {
373 if (preg_match('/^\*\s+OK\s\[(\w+)\s(\w+)\]/',$read[$i], $regs)) {
374 $result[strtoupper($regs[1])] = $regs[2];
375 } else if (preg_match('/^\*\s([0-9]+)\s(\w+)/',$read[$i], $regs)) {
376 $result[strtoupper($regs[2])] = $regs[1];
378 if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
379 $regs[1]=trim(preg_replace ( array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
380 $result['PERMANENTFLAGS'] = explode(' ',strtolower($regs[1]));
381 } else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
382 $regs[1]=trim(preg_replace ( array ("/\(/","/\)/") ,'', $regs[1])) ;
383 $result['FLAGS'] = explode(' ',strtolower($regs[1]));
387 if (!isset($result['PERMANENTFLAGS'])) {
388 $result['PERMANENTFLAGS'] = $result['FLAGS'];
390 if (preg_match('/^\[(.+)\]/',$message, $regs)) {
391 $result['RIGHTS']=strtoupper($regs[1]);
400 * Mailbox is automatically subscribed.
402 * Set $type to string that does not match 'noselect' (case insensitive),
403 * if you don't want to prepend delimiter to mailbox name. Please note
404 * that 'noinferiors' might be used someday as keyword for folders
405 * that store only messages.
406 * @param stream $imap_steam imap connection resource
407 * @param string $mailbox mailbox name
408 * @param string $type folder type.
409 * @since 1.0 or older
411 function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
413 if (strtolower($type) == 'noselect') {
414 $create_mailbox = $mailbox . $delimiter;
416 $create_mailbox = $mailbox;
419 $read_ary = sqimap_run_command($imap_stream, 'CREATE ' .
420 sqimap_encode_mailbox_name($create_mailbox),
421 true, $response, $message);
422 sqimap_subscribe ($imap_stream, $mailbox);
426 * Subscribes to an existing folder.
427 * @param stream $imap_stream imap connection resource
428 * @param string $mailbox mailbox name
429 * @param boolean $debug (since 1.5.1)
430 * @since 1.0 or older
432 function sqimap_subscribe ($imap_stream, $mailbox,$debug=true) {
433 $read_ary = sqimap_run_command($imap_stream, 'SUBSCRIBE ' .
434 sqimap_encode_mailbox_name($mailbox),
435 $debug, $response, $message);
439 * Unsubscribes from an existing folder
440 * @param stream $imap_stream imap connection resource
441 * @param string $mailbox mailbox name
442 * @since 1.0 or older
444 function sqimap_unsubscribe ($imap_stream, $mailbox) {
445 $read_ary = sqimap_run_command($imap_stream, 'UNSUBSCRIBE ' .
446 sqimap_encode_mailbox_name($mailbox),
447 false, $response, $message);
451 * Deletes the given folder
452 * Since 1.2.6 and 1.3.0 contains rename_or_delete_folder hook
453 * @param stream $imap_stream imap connection resource
454 * @param string $mailbox mailbox name
455 * @since 1.0 or older
457 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
458 global $data_dir, $username;
459 sqimap_unsubscribe ($imap_stream, $mailbox);
461 if (sqimap_mailbox_exists($imap_stream, $mailbox)) {
463 $read_ary = sqimap_run_command($imap_stream, 'DELETE ' .
464 sqimap_encode_mailbox_name($mailbox),
465 true, $response, $message);
466 if ($response !== 'OK') {
468 sqimap_subscribe ($imap_stream, $mailbox);
470 do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
471 removePref($data_dir, $username, "thread_$mailbox");
472 removePref($data_dir, $username, "collapse_folder_$mailbox");
478 * Determines if the user is subscribed to the folder or not
479 * @param stream $imap_stream imap connection resource
480 * @param string $mailbox mailbox name
484 function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
485 $boxesall = sqimap_mailbox_list ($imap_stream);
486 foreach ($boxesall as $ref) {
487 if ($ref['unformatted'] == $folder) {
496 * Since 1.2.6 and 1.3.0 contains rename_or_delete_folder hook
497 * @param stream $imap_stream imap connection resource
498 * @param string $old_name mailbox name
499 * @param string $new_name new mailbox name
502 function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
503 if ( $old_name != $new_name ) {
504 global $delimiter, $imap_server_type, $data_dir, $username;
505 if ( substr( $old_name, -1 ) == $delimiter ) {
506 $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
507 $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 );
508 $postfix = $delimiter;
513 $boxesall = sqimap_mailbox_list_all($imap_stream);
514 $cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) .
515 ' ' . sqimap_encode_mailbox_name($new_name);
516 $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
517 sqimap_unsubscribe($imap_stream, $old_name.$postfix);
518 $oldpref_thread = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
519 $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
520 removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
521 removePref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
522 sqimap_subscribe($imap_stream, $new_name.$postfix);
523 setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref_thread);
524 setPref($data_dir, $username, 'collapse_folder_'.$new_name.$postfix, $oldpref_collapse);
525 do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
526 $l = strlen( $old_name ) +
1;
529 foreach ($boxesall as $box) {
530 if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
531 $new_sub = $new_name . $delimiter . substr($box[$p], $l);
532 /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */
533 if ($imap_server_type == 'cyrus') {
534 $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
535 $data = sqimap_run_command($imap_stream, $cmd, false,
536 $response, $message);
538 $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]);
539 if ( $was_subscribed ) {
540 sqimap_unsubscribe($imap_stream, $box[$p]);
542 $oldpref_thread = getPref($data_dir, $username, 'thread_'.$box[$p]);
543 $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$box[$p]);
544 removePref($data_dir, $username, 'thread_'.$box[$p]);
545 removePref($data_dir, $username, 'collapse_folder_'.$box[$p]);
546 if ( $was_subscribed ) {
547 sqimap_subscribe($imap_stream, $new_sub);
549 setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref_thread);
550 setPref($data_dir, $username, 'collapse_folder_'.$new_sub, $oldpref_collapse);
551 do_hook_function('rename_or_delete_folder',
552 $args = array($box[$p], 'rename', $new_sub));
559 * Formats a mailbox into parts for the $boxesall array
563 * <li>raw - Raw LIST/LSUB response from the IMAP server
564 * <li>formatted - nicely formatted folder name
565 * <li>unformatted - unformatted, but with delimiter at end removed
566 * <li>unformatted-dm - folder name as it appears in raw response
567 * <li>unformatted-disp - unformatted without $folder_prefix
568 * <li>id - TODO: document me
569 * <li>flags - TODO: document me
571 * Before 1.2.0 used third argument for delimiter.
573 * Before 1.5.1 used second argument for lsub line. Argument was removed in order to use
574 * find_mailbox_name() on the raw input. Since 1.5.1 includes RFC3501 names in flags
575 * array (for example, "\NoSelect" in addition to "noselect")
578 * @since 1.0 or older
579 * @todo document id and flags keys in boxes array and function arguments.
581 function sqimap_mailbox_parse ($line) {
582 global $folder_prefix, $delimiter;
584 /* Process each folder line */
585 for ($g = 0, $cnt = count($line); $g < $cnt; ++
$g) {
586 /* Store the raw IMAP reply */
587 if (isset($line[$g])) {
588 $boxesall[$g]['raw'] = $line[$g];
590 $boxesall[$g]['raw'] = '';
593 /* Count number of delimiters ($delimiter) in folder name */
594 $mailbox = find_mailbox_name($line[$g]);
595 $dm_count = substr_count($mailbox, $delimiter);
596 if (substr($mailbox, -1) == $delimiter) {
597 /* If name ends in delimiter, decrement count by one */
601 /* Format folder name, but only if it's a INBOX.* or has a parent. */
602 $boxesallbyname[$mailbox] = $g;
603 $parentfolder = readMailboxParent($mailbox, $delimiter);
604 if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
605 (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
606 (isset($boxesallbyname[$parentfolder]) &&
607 (strlen($parentfolder) > 0) ) ) {
608 $indent = $dm_count - (substr_count($folder_prefix, $delimiter));
610 $boxesall[$g]['formatted'] = str_repeat(' ', $indent);
612 $boxesall[$g]['formatted'] = '';
614 $boxesall[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
616 $boxesall[$g]['formatted'] = imap_utf7_decode_local($mailbox);
619 $boxesall[$g]['unformatted-dm'] = $mailbox;
620 if (substr($mailbox, -1) == $delimiter) {
621 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
623 $boxesall[$g]['unformatted'] = $mailbox;
624 if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix) {
625 $mailbox = substr($mailbox, strlen($folder_prefix));
627 $boxesall[$g]['unformatted-disp'] = $mailbox;
628 $boxesall[$g]['id'] = $g;
630 $boxesall[$g]['flags'] = array();
631 if (isset($line[$g])) {
632 ereg("\(([^)]*)\)",$line[$g],$regs);
634 * Since 1.5.1 flags are stored with RFC3501 naming
635 * and also the old way for backwards compatibility
636 * so for example "\NoSelect" and "noselect"
638 $flags = trim($regs[1]);
640 $flagsarr = explode(' ',$flags);
641 $flagsarrnew=$flagsarr;
643 foreach ($flagsarr as $flag) {
644 $flagsarrnew[]=strtolower(str_replace('\\', '',$flag));
646 $boxesall[$g]['flags']=$flagsarrnew;
654 * Returns an array of mailboxes available. Separated from sqimap_mailbox_option_list()
655 * below for template development.
657 * @author Steve Brown
660 function sqimap_mailbox_option_array($imap_stream, $folder_skip = 0, $boxes = 0,
661 $flag = 'noselect', $use_long_format = false ) {
662 global $username, $data_dir, $translate_special_folders, $sent_folder,
663 $trash_folder, $draft_folder;
665 $delimiter = sqimap_get_delimiter($imap_stream);
668 if ( $use_long_format ) {
669 $shorten_box_names = 0;
671 $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF
);
675 $boxes = sqimap_mailbox_list($imap_stream);
679 foreach ($boxes as $boxes_part) {
680 if ($flag == NULL ||
(is_array($boxes_part['flags'])
681 && !in_array($flag, $boxes_part['flags']))) {
682 $box = $boxes_part['unformatted'];
684 if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
687 $lowerbox = strtolower($box);
688 // mailboxes are casesensitive => inbox.sent != inbox.Sent
689 // nevermind, to many dependencies this should be fixed!
691 if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
694 switch ($shorten_box_names)
696 case 2: /* delimited, style = 2 */
697 if ($translate_special_folders && $boxes_part['unformatted-dm']==$sent_folder) {
699 * calculate pad level from number of delimiters. do it inside if control in order
700 * to reduce number of calculations. Other folders don't need it.
702 $pad = str_pad('',7 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),'. ');
703 // i18n: Name of Sent folder
704 $box2 = $pad . _("Sent");
705 } elseif ($translate_special_folders && $boxes_part['unformatted-dm']==$trash_folder) {
706 $pad = str_pad('',7 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),'. ');
707 // i18n: Name of Trash folder
708 $box2 = $pad . _("Trash");
709 } elseif ($translate_special_folders && $boxes_part['unformatted-dm']==$draft_folder) {
710 $pad = str_pad('',7 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),'. ');
711 // i18n: Name of Drafts folder
712 $box2 = $pad . _("Drafts");
714 $box2 = str_replace('&nbsp;&nbsp;', '. ', htmlspecialchars($boxes_part['formatted']));
717 case 1: /* indent, style = 1 */
718 if ($translate_special_folders && $boxes_part['unformatted-dm']==$sent_folder) {
719 $pad = str_pad('',12 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),' ');
720 $box2 = $pad . _("Sent");
721 } elseif ($translate_special_folders && $boxes_part['unformatted-dm']==$trash_folder) {
722 $pad = str_pad('',12 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),' ');
723 $box2 = $pad . _("Trash");
724 } elseif ($translate_special_folders && $boxes_part['unformatted-dm']==$draft_folder) {
725 $pad = str_pad('',12 * (count(explode($delimiter,$boxes_part['unformatted-dm']))-1),' ');
726 $box2 = $pad . _("Drafts");
728 $box2 = str_replace('&nbsp;&nbsp;', ' ', htmlspecialchars($boxes_part['formatted']));
731 default: /* default, long names, style = 0 */
732 $box2 = str_replace(' ', ' ', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
737 $a[htmlspecialchars($box)] = $box2;
745 * Returns list of options (to be echoed into select statement
746 * based on available mailboxes and separators
747 * Caller should surround options with <select ...> </select> and
749 * @param stream $imap_stream imap connection resource to query for mailboxes
750 * @param array $show_selected array containing list of mailboxes to pre-select (0 if none)
751 * @param array $folder_skip array of folders to keep out of option list (compared in lower)
752 * @param $boxes list of already fetched boxes (for places like folder panel, where
753 * you know these options will be shown 3 times in a row.. (most often unset).
754 * @param string $flag (since 1.4.1) flag to check for in mailbox flags, used to filter out mailboxes.
755 * 'noselect' by default to remove unselectable mailboxes.
756 * 'noinferiors' used to filter out folders that can not contain subfolders.
757 * NULL to avoid flag check entirely.
758 * NOTE: noselect and noiferiors are used internally. The IMAP representation is
759 * \NoSelect and \NoInferiors
760 * @param boolean $use_long_format (since 1.4.1) override folder display preference and always show full folder name.
761 * @return string html formated mailbox selection options
764 function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0,
765 $flag = 'noselect', $use_long_format = false ) {
766 global $username, $data_dir, $translate_special_folders, $sent_folder,
767 $trash_folder, $draft_folder;
769 $boxes = sqimap_mailbox_option_array($imap_stream, $folder_skip, $boxes, $flag, $use_long_format);
772 foreach ($boxes as $value=>$option) {
773 $lowerbox = strtolower(htmlspecialchars($value));
775 if ($show_selected != 0) {
776 reset($show_selected);
777 while (!$sel && (list($x, $val) = each($show_selected))) {
778 if (strtolower($value) == strtolower(htmlspecialchars($val))) {
784 $str .= '<option value="'. $value .'"'. ($sel ?
' selected="selected"' : '').'>'. $option ."</option>\n";
791 * Returns sorted mailbox lists in several different ways.
793 * Since 1.5.1 most of the functionality has been moved to new function sqimap_get_mailboxes
795 * See comment on sqimap_mailbox_parse() for info about the returned array.
796 * @param resource $imap_stream imap connection resource
797 * @param boolean $force force update of mailbox listing. available since 1.4.2 and 1.5.0
798 * @return array list of mailboxes
799 * @since 1.0 or older
801 function sqimap_mailbox_list($imap_stream, $force=false) {
802 global $boxesnew,$show_only_subscribed_folders;
803 if (!sqgetGlobalVar('boxesnew',$boxesnew,SQ_SESSION
) ||
$force) {
804 $boxesnew=sqimap_get_mailboxes($imap_stream,$force,$show_only_subscribed_folders);
810 * Returns a list of all folders, subscribed or not
812 * Since 1.5.1 code moved to sqimap_get_mailboxes()
814 * @param stream $imap_stream imap connection resource
815 * @return array see sqimap_mailbox_parse()
816 * @since 1.0 or older
818 function sqimap_mailbox_list_all($imap_stream) {
819 global $show_only_subscribed_folders;
820 // fourth argument prevents registration of retrieved list of mailboxes in session
821 $boxes=sqimap_get_mailboxes($imap_stream,true,false,false);
827 * Gets the list of mailboxes for sqimap_maolbox_tree and sqimap_mailbox_list
829 * This is because both of those functions had duplicated logic, but with slightly different
830 * implementations. This will make both use the same implementation, which should make it
831 * easier to maintain and easier to modify in the future
832 * @param stream $imap_stream imap connection resource
833 * @param bool $force force a reload and ignore cache
834 * @param bool $show_only_subscribed controls listing of visible or all folders
835 * @param bool $session_register controls registration of retrieved data in session.
836 * @return object boxesnew - array of mailboxes and their attributes
839 function sqimap_get_mailboxes($imap_stream,$force=false,$show_only_subscribed=true,$session_register=true) {
840 global $show_only_subscribed_folders,$noselect_fix_enable,$folder_prefix,
841 $list_special_folders_first,$imap_server_type;
842 $inbox_subscribed = false;
843 $listsubscribed = sqimap_capability($imap_stream,'LIST-SUBSCRIBED');
845 if ($show_only_subscribed) { $show_only_subscribed=$show_only_subscribed_folders; }
847 //require_once(SM_PATH . 'include/load_prefs.php');
850 * There are three main listing commands we can use in IMAP:
851 * LSUB shows just the list of subscribed folders
852 * may include flags, but these are not necessarily accurate or authoratative
853 * \NoSelect has special meaning: the folder does not exist -OR- it means this
854 * folder is not subscribed but children may be
856 * LIST this shows every mailbox on the system
857 * flags are always included and are accurate and authoratative
858 * \NoSelect means folder should not be selected
860 * LIST (SUBSCRIBED) implemented with LIST-SUBSCRIBED extension
861 * this is like list but returns only subscribed folders
862 * flag meanings are like LIST, not LSUB
863 * \NonExistent means mailbox doesn't exist
864 * \PlaceHolder means parent is not valid (selectable), but one or more children are
865 * \NoSelect indeed means that the folder should not be selected
866 * IMAPEXT-LIST-EXTENSIONS-04 August 2003 B. Leiba
868 if (!$show_only_subscribed) {
870 $sub_cache_name='list_cache';
871 } elseif ($listsubscribed) {
872 $lsub = 'LIST (SUBSCRIBED)';
873 $sub_cache_name='listsub_cache';
876 $sub_cache_name='lsub_cache';
879 // Some IMAP servers allow subfolders to exist even if the parent folders do not
880 // This fixes some problems with the folder list when this is the case, causing the
881 // NoSelect folders to be displayed
882 if ($noselect_fix_enable) {
883 $lsub_args = "$lsub \"$folder_prefix\" \"*%\"";
884 $list_args = "LIST \"$folder_prefix\" \"*%\"";
886 $lsub_args = "$lsub \"$folder_prefix\" \"*\"";
887 $list_args = "LIST \"$folder_prefix\" \"*\"";
890 // get subscribed mailbox list from cache (session)
891 // if not there, then get it from the imap server and store in cache
894 sqgetGlobalVar($sub_cache_name,$lsub_cache,SQ_SESSION
);
897 $lsub_assoc_ary=array();
898 if (!empty($lsub_cache)) {
899 $lsub_assoc_ary=$lsub_cache;
901 $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args, true, $response, $message);
902 $lsub_ary = compact_mailboxes_response($lsub_ary);
903 if (!empty($lsub_ary)) {
904 foreach ($lsub_ary as $rawline) {
905 $temp_mailbox_name=find_mailbox_name($rawline);
906 $lsub_assoc_ary[$temp_mailbox_name]=$rawline;
909 sqsession_register($lsub_assoc_ary,$sub_cache_name);
913 // Now to get the mailbox flags
914 // The LSUB response may return \NoSelect flags, etc. but it is optional
915 // according to RFC3501, and even when returned it may not be accurate
916 // or authoratative. LIST will always return accurate results.
917 if (($lsub == 'LIST') ||
($lsub == 'LIST (SUBSCRIBED)')) {
918 // we've already done a LIST or LIST (SUBSCRIBED)
919 // and NOT a LSUB, so no need to do it again
920 $list_assoc_ary = $lsub_assoc_ary;
922 // we did a LSUB so now we need to do a LIST
923 // first see if it is in cache
924 $list_cache_name='list_cache';
926 sqgetGlobalVar($list_cache_name,$list_cache,SQ_SESSION
);
929 if (!empty($list_cache)) {
930 $list_assoc_ary=$list_cache;
931 // we could store this in list_cache_name but not necessary
933 // not in cache so we need to go get it from the imap server
934 $list_assoc_ary = array();
935 $list_ary = sqimap_run_command($imap_stream, $list_args,
936 true, $response, $message);
937 $list_ary = compact_mailboxes_response($list_ary);
938 if (!empty($list_ary)) {
939 foreach ($list_ary as $rawline) {
940 $temp_mailbox_name=find_mailbox_name($rawline);
941 $list_assoc_ary[$temp_mailbox_name]=$rawline;
944 sqsession_register($list_assoc_ary,$list_cache_name);
949 // If they aren't subscribed to the inbox, then add it anyway (if its in LIST)
950 $inbox_subscribed=false;
951 if (!empty($lsub_assoc_ary)) {
952 foreach ($lsub_assoc_ary as $temp_mailbox_name=>$rawline) {
953 if (strtoupper($temp_mailbox_name) == 'INBOX') {
954 $inbox_subscribed=true;
958 if (!$inbox_subscribed) {
959 if (!empty($list_assoc_ary)) {
960 foreach ($list_assoc_ary as $temp_mailbox_name=>$rawline) {
961 if (strtoupper($temp_mailbox_name) == 'INBOX') {
962 $lsub_assoc_ary[$temp_mailbox_name]=$rawline;
968 // Now we have the raw output, we need to create an array of mailbox names we will return
969 if (!$show_only_subscribed) {
970 $final_folders_assoc_ary=$list_assoc_ary;
973 * only show subscribed folders
974 * we need to merge the folders here... we can't trust the flags, etc. from the lsub_assoc_array
975 * so we use the lsub_assoc_array as the list of folders and the values come from list_assoc_array
977 if (!empty($lsub_assoc_ary)) {
978 foreach ($lsub_assoc_ary as $temp_mailbox_name=>$rawline) {
979 if (!empty($list_assoc_ary[$temp_mailbox_name])) {
980 $final_folders_assoc_ary[$temp_mailbox_name]=$list_assoc_ary[$temp_mailbox_name];
987 // Now produce a flat, sorted list
988 if (!empty($final_folders_assoc_ary)) {
989 uksort($final_folders_assoc_ary,'strnatcasecmp');
990 foreach ($final_folders_assoc_ary as $temp_mailbox_name=>$rawline) {
991 $final_folders_ary[]=$rawline;
995 // this will put it into an array we can use later
997 // raw - Raw LIST/LSUB response from the IMAP server
998 // formatted - formatted folder name
999 // unformatted - unformatted, but with the delimiter at the end removed
1000 // unformated-dm - folder name as it appears in raw response
1001 // unformatted-disp - unformatted without $folder_prefix
1002 // id - the array element number (0, 1, 2, etc.)
1003 // flags - mailbox flags
1004 if (!empty($final_folders_ary)) {
1005 $boxesall = sqimap_mailbox_parse($final_folders_ary);
1007 // they have no mailboxes
1011 /* Now, lets sort for special folders */
1012 $boxesnew = $used = array();
1015 $cnt = count($boxesall);
1016 $used = array_pad($used,$cnt,false);
1018 for($k = 0; $k < $cnt; ++
$k) {
1019 if (strtoupper($boxesall[$k]['unformatted']) == 'INBOX') {
1020 $boxesnew[] = $boxesall[$k];
1027 if ($has_inbox == false) {
1028 // do a list request for inbox because we should always show
1029 // inbox even if the user isn't subscribed to it.
1030 $inbox_ary = sqimap_run_command($imap_stream, 'LIST "" "INBOX"',
1031 true, $response, $message);
1032 $inbox_ary = compact_mailboxes_response($inbox_ary);
1033 if (count($inbox_ary)) {
1034 $inbox_entry = sqimap_mailbox_parse($inbox_ary);
1035 // add it on top of the list
1036 if (!empty($boxesnew)) {
1037 array_unshift($boxesnew,$inbox_entry[0]);
1039 $boxesnew[]=$inbox_entry[0];
1041 /* array_unshift($used,true); */
1045 /* List special folders and their subfolders, if requested. */
1046 if ($list_special_folders_first) {
1047 for($k = 0; $k < $cnt; ++
$k) {
1048 if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
1049 $boxesnew[] = $boxesall[$k];
1055 /* Find INBOX's children */
1056 for($k = 0; $k < $cnt; ++
$k) {
1057 $isboxbelow=isBoxBelow(strtoupper($boxesall[$k]['unformatted']),'INBOX');
1058 if (strtoupper($boxesall[$k]['unformatted']) == 'INBOX') {
1064 if (!$used[$k] && $isboxbelow && $is_inbox) {
1065 $boxesnew[] = $boxesall[$k];
1070 /* Rest of the folders */
1071 for($k = 0; $k < $cnt; $k++
) {
1073 $boxesnew[] = $boxesall[$k];
1077 * Don't register boxes in session, if $session_register is set to false
1078 * Prevents registration of sqimap_mailbox_list_all() results.
1080 if ($session_register) sqsession_register($boxesnew,'boxesnew');
1085 * Fills mailbox object
1087 * this is passed the mailbox array by left_main.php
1088 * who has previously obtained it from sqimap_get_mailboxes
1089 * that way, the raw mailbox list is available in left_main to other
1090 * things besides just sqimap_mailbox_tree
1091 * imap_stream is just used now to get status info
1093 * most of the functionality is moved to sqimap_get_mailboxes
1094 * also takes care of TODO items:
1095 * caching mailbox tree
1096 * config setting for UW imap section (not needed now)
1098 * Some code fragments are present in 1.3.0 - 1.4.4.
1099 * @param stream $imap_stream imap connection resource
1100 * @param array $lsub_ary output array from sqimap_get_mailboxes (contains mailboxes and flags)
1101 * @return object see mailboxes class.
1104 function sqimap_mailbox_tree($imap_stream,$lsub_ary) {
1106 $sorted_lsub_ary = array();
1107 $cnt = count($lsub_ary);
1108 for ($i = 0; $i < $cnt; $i++
) {
1109 $mbx=$lsub_ary[$i]['unformatted'];
1110 $flags=$lsub_ary[$i]['flags'];
1113 if (in_array('\Noinferiors',$flags)) { $noinferiors=1; }
1114 if (in_array('\NoInferiors',$flags)) { $noinferiors=1; }
1115 if (in_array('\HasNoChildren',$flags)) { $noinferiors=1; }
1118 if (in_array('\NoSelect',$flags)) { $noselect=1; }
1120 * LIST (SUBSCRIBED) has two new flags, \NonExistent which means the mailbox is subscribed to
1121 * but doesn't exist, and \PlaceHolder which is similar (but not the same) as \NoSelect
1122 * For right now, we'll treat these the same as \NoSelect and this behavior can be changed
1125 if (in_array('\NonExistent',$flags)) { $noselect=1; }
1126 if (in_array('\PlaceHolder',$flags)) { $noselect=1; }
1127 $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
1130 $sorted_lsub_ary = array_values($sorted_lsub_ary);
1131 usort($sorted_lsub_ary, 'mbxSort');
1132 $boxestree = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
1137 * Callback function used for sorting mailboxes in sqimap_mailbox_tree
1140 * @return integer see php strnatcasecmp()
1143 function mbxSort($a, $b) {
1144 return strnatcasecmp($a['mbx'], $b['mbx']);
1148 * Fills mailbox object
1150 * Some code fragments are present in 1.3.0 - 1.4.4.
1151 * @param array $mbx_ary
1153 * @param stream $imap_stream imap connection resource
1154 * @return object see mailboxes class
1157 function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
1158 global $data_dir, $username, $list_special_folders_first,
1159 $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
1160 $move_to_trash, $move_to_sent, $save_as_draft,
1161 $delimiter, $imap_server_type;
1163 // $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
1165 /* create virtual root node */
1166 $mailboxes= new mailboxes();
1167 $mailboxes->is_root
= true;
1171 if (isset($folder_prefix) && ($folder_prefix != '')) {
1172 $start = substr_count($folder_prefix,$delimiter);
1173 if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
1174 $mailboxes->mailboxname_full
= substr($folder_prefix,0, (strlen($folder_prefix)-1));
1176 $mailboxes->mailboxname_full
= $folder_prefix;
1179 $mailboxes->mailboxname_sub
= $mailboxes->mailboxname_full
;
1184 $cnt = count($mbx_ary);
1185 for ($i=0; $i < $cnt; $i++
) {
1186 if ($mbx_ary[$i]['mbx'] !='' ) {
1187 $mbx = new mailboxes();
1188 $mailbox = $mbx_ary[$i]['mbx'];
1191 * Set the is_special flag if it concerned a special mailbox.
1192 * Used for displaying the special folders on top in the mailbox
1193 * tree displaying code.
1195 $mbx->is_special |
= ($mbx->is_inbox
= (strtoupper($mailbox) == 'INBOX'));
1196 $mbx->is_special |
= ($mbx->is_trash
= isTrashMailbox($mailbox));
1197 $mbx->is_special |
= ($mbx->is_sent
= isSentMailbox($mailbox));
1198 $mbx->is_special |
= ($mbx->is_draft
= isDraftMailbox($mailbox));
1200 if (!$mbx->is_special
)
1201 $mbx->is_special
= boolean_hook_function('special_mailbox', $mailbox, 1);
1203 if (isset($mbx_ary[$i]['unseen'])) {
1204 $mbx->unseen
= $mbx_ary[$i]['unseen'];
1206 if (isset($mbx_ary[$i]['nummessages'])) {
1207 $mbx->total
= $mbx_ary[$i]['nummessages'];
1210 $mbx->is_noselect
= $mbx_ary[$i]['noselect'];
1211 $mbx->is_noinferiors
= $mbx_ary[$i]['noinferiors'];
1213 $r_del_pos = strrpos($mbx_ary[$i]['mbx'], $delimiter);
1215 $mbx->mailboxname_sub
= substr($mbx_ary[$i]['mbx'],$r_del_pos+
1);
1216 } else { /* mailbox is root folder */
1217 $mbx->mailboxname_sub
= $mbx_ary[$i]['mbx'];
1219 $mbx->mailboxname_full
= $mbx_ary[$i]['mbx'];
1221 $mailboxes->addMbx($mbx, $delimiter, $start, $list_special_folders_first);
1224 sqimap_utf7_decode_mbx_tree($mailboxes);
1225 sqimap_get_status_mbx_tree($imap_stream,$mailboxes);
1230 * @param object $mbx_tree
1233 function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
1234 global $draft_folder, $sent_folder, $trash_folder, $translate_special_folders;
1236 /* decode folder name and set mailboxname_sub */
1237 if ($translate_special_folders && strtoupper($mbx_tree->mailboxname_full
) == 'INBOX') {
1238 $mbx_tree->mailboxname_sub
= _("INBOX");
1239 } elseif ($translate_special_folders && $mbx_tree->mailboxname_full
== $draft_folder) {
1240 $mbx_tree->mailboxname_sub
= _("Drafts");
1241 } elseif ($translate_special_folders && $mbx_tree->mailboxname_full
== $sent_folder) {
1242 $mbx_tree->mailboxname_sub
= _("Sent");
1243 } elseif ($translate_special_folders && $mbx_tree->mailboxname_full
== $trash_folder) {
1244 $mbx_tree->mailboxname_sub
= _("Trash");
1246 $mbx_tree->mailboxname_sub
= imap_utf7_decode_local($mbx_tree->mailboxname_sub
);
1249 if ($mbx_tree->mbxs
) {
1250 $iCnt = count($mbx_tree->mbxs
);
1251 for ($i=0;$i<$iCnt;++
$i) {
1252 sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs
[$i]);
1258 * @param object $mbx_tree
1259 * @param array $aMbxs
1262 function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
1264 $aMbxs[] =& $mbx_tree;
1265 if ($mbx_tree->mbxs
) {
1266 $iCnt = count($mbx_tree->mbxs
);
1267 for ($i=0;$i<$iCnt;++
$i) {
1268 sqimap_tree_to_ref_array($mbx_tree->mbxs
[$i],$aMbxs);
1274 * @param stream $imap_stream imap connection resource
1275 * @param object $mbx_tree
1276 * @since since 1.5.0
1278 function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
1279 global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
1280 $aMbxs = $aQuery = array();
1281 sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
1282 // remove the root node
1283 array_shift($aMbxs);
1285 if($unseen_notify == 3) {
1286 $cnt = count($aMbxs);
1287 for($i=0;$i<$cnt;++
$i) {
1288 $oMbx =& $aMbxs[$i];
1289 if (!$oMbx->is_noselect
) {
1290 $mbx = $oMbx->mailboxname_full
;
1291 if ($unseen_type == 2 ||
1292 ($move_to_trash && $oMbx->mailboxname_full
== $trash_folder)) {
1293 $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN RECENT)';
1295 $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN RECENT)';
1297 sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
1299 $oMbx->unseen
= $oMbx->total
= $oMbx->recent
= false;
1303 $aMbxs[$i] =& $oMbx;
1305 // execute all the queries at once
1306 $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
1307 $cnt = count($aMbxs);
1308 for($i=0;$i<$cnt;++
$i) {
1309 $oMbx =& $aMbxs[$i];
1311 if ($tag && $aServerResponse[$tag] == 'OK') {
1312 $sResponse = implode('', $aResponse[$tag]);
1313 if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
1314 $oMbx->unseen
= $regs[1];
1316 if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
1317 $oMbx->total
= $regs[1];
1319 if (preg_match('/RECENT\s+([0-9]+)/i', $sResponse, $regs)) {
1320 $oMbx->recent
= $regs[1];
1326 } else if ($unseen_notify == 2) { // INBOX only
1327 $cnt = count($aMbxs);
1328 for($i=0;$i<$cnt;++
$i) {
1329 $oMbx =& $aMbxs[$i];
1330 if (strtoupper($oMbx->mailboxname_full
) == 'INBOX' ||
1331 ($move_to_trash && $oMbx->mailboxname_full
== $trash_folder)) {
1332 if ($unseen_type == 2 ||
1333 ($oMbx->mailboxname_full
== $trash_folder && $move_to_trash)) {
1334 $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full
);
1335 $oMbx->unseen
= $aStatus['UNSEEN'];
1336 $oMbx->total
= $aStatus['MESSAGES'];
1337 $oMbx->recent
= $aStatus['RECENT'];
1339 $oMbx->unseen
= sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full
);
1341 $aMbxs[$i] =& $oMbx;
1342 if (!$move_to_trash && $trash_folder) {
1345 // trash comes after INBOX
1346 if ($oMbx->mailboxname_full
== $trash_folder) {
1354 $cnt = count($aMbxs);
1355 for($i=0;$i<$cnt;++
$i) {
1356 $oMbx =& $aMbxs[$i];
1357 unset($hook_status);
1358 if (!empty($oMbx->unseen
)) { $hook_status['UNSEEN']=$oMbx->unseen
; }
1359 if (!empty($oMbx->total
)) { $hook_status['MESSAGES']=$oMbx->total
; }
1360 if (!empty($oMbx->recent
)) { $hook_status['RECENT']=$oMbx->recent
; }
1361 if (!empty($hook_status))
1363 $hook_status['MAILBOX']=$oMbx->mailboxname_full
;
1364 $hook_status['CALLER']='sqimap_get_status_mbx_tree'; // helps w/ debugging
1365 do_hook_function('folder_status',$hook_status);
1371 * Checks if folder is noselect (can't store messages)
1373 * Function does not check if folder subscribed.
1374 * @param stream $oImapStream imap connection resource
1375 * @param string $sImapFolder imap folder name
1376 * @param object $oBoxes mailboxes class object.
1377 * @return boolean true, when folder has noselect flag. false in any other case.
1380 function sqimap_mailbox_is_noselect($oImapStream,$sImapFolder,&$oBoxes) {
1381 // build mailbox object if it is not available
1382 if (! is_object($oBoxes)) $oBoxes=sqimap_mailbox_list($oImapStream);
1383 foreach($oBoxes as $box) {
1384 if ($box['unformatted']==$sImapFolder) {
1385 return (bool) check_is_noselect($box['raw']);
1392 * Checks if folder is noinferiors (can't store other folders)
1394 * Function does not check if folder subscribed.
1395 * @param stream $oImapStream imap connection resource
1396 * @param string $sImapFolder imap folder name
1397 * @param object $oBoxes mailboxes class object.
1398 * @return boolean true, when folder has noinferiors flag. false in any other case.
1401 function sqimap_mailbox_is_noinferiors($oImapStream,$sImapFolder,&$oBoxes) {
1402 // build mailbox object if it is not available
1403 if (! is_object($oBoxes)) $oBoxes=sqimap_mailbox_list($oImapStream);
1404 foreach($oBoxes as $box) {
1405 if ($box['unformatted']==$sImapFolder) {
1406 return (bool) check_is_noinferiors($box['raw']);