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
33
var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false, $is_noinferiors = false,
22
var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false,
34
23
$is_special = false, $is_root = false, $is_inbox = false, $is_sent = false,
35
$is_trash = false, $is_draft = false, $mbxs = array(),
24
$is_trash = false, $is_draft = false, $mbxs = array(),
36
25
$unseen = false, $total = false;
38
27
function addMbx($mbx, $delimiter, $start, $specialfirst) {
39
28
$ary = explode($delimiter, $mbx->mailboxname_full);
41
30
for ($i = $start, $c = count($ary)-1; $i < $c; $i++) {
42
$mbx_childs =& $mbx_parent->mbxs;
31
$mbx_childs = &$mbx_parent->mbxs;
45
34
foreach ($mbx_childs as $key => $parent) {
46
35
if ($parent->mailboxname_sub == $ary[$i]) {
47
$mbx_parent =& $mbx_parent->mbxs[$key];
36
$mbx_parent = &$mbx_parent->mbxs[$key];
86
74
$bcmp = '2' . $b->mailboxname_full;
88
return strnatcasecmp($acmp, $bcmp);
91
function compact_mailboxes_response($ary)
94
* Workaround for mailboxes returned as literal
95
* FIXME : Doesn't work if the mailbox name is multiple lines
96
* (larger then fgets buffer)
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]*)$",
102
$ary[$i] = $regs[1] . '"' . addslashes(trim($ary[$i+1])) . '"' . $regs[2];
103
array_splice($ary, $i+1, 2);
107
/* remove duplicates and ensure array is contiguous */
108
return array_values(array_unique($ary));
112
* Extract the mailbox name from an untagged LIST (7.2.2) or LSUB (7.2.3) answer
113
* (LIST|LSUB) (<Flags list>) (NIL|"<separator atom>") <mailbox name string>\r\n
114
* mailbox name in quoted string MUST be unquoted and stripslashed (sm API)
116
function find_mailbox_name($line)
118
if (preg_match('/^\* (?:LIST|LSUB) \([^\)]*\) (?:NIL|\"[^\"]*\") ([^\r\n]*)[\r\n]*$/i', $line, $regs)) {
119
if (substr($regs[1], 0, 1) == '"')
120
return stripslashes(substr($regs[1], 1, -1));
76
if ($acmp == $bcmp) return 0;
77
return ($acmp > $bcmp) ? 1: -1;
80
function find_mailbox_name ($mailbox) {
81
if (preg_match('/\*.+\"([^\r\n\"]*)\"[\s\r\n]*$/', $mailbox, $regs))
83
if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
85
ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
127
90
* @return bool whether this is a Noselect mailbox.
129
92
function check_is_noselect ($lsub_line) {
130
return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noselect[^\)]*\)/i", $lsub_line);
134
* @return bool whether this is a Noinferiors mailbox.
136
function check_is_noinferiors ($lsub_line) {
137
return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noinferiors[^\)]*\)/i", $lsub_line);
93
return preg_match("/^\* LSUB \([^\)]*\\Noselect[^\)]*\)/i", $lsub_line);
252
* Expunge specified message, updated $msgs and $msort
254
* Until Marc and I come up with a better way to maintain
255
* these stupid arrays, we'll use this wrapper function to
256
* remove the message with the matching UID .. the order
257
* won't be changed - the array element for the message
258
* will just be removed.
260
function sqimap_mailbox_expunge_dmn($message_id)
262
global $msgs, $msort, $sort, $imapConnection,
263
$mailbox, $uid_support, $mbx_response, $auto_expunge,
264
$sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
265
$username, $data_dir;
267
// Got to grab this out of prefs, since it isn't saved from mailbox_view.php
268
if ($allow_thread_sort) {
269
$thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0);
272
for ($i = 0; $i < count($msort); $i++) {
273
if ($msgs[$i]['ID'] == $message_id) {
281
$msgs = array_values($msgs);
282
$msort = array_values($msort);
284
sqsession_register($msgs, 'msgs');
285
sqsession_register($msort, 'msort');
288
sqimap_mailbox_expunge($imapConnection, $mailbox, true);
291
// And after all that mucking around, update the sort list!
292
// Remind me why the hell we need those two arrays again?!
293
if ( $allow_thread_sort && $thread_sort_messages ) {
294
$server_sort_array = get_thread_sort($imapConnection);
295
} elseif ( $allow_server_sort ) {
296
$server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response);
297
} elseif ( $uid_support ) {
298
$server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response);
304
211
* Checks whether or not the specified mailbox exists
306
213
function sqimap_mailbox_exists ($imap_stream, $mailbox) {
307
214
if (!isset($mailbox) || empty($mailbox)) {
310
$mbx = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mailbox),
217
$mbx = sqimap_run_command($imap_stream, "LIST \"\" \"$mailbox\"",
311
218
true, $response, $message);
312
219
return isset($mbx[0]);
609
* Returns sorted mailbox lists in several different ways.
524
* Mailboxes with some chars (like -) can mess up the order, this fixes it
526
function mailtree_sort(&$lsub) {
527
if(!is_array($lsub)) return;
529
foreach($lsub as $index => $mailbox)
530
$lsub[$index] = str_replace('.',' -#- ',$lsub[$index]);
532
usort($lsub, 'user_strcasecmp');
534
foreach($lsub as $index => $mailbox)
535
$lsub[$index] = str_replace(' -#- ','.',$lsub[$index]);
539
* Returns sorted mailbox lists in several different ways.
610
540
* See comment on sqimap_mailbox_parse() for info about the returned array.
612
function sqimap_mailbox_list($imap_stream) {
544
function sqimap_mailbox_list($imap_stream, $force=false) {
613
545
global $default_folder_prefix;
615
if (!isset($boxesnew)) {
547
if (!sqgetGlobalVar('boxesnew',$boxesnew,SQ_SESSION) || $force) {
616
548
global $data_dir, $username, $list_special_folders_first,
617
549
$folder_prefix, $trash_folder, $sent_folder, $draft_folder,
618
550
$move_to_trash, $move_to_sent, $save_as_draft,
619
551
$delimiter, $noselect_fix_enable;
621
552
$inbox_in_list = false;
622
553
$inbox_subscribed = false;
632
563
$lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
633
564
true, $response, $message);
634
$lsub_ary = compact_mailboxes_response($lsub_ary);
636
566
$sorted_lsub_ary = array();
637
567
for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
569
* Workaround for mailboxes returned as literal
570
* Doesn't work if the mailbox name is multiple lines
571
* (larger then fgets buffer)
573
if (isset($lsub_ary[$i + 1]) && substr($lsub_ary[$i],-3) == "}\r\n") {
574
if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
575
$lsub_ary[$i], $regs)) {
577
$lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
638
580
$temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
639
581
$sorted_lsub_ary[] = $temp_mailbox_name;
640
582
if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
641
583
$inbox_subscribed = true;
586
/* remove duplicates */
587
$sorted_lsub_ary = array_unique($sorted_lsub_ary);
645
589
/* natural sort mailboxes */
646
590
if (isset($sorted_lsub_ary)) {
647
usort($sorted_lsub_ary, 'strnatcasecmp');
591
mailtree_sort($sorted_lsub_ary);
650
594
* The LSUB response doesn't provide us information about \Noselect
662
606
$mbx = $sorted_lsub_ary[$i];
664
$mbx = stripslashes($mbx);
665
$read = sqimap_run_command ($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx),
609
$read = sqimap_run_command ($imap_stream, "LIST \"\" \"$mbx\"",
666
610
true, $response, $message);
667
$read = compact_mailboxes_response($read);
612
/* Another workaround for literals */
614
if (isset($read[1]) && substr($read[1],-3) == "}\r\n") {
615
if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
617
$read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
668
621
if (isset($read[0])) {
669
622
$sorted_list_ary[$i] = $read[0];
671
624
$sorted_list_ary[$i] = '';
675
629
* Just in case they're not subscribed to their inbox,
676
630
* we'll get it for them anyway
678
632
if (!$inbox_subscribed) {
679
$inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
633
$inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
680
634
true, $response, $message);
681
$sorted_list_ary[] = implode('', compact_mailboxes_response($inbox_ary));
635
/* Another workaround for literals */
636
if (isset($inbox_ary[1]) && substr($inbox_ary[0],-3) == "}\r\n") {
637
if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
638
$inbox_ary[0], $regs)) {
639
$inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
643
$sorted_list_ary[] = $inbox_ary[0];
682
644
$sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
724
686
function sqimap_mailbox_list_all($imap_stream) {
725
687
global $list_special_folders_first, $folder_prefix, $delimiter;
727
$read_ary = sqimap_run_command($imap_stream,"LIST \"$folder_prefix\" *",true,$response, $message,false);
728
$read_ary = compact_mailboxes_response($read_ary);
689
$ssid = sqimap_session_id();
690
$lsid = strlen( $ssid );
691
fputs ($imap_stream, $ssid . " LIST \"$folder_prefix\" *\r\n");
692
$read_ary = sqimap_read_data ($imap_stream, $ssid, true, $response, $message);
731
694
$phase = 'inbox';
732
695
$fld_pre_length = strlen($folder_prefix);
733
697
for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
734
/* Store the raw IMAP reply */
735
$boxes[$g]['raw'] = $read_ary[$i];
737
/* Count number of delimiters ($delimiter) in folder name */
738
$mailbox = find_mailbox_name($read_ary[$i]);
739
$dm_count = substr_count($mailbox, $delimiter);
740
if (substr($mailbox, -1) == $delimiter) {
741
/* If name ends in delimiter - decrement count by one */
745
/* Format folder name, but only if it's a INBOX.* or has a parent. */
746
$boxesallbyname[$mailbox] = $g;
747
$parentfolder = readMailboxParent($mailbox, $delimiter);
748
if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
749
(ereg('^'.$folder_prefix, $mailbox)) ||
750
( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
752
$boxes[$g]['formatted'] = str_repeat(' ', $dm_count);
754
$boxes[$g]['formatted'] = '';
756
$boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
758
$boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
761
$boxes[$g]['unformatted-dm'] = $mailbox;
762
if (substr($mailbox, -1) == $delimiter) {
763
$mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
765
$boxes[$g]['unformatted'] = $mailbox;
766
$boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
768
$boxes[$g]['id'] = $g;
770
/* Now lets get the flags for this mailbox */
771
$read_mlbx = $read_ary[$i];
772
$flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
773
$flags = substr($flags, 0, strpos($flags, ')'));
774
$flags = str_replace('\\', '', $flags);
775
$flags = trim(strtolower($flags));
777
$boxes[$g]['flags'] = explode(' ', $flags);
779
$boxes[$g]['flags'] = array();
698
/* Another workaround for EIMS */
699
if (isset($read_ary[$i + 1]) &&
700
ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
701
$read_ary[$i], $regs)) {
703
$read_ary[$i] = $regs[1] . '"' . addslashes(trim($read_ary[$i])) . '"' . $regs[2];
705
if (substr($read_ary[$i], 0, $lsid) != $ssid ) {
706
/* Store the raw IMAP reply */
707
$boxes[$g]['raw'] = $read_ary[$i];
709
/* Count number of delimiters ($delimiter) in folder name */
710
$mailbox = find_mailbox_name($read_ary[$i]);
711
$dm_count = substr_count($mailbox, $delimiter);
712
if (substr($mailbox, -1) == $delimiter) {
713
/* If name ends in delimiter - decrement count by one */
717
/* Format folder name, but only if it's a INBOX.* or has a parent. */
718
$boxesallbyname[$mailbox] = $g;
719
$parentfolder = readMailboxParent($mailbox, $delimiter);
720
if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
721
(ereg('^'.$folder_prefix, $mailbox)) ||
722
( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
724
$boxes[$g]['formatted'] = str_repeat(' ', $dm_count);
726
$boxes[$g]['formatted'] = '';
728
$boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
730
$boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
733
$boxes[$g]['unformatted-dm'] = $mailbox;
734
if (substr($mailbox, -1) == $delimiter) {
735
$mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
737
$boxes[$g]['unformatted'] = $mailbox;
738
$boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
740
$boxes[$g]['id'] = $g;
742
/* Now lets get the flags for this mailbox */
743
$read_mlbx = $read_ary[$i];
745
// $read_mlbx = sqimap_run_command ($imap_stream, "LIST \"\" \"$mailbox\"",
746
// true, $response, $message);
748
/* Another workaround for EIMS */
749
// if (isset($read_mlbx[1]) &&
750
// ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", $read_mlbx[0], $regs)) {
751
// $read_mlbx[0] = $regs[1] . '"' . addslashes(trim($read_mlbx[1])) . '"' . $regs[2];
753
// echo $read_mlbx[0] .' raw 2 <br>';
755
$flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
756
$flags = substr($flags, 0, strpos($flags, ')'));
757
$flags = str_replace('\\', '', $flags);
758
$flags = trim(strtolower($flags));
760
$boxes[$g]['flags'] = explode(' ', $flags);
762
$boxes[$g]['flags'] = array();
792
776
if (!isset($boxesnew)) {
794
778
global $data_dir, $username, $list_special_folders_first,
795
$folder_prefix, $delimiter, $trash_folder, $move_to_trash,
779
$folder_prefix, $delimiter, $trash_folder, $move_to_trash;
799
782
$inbox_in_list = false;
800
783
$inbox_subscribed = false;
802
$noinferiors = false;
804
785
require_once(SM_PATH . 'include/load_prefs.php');
807
788
$lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
808
789
true, $response, $message);
809
$lsub_ary = compact_mailboxes_response($lsub_ary);
811
/* Check to see if we have an INBOX */
814
for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
815
if (preg_match("/^\*\s+LSUB\s+(.*)\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
816
$lsub_ary[$i] = strtoupper($lsub_ary[$i]);
822
if ($has_inbox == false) {
823
$lsub_ary[] = '* LSUB () NIL INBOX';
827
* Section about removing the last element was removed
792
* Section about removing the last element was removed
828
793
* We don't return "* OK" anymore from sqimap_read_data
831
795
$sorted_lsub_ary = array();
832
796
$cnt = count($lsub_ary);
833
797
for ($i = 0; $i < $cnt; $i++) {
799
* Workaround for EIMS
800
* Doesn't work if the mailbox name is multiple lines
802
if (isset($lsub_ary[$i + 1]) &&
803
ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
804
$lsub_ary[$i], $regs)) {
806
$lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
810
if (preg_match("/^\*\s+LSUB\s+\((.*)\)\s+\"(.*)\"\s+\"?(.+(?=\")|.+).*$/",$lsub_ary[$i],$regs)) {
812
$mbx = trim($regs[3]);
813
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => $flag);
834
816
$mbx = find_mailbox_name($lsub_ary[$i]);
836
// only do the noselect test if !uw, is checked later. FIX ME see conf.pl setting
837
if ($imap_server_type != "uw") {
838
$noselect = check_is_noselect($lsub_ary[$i]);
839
$noinferiors = check_is_noinferiors($lsub_ary[$i]);
841
if (substr($mbx, -1) == $delimiter) {
842
$mbx = substr($mbx, 0, strlen($mbx) - 1);
844
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
846
// FIX ME this requires a config setting inside conf.pl instead of checking on server type
847
if ($imap_server_type == "uw") {
850
// prepare an array with queries
851
foreach ($sorted_lsub_ary as $aMbx) {
852
$mbx = stripslashes($aMbx['mbx']);
853
sqimap_prepare_pipelined_query('LIST "" ' . sqimap_encode_mailbox_name($mbx), $tag, $aQuery, false);
856
$sorted_lsub_ary = array();
857
// execute all the queries at once
858
$aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
859
foreach($aTag as $tag => $mbx) {
860
if ($aServerResponse[$tag] == 'OK') {
861
$sResponse = implode('', $aResponse[$tag]);
862
$noselect = check_is_noselect($sResponse);
863
$noinferiors = check_is_noinferiors($sResponse);
864
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
867
$cnt = count($sorted_lsub_ary);
869
$sorted_lsub_ary = array_values($sorted_lsub_ary);
870
array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
871
$boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
817
$noselect = check_is_noselect($lsub_ary[$i]);
818
if (substr($mbx, -1) == $delimiter) {
819
$mbx = substr($mbx, 0, strlen($mbx) - 1);
821
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect);
823
array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
825
for($i = 0; $i < $cnt; $i++) {
826
if ($sorted_lsub_ary[$i]['mbx'] == 'INBOX') {
827
$inbox_in_list = true;
833
* Just in case they're not subscribed to their inbox,
834
* we'll get it for them anyway
836
if (!$inbox_in_list) {
837
$inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
838
true, $response, $message);
839
/* Another workaround for EIMS */
840
if (isset($inbox_ary[1]) &&
841
ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
842
$inbox_ary[0], $regs)) {
843
$inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
846
$mbx = find_mailbox_name($inbox_ary[0]);
847
if (substr($mbx, -1) == $delimiter) {
848
$mbx = substr($mbx, 0, strlen($mbx) - 1);
850
if ($mbx == 'INBOX') {
851
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => '');
852
sqimap_subscribe($imap_stream, 'INBOX');
857
if (preg_match("/^\*\s+LIST\s+\((.*)\)\s+\"(.*)\"\s+\"?(.+(?=\")|.+).*$/",$inbox_ary[0],$regs)) {
859
$mbx = trim($regs[3]);
860
if (substr($mbx, -1) == $delimiter) {
861
$mbx = substr($mbx, 0, strlen($mbx) - 1);
863
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => $flag);
867
for ($i = 0 ; $i < $cnt; $i++) {
868
$mbx = $sorted_lsub_ary[$i]['mbx'];
869
if (($unseen_notify == 2 && $mbx == 'INBOX') ||
870
($unseen_notify == 3) ||
871
($move_to_trash && ($mbx == $trash_folder))) {
872
if($sorted_lsub_ary[$i]['noselect']) {
873
$sorted_lsub_ary[$i]['unseen'] = 0;
875
$sorted_lsub_ary[$i]['unseen'] =
876
sqimap_unseen_messages($imap_stream, $mbx);
878
if (($unseen_type == 2) ||
879
($move_to_trash && ($mbx == $trash_folder)) ||
880
($mbx == $trash_folder)) {
881
if($sorted_lsub_ary[$i]['noselect']) {
882
$sorted_lsub_ary[$i]['nummessages'] = 0;
884
$sorted_lsub_ary[$i]['nummessages'] =
885
sqimap_get_num_messages($imap_stream, $mbx);
890
$boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary);
876
function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
895
function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false) {
877
896
global $data_dir, $username, $list_special_folders_first,
878
897
$folder_prefix, $trash_folder, $sent_folder, $draft_folder,
879
898
$move_to_trash, $move_to_sent, $save_as_draft,
880
$delimiter, $imap_server_type;
882
901
$special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
973
963
$mailboxes->addMbx($mbx, $delimiter, $start, $list_special_folders_first);
976
sqimap_utf7_decode_mbx_tree($mailboxes);
977
sqimap_get_status_mbx_tree($imap_stream,$mailboxes);
978
967
return $mailboxes;
981
function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
982
if (strtoupper($mbx_tree->mailboxname_sub) == 'INBOX')
983
$mbx_tree->mailboxname_sub = _("INBOX");
985
$mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);
986
if ($mbx_tree->mbxs) {
987
$iCnt = count($mbx_tree->mbxs);
988
for ($i=0;$i<$iCnt;++$i) {
989
$mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
995
function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
997
$aMbxs[] =& $mbx_tree;
998
if ($mbx_tree->mbxs) {
999
$iCnt = count($mbx_tree->mbxs);
1000
for ($i=0;$i<$iCnt;++$i) {
1001
sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
1006
function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
1007
global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
1008
$aMbxs = $aQuery = $aTag = array();
1009
sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
1010
// remove the root node
1011
array_shift($aMbxs);
1013
if($unseen_notify == 3) {
1014
$cnt = count($aMbxs);
1015
for($i=0;$i<$cnt;++$i) {
1016
$oMbx =& $aMbxs[$i];
1017
if (!$oMbx->is_noselect) {
1018
$mbx = $oMbx->mailboxname_full;
1019
if ($unseen_type == 2 ||
1020
($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
1021
$query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN)';
1023
$query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN)';
1025
sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
1027
$oMbx->unseen = $oMbx->total = false;
1031
$aMbxs[$i] =& $oMbx;
1033
// execute all the queries at once
1034
$aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
1035
$cnt = count($aMbxs);
1036
for($i=0;$i<$cnt;++$i) {
1037
$oMbx =& $aMbxs[$i];
1039
if ($tag && $aServerResponse[$tag] == 'OK') {
1040
$sResponse = implode('', $aResponse[$tag]);
1041
if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
1042
$oMbx->unseen = $regs[1];
1044
if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
1045
$oMbx->total = $regs[1];
1050
} else if ($unseen_notify == 2) { // INBOX only
1051
$cnt = count($aMbxs);
1052
for($i=0;$i<$cnt;++$i) {
1053
$oMbx =& $aMbxs[$i];
1054
if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
1055
($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
1056
if ($unseen_type == 2 ||
1057
($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
1058
$aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
1059
$oMbx->unseen = $aStatus['UNSEEN'];
1060
$oMbx->total = $aStatus['MESSAGES'];
1062
$oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
1064
$aMbxs[$i] =& $oMbx;
1065
if (!$move_to_trash && $trash_folder) {
1068
// trash comes after INBOX
1069
if ($oMbx->mailboxname_full == $trash_folder) {
b'\\ No newline at end of file'