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

imap_mailbox.php
Go to the documentation of this file.
1 <?php
2 
16 require_once(SM_PATH . 'functions/imap_utf7_local.php');
17 
18 global $boxesnew;
19 
20 function sortSpecialMbx($a, $b) {
21  if ($a->is_inbox) {
22  $acmp = '0'. $a->mailboxname_full;
23  } else if ($a->is_special) {
24  $acmp = '1'. $a->mailboxname_full;
25  } else {
26  $acmp = '2' . $a->mailboxname_full;
27  }
28  if ($b->is_inbox) {
29  $bcmp = '0'. $b->mailboxname_full;
30  }else if ($b->is_special) {
31  $bcmp = '1' . $b->mailboxname_full;
32  } else {
33  $bcmp = '2' . $b->mailboxname_full;
34  }
35  if ($acmp == $bcmp) return 0;
36  return ($acmp > $bcmp) ? 1: -1;
37 }
38 
40  if (preg_match('/\*.+\"([^\r\n\"]*)\"[\s\r\n]*$/', $mailbox, $regs))
41  return $regs[1];
42  if (preg_match('/ *"([^\r\n"]*)"[ \r\n]*$/', $mailbox, $regs))
43  return $regs[1];
44  preg_match('/ *([^ \r\n"]*)[ \r\n]*$/',$mailbox,$regs);
45  return $regs[1];
46 }
47 
51 function check_is_noselect ($lsub_line) {
52  return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noselect[^\)]*\)/i", $lsub_line);
53 }
54 
60 function readMailboxParent($haystack, $needle) {
61  if ($needle == '') {
62  $ret = '';
63  } else {
64  $parts = explode($needle, $haystack);
65  $elem = array_pop($parts);
66  while ($elem == '' && count($parts)) {
67  $elem = array_pop($parts);
68  }
69  $ret = join($needle, $parts);
70  }
71  return( $ret );
72 }
73 
77 function isBoxBelow( $subbox, $parentbox ) {
78  global $delimiter;
79  /*
80  * Eliminate the obvious mismatch, where the
81  * subfolder path is shorter than that of the potential parent
82  */
83  if ( strlen($subbox) < strlen($parentbox) ) {
84  return false;
85  }
86  /* check for delimiter */
87  if (substr($parentbox,-1) != $delimiter) {
88  $parentbox.=$delimiter;
89  }
90  if (substr($subbox,0,strlen($parentbox)) == $parentbox) {
91  return true;
92  } else {
93  return false;
94  }
95 }
96 
118 function isSpecialMailbox($box,$include_subs=true) {
119  global $subfolders_of_inbox_are_special;
120  $ret = ( ($subfolders_of_inbox_are_special && isInboxMailbox($box,$include_subs)) ||
121  (!$subfolders_of_inbox_are_special && strtolower($box) == 'inbox') ||
122  isTrashMailbox($box,$include_subs) ||
123  isSentMailbox($box,$include_subs) ||
124  isDraftMailbox($box,$include_subs) );
125 
126  if ( !$ret ) {
127  $ret = boolean_hook_function('special_mailbox',$box,1);
128  }
129  return $ret;
130 }
131 
144 function isInboxMailbox($box, $include_subs=TRUE) {
145  return ((strtolower($box) == 'inbox')
146  || ($include_subs && isBoxBelow(strtolower($box), 'inbox')));
147 }
148 
149 
158 function isTrashMailbox ($box,$include_subs=true) {
160  return $move_to_trash && $trash_folder &&
161  ( $box == $trash_folder ||
162  ($include_subs && isBoxBelow($box, $trash_folder)) );
163 }
164 
173 function isSentMailbox($box,$include_subs=true) {
174  global $sent_folder, $move_to_sent;
175  return $move_to_sent && $sent_folder &&
176  ( $box == $sent_folder ||
177  ($include_subs && isBoxBelow($box, $sent_folder)) );
178 }
179 
188 function isDraftMailbox($box,$include_subs=true) {
190  return $save_as_draft &&
191  ( $box == $draft_folder ||
192  ($include_subs && isBoxBelow($box, $draft_folder)) );
193 }
194 
198 function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
199  global $uid_support;
200  if ($id) {
201  if (is_array($id)) {
203  }
204  $id = ' '.$id;
205  $uid = $uid_support;
206  } else {
207  $uid = false;
208  }
209  $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
210  $response, $message, $uid);
211  $cnt = 0;
212 
213  if (is_array($read)) {
214  foreach ($read as $r) {
215  if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
216  $cnt++;
217  }
218  }
219  }
220  return $cnt;
221 }
222 
227  if (!isset($mailbox) || empty($mailbox)) {
228  return false;
229  }
230  $mbx = sqimap_run_command($imap_stream, "LIST \"\" \"$mailbox\"",
231  true, $response, $message);
232  return isset($mbx[0]);
233 }
234 
239  global $auto_expunge;
240 
241  if (empty($mailbox)) {
242  return;
243  }
244 
254  if (strstr($mailbox, '../') || substr($mailbox, 0, 1) == '/') {
255  global $color;
256  include_once(SM_PATH . 'functions/display_messages.php');
257  error_box(sprintf(_("Invalid mailbox name: %s"),htmlspecialchars($mailbox)),$color);
259  die('</body></html>');
260  }
261 
262  // cleanup $mailbox in order to prevent IMAP injection attacks
263  $mailbox = str_replace(array("\r","\n"), array("",""),$mailbox);
264 
265  $read = sqimap_run_command($imap_stream, "SELECT \"$mailbox\"",
266  true, $response, $message);
267  $result = array();
268  for ($i = 0, $cnt = count($read); $i < $cnt; $i++) {
269  if (preg_match('/^\*\s+OK\s\[(\w+)\s(\w+)\]/',$read[$i], $regs)) {
270  $result[strtoupper($regs[1])] = $regs[2];
271  } else if (preg_match('/^\*\s([0-9]+)\s(\w+)/',$read[$i], $regs)) {
272  $result[strtoupper($regs[2])] = $regs[1];
273  } else {
274  if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
275  $regs[1]=trim(preg_replace ( array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
276  $result['PERMANENTFLAGS'] = $regs[1];
277  } else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
278  $regs[1]=trim(preg_replace ( array ("/\(/","/\)/") ,'', $regs[1])) ;
279  $result['FLAGS'] = $regs[1];
280  }
281  }
282  }
283  if (preg_match('/^\[(.+)\]/',$message, $regs)) {
284  $result['RIGHTS']=$regs[1];
285  }
286 
287  if ($auto_expunge) {
288  $tmp = sqimap_run_command($imap_stream, 'EXPUNGE', false, $a, $b);
289  }
290  return $result;
291 }
292 
297  global $delimiter;
298  if (strtolower($type) == 'noselect') {
299  $create_mailbox = $mailbox . $delimiter;
300  } else {
301  $create_mailbox = $mailbox;
302  }
303 
304  $read_ary = sqimap_run_command($imap_stream, "CREATE \"$create_mailbox\"",
305  true, $response, $message);
307 }
308 
313  $read_ary = sqimap_run_command($imap_stream, "SUBSCRIBE \"$mailbox\"",
314  true, $response, $message);
315 }
316 
321  $read_ary = sqimap_run_command($imap_stream, "UNSUBSCRIBE \"$mailbox\"",
322  false, $response, $message);
323 }
324 
329  global $data_dir, $username;
332  $read_ary = sqimap_run_command($imap_stream, "DELETE \"$mailbox\"",
333  true, $response, $message);
334  if ($response !== 'OK') {
335  // subscribe again
337  } else {
338  do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
339  removePref($data_dir, $username, "thread_$mailbox");
340  removePref($data_dir, $username, "collapse_folder_$mailbox");
341  }
342  }
343 }
344 
349  $boxesall = sqimap_mailbox_list ($imap_stream);
350  foreach ($boxesall as $ref) {
351  if ($ref['unformatted'] == $folder) {
352  return true;
353  }
354  }
355  return false;
356 }
357 
362  if ( $old_name != $new_name ) {
363  global $delimiter, $imap_server_type, $data_dir, $username;
364  if ( substr( $old_name, -1 ) == $delimiter ) {
365  $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
366  $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 );
367  $postfix = $delimiter;
368  } else {
369  $postfix = '';
370  }
371 
373  $cmd = 'RENAME "' . $old_name . '" "' . $new_name . '"';
374  $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
376  $oldpref_thread = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
377  $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
378  removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
379  removePref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
381  setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref_thread);
382  setPref($data_dir, $username, 'collapse_folder_'.$new_name.$postfix, $oldpref_collapse);
383  do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
384  $l = strlen( $old_name ) + 1;
385  $p = 'unformatted';
386 
387  foreach ($boxesall as $box) {
388  if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
389  $new_sub = $new_name . $delimiter . substr($box[$p], $l);
390  /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */
391  if ($imap_server_type == 'cyrus') {
392  $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
393  $data = sqimap_run_command($imap_stream, $cmd, false,
394  $response, $message);
395  }
396  $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]);
397  if ( $was_subscribed ) {
398  sqimap_unsubscribe($imap_stream, $box[$p]);
399  }
400  $oldpref_thread = getPref($data_dir, $username, 'thread_'.$box[$p]);
401  $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$box[$p]);
402  removePref($data_dir, $username, 'thread_'.$box[$p]);
403  removePref($data_dir, $username, 'collapse_folder_'.$box[$p]);
404  if ( $was_subscribed ) {
405  sqimap_subscribe($imap_stream, $new_sub);
406  }
407  setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref_thread);
408  setPref($data_dir, $username, 'collapse_folder_'.$new_sub, $oldpref_collapse);
409  do_hook_function('rename_or_delete_folder',
410  $args = array($box[$p], 'rename', $new_sub));
411  }
412  }
413  }
414 }
415 
427 function sqimap_mailbox_parse ($line, $line_lsub) {
428  global $folder_prefix, $delimiter;
429 
430  /* Process each folder line */
431  for ($g = 0, $cnt = count($line); $g < $cnt; ++$g) {
432  /* Store the raw IMAP reply */
433  if (isset($line[$g])) {
434  $boxesall[$g]['raw'] = $line[$g];
435  } else {
436  $boxesall[$g]['raw'] = '';
437  }
438 
439  /* Count number of delimiters ($delimiter) in folder name */
440  $mailbox = $line_lsub[$g];
441  $dm_count = substr_count($mailbox, $delimiter);
442  if (substr($mailbox, -1) == $delimiter) {
443  /* If name ends in delimiter, decrement count by one */
444  $dm_count--;
445  }
446 
447  /* Format folder name, but only if it's a INBOX.* or has a parent. */
448  $boxesallbyname[$mailbox] = $g;
449  $parentfolder = readMailboxParent($mailbox, $delimiter);
450  if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
451  (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
452  (isset($boxesallbyname[$parentfolder]) &&
453  (strlen($parentfolder) > 0) ) ) {
454  $indent = $dm_count - (substr_count($folder_prefix, $delimiter));
455  if ($indent > 0) {
456  $boxesall[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $indent);
457  } else {
458  $boxesall[$g]['formatted'] = '';
459  }
460  $boxesall[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
461  } else {
462  $boxesall[$g]['formatted'] = imap_utf7_decode_local($mailbox);
463  }
464 
465  $boxesall[$g]['unformatted-dm'] = $mailbox;
466  if (substr($mailbox, -1) == $delimiter) {
467  $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
468  }
469  $boxesall[$g]['unformatted'] = $mailbox;
470  if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix) {
471  $mailbox = substr($mailbox, strlen($folder_prefix));
472  }
473  $boxesall[$g]['unformatted-disp'] = $mailbox;
474  $boxesall[$g]['id'] = $g;
475 
476  $boxesall[$g]['flags'] = array();
477  if (isset($line[$g])) {
478  if ( preg_match('/\(([^)]*)\)/',$line[$g],$regs) ) {
479  $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
480  if ($flags) {
481  $boxesall[$g]['flags'] = explode(' ', $flags);
482  }
483  }
484  }
485  }
486  return $boxesall;
487 }
488 
501 function user_strcasecmp($a, $b) {
502  return strnatcasecmp($a, $b);
503 }
504 
521 function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0,
522  $flag = 'noselect', $use_long_format = false ) {
523  global $username, $data_dir;
524  $mbox_options = '';
525  if ( $use_long_format ) {
526  $shorten_box_names = 0;
527  } else {
528  $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', 1);
529  }
530 
531  if ($boxes == 0) {
533  }
534 
535  foreach ($boxes as $boxes_part) {
536  if ($flag == NULL || !in_array($flag, $boxes_part['flags'])) {
537  $box = $boxes_part['unformatted'];
538 
539  if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
540  continue;
541  }
542  $lowerbox = strtolower($box);
543  // mailboxes are casesensitive => inbox.sent != inbox.Sent
544  // nevermind, to many dependencies this should be fixed!
545 
546  if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
547  $box2 = _("INBOX");
548  } else {
549  switch ($shorten_box_names)
550  {
551  case 2: /* delimited, style = 2 */
552  $box2 = str_replace('&nbsp;&nbsp;', '.&nbsp;', $boxes_part['formatted']);
553  break;
554  case 1: /* indent, style = 1 */
555  $box2 = $boxes_part['formatted'];
556  break;
557  default: /* default, long names, style = 0 */
558  $box2 = str_replace(' ', '&nbsp;', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
559  break;
560  }
561  }
562  $box2 = str_replace(array('<','>'), array('&lt;','&gt;') , $box2);
563 
564  if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
565  $mbox_options .= '<option value="' . htmlspecialchars($box) .'" selected="selected">'.$box2.'</option>' . "\n";
566  } else {
567  $mbox_options .= '<option value="' . htmlspecialchars($box) .'">'.$box2.'</option>' . "\n";
568  }
569  }
570  }
571  return $mbox_options;
572 }
573 
577 function mailtree_sort(&$lsub) {
578  if(!is_array($lsub)) return;
579 
580  global $delimiter;
581 
582  foreach($lsub as $index => $mailbox)
583  $lsub[$index] = str_replace($delimiter,' -#- ',$lsub[$index]);
584 
585  usort($lsub, 'user_strcasecmp');
586 
587  foreach($lsub as $index => $mailbox)
588  $lsub[$index] = str_replace(' -#- ',$delimiter,$lsub[$index]);
589 }
590 
597 function sqimap_mailbox_list($imap_stream, $force=false) {
599 
600  if (!sqgetGlobalVar('boxesnew',$boxesnew,SQ_SESSION) || $force) {
603  $move_to_trash, $move_to_sent, $save_as_draft,
604  $delimiter, $noselect_fix_enable;
605  $inbox_in_list = false;
606  $inbox_subscribed = false;
607 
608  require_once(SM_PATH . 'include/load_prefs.php');
609 
610  if ($noselect_fix_enable) {
611  $lsub_args = "LSUB \"$folder_prefix\" \"*%\"";
612  } else {
613  $lsub_args = "LSUB \"$folder_prefix\" \"*\"";
614  }
615  /* LSUB array */
616  $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
617  true, $response, $message);
618 
619  $sorted_lsub_ary = array();
620  for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
621  /*
622  * Workaround for mailboxes returned as literal
623  * Doesn't work if the mailbox name is multiple lines
624  * (larger then fgets buffer)
625  */
626  if (isset($lsub_ary[$i + 1]) && substr($lsub_ary[$i],-3) == "}\r\n") {
627  if (preg_match('/^(\* [A-Z]+.*)\{[0-9]+\}([ \n\r\t]*)$/',
628  $lsub_ary[$i], $regs)) {
629  $i++;
630  $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
631  }
632  }
633  $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
634  $sorted_lsub_ary[] = $temp_mailbox_name;
635  if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
636  $inbox_subscribed = true;
637  }
638  }
639  /* remove duplicates */
640  $sorted_lsub_ary = array_unique($sorted_lsub_ary);
641 
642  /* natural sort mailboxes */
643  if (isset($sorted_lsub_ary)) {
644  mailtree_sort($sorted_lsub_ary);
645  }
646  /*
647  * The LSUB response doesn't provide us information about \Noselect
648  * mail boxes. The LIST response does, that's why we need to do a LIST
649  * call to retrieve the flags for the mailbox
650  * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
651  * in other words, we cannot rely on it.
652  */
653  $sorted_list_ary = array();
654  for ($i=0; $i < count($sorted_lsub_ary); $i++) {
655  if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
656  $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
657  }
658  else {
659  $mbx = $sorted_lsub_ary[$i];
660  }
661 
662  $read = sqimap_run_command ($imap_stream, "LIST \"\" \"$mbx\"",
663  true, $response, $message);
664 
665  /* Another workaround for literals */
666 
667  if (isset($read[1]) && substr($read[1],-3) == "}\r\n") {
668  if (preg_match('/^(\* [A-Z]+.*)\{[0-9]+\}([ \n\r\t]*)$/',
669  $read[0], $regs)) {
670  $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
671  }
672  }
673 
674  if (isset($read[0])) {
675  $sorted_list_ary[$i] = $read[0];
676  } else {
677  $sorted_list_ary[$i] = '';
678  }
679  }
680 
681  /*
682  * Just in case they're not subscribed to their inbox,
683  * we'll get it for them anyway
684  */
685  if (!$inbox_subscribed) {
686  $inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
687  true, $response, $message);
688  /* Another workaround for literals */
689  if (isset($inbox_ary[1]) && substr($inbox_ary[0],-3) == "}\r\n") {
690  if (preg_match('/^(\* [A-Z]+.*)\{[0-9]+\}([ \n\r\t]*)$/',
691  $inbox_ary[0], $regs)) {
692  $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
693  '"' . $regs[2];
694  }
695  }
696  $sorted_list_ary[] = $inbox_ary[0];
697  $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
698  }
699 
700  $boxesall = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary);
701 
702  /* Now, lets sort for special folders */
703  $boxesnew = $used = array();
704 
705  /* Find INBOX */
706  $cnt = count($boxesall);
707  $used = array_pad($used,$cnt,false);
708  for($k = 0; $k < $cnt; ++$k) {
709  if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
710  $boxesnew[] = $boxesall[$k];
711  $used[$k] = true;
712  break;
713  }
714  }
715 
716  /*
717  * For systems where folders might be either under the INBOX or
718  * at the top-level (Dovecot, hMailServer), INBOX subfolders have
719  * to be added before special folders
720  */
721  if (!$default_sub_of_inbox) {
722  for($k = 0; $k < $cnt; ++$k) {
723  if (!$used[$k] && isBoxBelow(strtolower($boxesall[$k]['unformatted']), 'inbox') &&
724  strtolower($boxesall[$k]['unformatted']) != 'inbox') {
725  $boxesnew[] = $boxesall[$k];
726  $used[$k] = true;
727  }
728  }
729  }
730 
731 
732  /* List special folders and their subfolders, if requested. */
734  for($k = 0; $k < $cnt; ++$k) {
735  if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
736  $boxesnew[] = $boxesall[$k];
737  $used[$k] = true;
738  }
739  }
740  }
741 
742 
743  /* Find INBOX's children for systems where folders are ONLY under INBOX */
744  if ($default_sub_of_inbox) {
745  for($k = 0; $k < $cnt; ++$k) {
746  if (!$used[$k] && isBoxBelow(strtolower($boxesall[$k]['unformatted']), 'inbox') &&
747  strtolower($boxesall[$k]['unformatted']) != 'inbox') {
748  $boxesnew[] = $boxesall[$k];
749  $used[$k] = true;
750  }
751  }
752  }
753 
754 
755  /* Rest of the folders */
756  for($k = 0; $k < $cnt; $k++) {
757  if (!$used[$k]) {
758  $boxesnew[] = $boxesall[$k];
759  }
760  }
761  sqsession_register($boxesnew,'boxesnew');
762  }
763  return $boxesnew;
764 }
765 
770  global $list_special_folders_first, $folder_prefix, $delimiter;
771 
772  $ssid = sqimap_session_id();
773  $lsid = strlen( $ssid );
774  fputs ($imap_stream, $ssid . " LIST \"$folder_prefix\" *\r\n");
775  $read_ary = sqimap_read_data ($imap_stream, $ssid, true, $response, $message);
776  $g = 0;
777  $phase = 'inbox';
778  $fld_pre_length = strlen($folder_prefix);
779 
780  for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
781  /* Another workaround for EIMS */
782  if (isset($read_ary[$i + 1]) &&
783  preg_match('/^(\* [A-Z]+.*)\{[0-9]+\}([ \n\r\t]*)$/',
784  $read_ary[$i], $regs)) {
785  $i ++;
786  $read_ary[$i] = $regs[1] . '"' . addslashes(trim($read_ary[$i])) . '"' . $regs[2];
787  }
788  if (substr($read_ary[$i], 0, $lsid) != $ssid ) {
789  /* Store the raw IMAP reply */
790  $boxes[$g]['raw'] = $read_ary[$i];
791 
792  /* Count number of delimiters ($delimiter) in folder name */
793  $mailbox = find_mailbox_name($read_ary[$i]);
794  $dm_count = substr_count($mailbox, $delimiter);
795  if (substr($mailbox, -1) == $delimiter) {
796  /* If name ends in delimiter - decrement count by one */
797  $dm_count--;
798  }
799 
800  /* Format folder name, but only if it's a INBOX.* or has a parent. */
801  $boxesallbyname[$mailbox] = $g;
802  $parentfolder = readMailboxParent($mailbox, $delimiter);
803  /* @FIXME shouldn't use preg_match for simple string matching */
804  if((preg_match('|^inbox'.quotemeta($delimiter).'|i', $mailbox)) ||
805  (preg_match('|^'.$folder_prefix.'|', $mailbox)) ||
806  ( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
807  if ($dm_count) {
808  $boxes[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $dm_count);
809  } else {
810  $boxes[$g]['formatted'] = '';
811  }
812  $boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
813  } else {
814  $boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
815  }
816 
817  $boxes[$g]['unformatted-dm'] = $mailbox;
818  if (substr($mailbox, -1) == $delimiter) {
819  $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
820  }
821  $boxes[$g]['unformatted'] = $mailbox;
822  $boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
823 
824  $boxes[$g]['id'] = $g;
825 
826  /* Now lets get the flags for this mailbox */
827  $read_mlbx = $read_ary[$i];
828 
829 // $read_mlbx = sqimap_run_command ($imap_stream, "LIST \"\" \"$mailbox\"",
830 // true, $response, $message);
831 
832  /* Another workaround for EIMS */
833 // if (isset($read_mlbx[1]) &&
834 // preg_match('/^(\* [A-Z]+.*)\{[0-9]+\}([ \n\r\t]*)$/', $read_mlbx[0], $regs)) {
835 // $read_mlbx[0] = $regs[1] . '"' . addslashes(trim($read_mlbx[1])) . '"' . $regs[2];
836 // }
837 // echo $read_mlbx[0] .' raw 2 <br>';
838 
839  $flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
840  $flags = substr($flags, 0, strpos($flags, ')'));
841  $flags = str_replace('\\', '', $flags);
842  $flags = trim(strtolower($flags));
843  if ($flags) {
844  $boxes[$g]['flags'] = explode(' ', $flags);
845  } else {
846  $boxes[$g]['flags'] = array();
847  }
848  }
849  $g++;
850  }
851  if(is_array($boxes)) {
852  sort ($boxes);
853  }
854 
855  return $boxes;
856 }
857 
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$ret
$ret
Definition: webmail.php:172
$new_name
$new_name
Definition: folders_rename_do.php:46
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
sqimap_mailbox_expunge
sqimap_mailbox_expunge($imap_stream, $mailbox, $handle_errors=true, $id='')
Definition: imap_mailbox.php:198
$cnt
$cnt
Definition: options_identities.php:86
sqimap_session_id
sqimap_session_id($unique_id=FALSE)
Definition: imap_general.php:26
$draft_folder
$draft_folder
Definition: config_default.php:396
isSpecialMailbox
isSpecialMailbox($box, $include_subs=true)
Definition: imap_mailbox.php:118
isBoxBelow
isBoxBelow( $subbox, $parentbox)
Definition: imap_mailbox.php:77
$data_dir
$data_dir
Definition: config_default.php:499
sortSpecialMbx
sortSpecialMbx($a, $b)
Definition: imap_mailbox.php:20
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$imap_stream
$imap_stream
Definition: bug_report.php:119
$imap_server_type
$imap_server_type
Definition: config_default.php:231
$id
$id
Definition: move_messages.php:190
sqimap_mailbox_exists
sqimap_mailbox_exists($imap_stream, $mailbox)
Definition: imap_mailbox.php:226
$mailbox
$mailbox
Definition: options.php:28
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
$trash_folder
$trash_folder
Definition: config_default.php:394
$show_selected
$show_selected
Definition: folders.php:111
$username
global $username
Definition: validate.php:55
sqimap_mailbox_create
sqimap_mailbox_create($imap_stream, $mailbox, $type)
Definition: imap_mailbox.php:296
user_strcasecmp
user_strcasecmp($a, $b)
Definition: imap_mailbox.php:501
$used
$used
Definition: darkness.php:81
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$uid_support
$uid_support
Definition: config_default.php:643
$boxes
$boxes
Definition: empty_trash.php:49
$message
$message
Definition: download.php:54
sqimap_mailbox_rename
sqimap_mailbox_rename( $imap_stream, $old_name, $new_name)
Definition: imap_mailbox.php:361
mailtree_sort
mailtree_sort(&$lsub)
Definition: imap_mailbox.php:577
$g
$g
Definition: darkness.php:104
sqimap_mailbox_delete
sqimap_mailbox_delete($imap_stream, $mailbox)
Definition: imap_mailbox.php:328
isDraftMailbox
isDraftMailbox($box, $include_subs=true)
Definition: imap_mailbox.php:188
$sent_folder
$sent_folder
Definition: config_default.php:395
$noselect_fix_enable
$noselect_fix_enable
Definition: config_default.php:474
isSentMailbox
isSentMailbox($box, $include_subs=true)
Definition: imap_mailbox.php:173
find_mailbox_name
find_mailbox_name($mailbox)
Definition: imap_mailbox.php:39
$list_special_folders_first
$list_special_folders_first
Definition: config_default.php:424
do_hook_function
do_hook_function($name, $parm=NULL)
Definition: plugin.php:69
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
readMailboxParent
readMailboxParent($haystack, $needle)
Definition: imap_mailbox.php:60
$save_as_draft
$save_as_draft
Definition: load_prefs.php:86
removePref
removePref($data_dir, $username, $string)
Definition: db_prefs.php:331
$folder_prefix
$folder_prefix
Definition: load_prefs.php:103
$r
while(count($Left) > 0) $r
Definition: darkness.php:103
sqimap_mailbox_option_list
sqimap_mailbox_option_list($imap_stream, $show_selected=0, $folder_skip=0, $boxes=0, $flag='noselect', $use_long_format=false)
Definition: imap_mailbox.php:521
readShortMailboxName
readShortMailboxName($haystack, $needle)
Definition: strings.php:240
sqimap_read_data
sqimap_read_data($imap_stream, $tag_uid, $handle_errors, &$response, &$message, $query='', $filter=false, $outputstream=false, $no_return=false)
Definition: imap_general.php:454
sqimap_unsubscribe
sqimap_unsubscribe($imap_stream, $mailbox)
Definition: imap_mailbox.php:320
sqimap_mailbox_parse
sqimap_mailbox_parse($line, $line_lsub)
Definition: imap_mailbox.php:427
$data
$data
Definition: mailto.php:83
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
sqimap_subscribe
sqimap_subscribe($imap_stream, $mailbox)
Definition: imap_mailbox.php:312
imap_utf7_decode_local
imap_utf7_decode_local($s)
Definition: imap_utf7_local.php:88
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
$read
$read
Definition: message_details_bottom.php:75
sqimap_message_list_squisher
sqimap_message_list_squisher($messages_array)
Definition: imap_messages.php:91
sqimap_mailbox_is_subscribed
sqimap_mailbox_is_subscribed($imap_stream, $folder)
Definition: imap_mailbox.php:348
sqimap_run_command
sqimap_run_command($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id=false, $filter=false, $outputstream=false, $no_return=false)
Definition: imap_general.php:58
$boxesnew
global $boxesnew
Definition: imap_mailbox.php:16
$color
$color
Definition: load_prefs.php:28
$old_name
$old_name
Definition: folders_rename_do.php:59
isInboxMailbox
isInboxMailbox($box, $include_subs=TRUE)
Definition: imap_mailbox.php:144
NULL
if(!defined('PAGE_NAME')) define('PAGE_NAME' NULL
Definition: validate.php:16
$default_sub_of_inbox
$default_sub_of_inbox
Definition: config_default.php:433
$move_to_trash
$move_to_trash
Definition: load_prefs.php:84
boolean_hook_function
boolean_hook_function($name, $parm=NULL, $priority=0, $tie=false)
Definition: plugin.php:128
sqimap_mailbox_list_all
sqimap_mailbox_list_all($imap_stream)
Definition: imap_mailbox.php:769
$default_folder_prefix
$default_folder_prefix
Definition: config_default.php:342
sqimap_mailbox_list
sqimap_mailbox_list($imap_stream, $force=false)
Definition: imap_mailbox.php:597
isTrashMailbox
isTrashMailbox($box, $include_subs=true)
Definition: imap_mailbox.php:158
check_is_noselect
check_is_noselect($lsub_line)
Definition: imap_mailbox.php:51
$auto_expunge
$auto_expunge
Definition: config_default.php:397
error_box
error_box($string, $color)
Definition: display_messages.php:116