/**
* imap_mailbox.php
*
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This impliments all functions that manipulate mailboxes
$id = sqimap_message_list_squisher($id);
}
$id = ' '.$id;
- $uid = TRUE;
+ $uid = TRUE;
} else {
$uid = false;
}
} else {
do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
removePref($data_dir, $username, "thread_$mailbox");
+ removePref($data_dir, $username, "collapse_folder_$mailbox");
}
}
$postfix = '';
}
- $boxesall = sqimap_mailbox_list($imap_stream);
+ $boxesall = sqimap_mailbox_list_all($imap_stream);
$cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) .
- ' ' . sqimap_encode_mailbox_name($new_name);
+ ' ' . sqimap_encode_mailbox_name($new_name);
$data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
sqimap_unsubscribe($imap_stream, $old_name.$postfix);
- $oldpref = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
+ $oldpref_thread = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
+ $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
+ removePref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
sqimap_subscribe($imap_stream, $new_name.$postfix);
- setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref);
+ setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref_thread);
+ setPref($data_dir, $username, 'collapse_folder_'.$new_name.$postfix, $oldpref_collapse);
do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
$l = strlen( $old_name ) + 1;
$p = 'unformatted';
foreach ($boxesall as $box) {
if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
$new_sub = $new_name . $delimiter . substr($box[$p], $l);
+ /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */
if ($imap_server_type == 'cyrus') {
$cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
- $data = sqimap_run_command($imap_stream, $cmd, true,
+ $data = sqimap_run_command($imap_stream, $cmd, false,
$response, $message);
}
- sqimap_unsubscribe($imap_stream, $box[$p]);
- $oldpref = getPref($data_dir, $username, 'thread_'.$box[$p]);
+ $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]);
+ if ( $was_subscribed ) {
+ sqimap_unsubscribe($imap_stream, $box[$p]);
+ }
+ $oldpref_thread = getPref($data_dir, $username, 'thread_'.$box[$p]);
+ $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$box[$p]);
removePref($data_dir, $username, 'thread_'.$box[$p]);
- sqimap_subscribe($imap_stream, $new_sub);
- setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref);
+ removePref($data_dir, $username, 'collapse_folder_'.$box[$p]);
+ if ( $was_subscribed ) {
+ sqimap_subscribe($imap_stream, $new_sub);
+ }
+ setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref_thread);
+ setPref($data_dir, $username, 'collapse_folder_'.$new_sub, $oldpref_collapse);
do_hook_function('rename_or_delete_folder',
$args = array($box[$p], 'rename', $new_sub));
}
switch ($shorten_box_names)
{
case 2: /* delimited, style = 2 */
- $box2 = str_replace(' ', '. ', $boxes_part['formatted']);
+ $box2 = str_replace('  ', '. ', htmlspecialchars($boxes_part['formatted']));
break;
case 1: /* indent, style = 1 */
- $box2 = $boxes_part['formatted'];
+ $box2 = str_replace('  ', ' ', htmlspecialchars($boxes_part['formatted']));
break;
default: /* default, long names, style = 0 */
$box2 = str_replace(' ', ' ', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
/**
* Returns sorted mailbox lists in several different ways.
* See comment on sqimap_mailbox_parse() for info about the returned array.
+ * @param resource $imap_stream imap connection resource
+ * @param boolean $force force update of mailbox listing. available since 1.4.2 and 1.5.0
+ * @return array list of mailboxes
*/
-
-
function sqimap_mailbox_list($imap_stream, $force=false) {
- global $default_folder_prefix;
-
if (!sqgetGlobalVar('boxesnew',$boxesnew,SQ_SESSION) || $force) {
global $data_dir, $username, $list_special_folders_first,
$folder_prefix, $trash_folder, $sent_folder, $draft_folder,
$move_to_trash, $move_to_sent, $save_as_draft,
- $delimiter, $noselect_fix_enable, $imap_server_type;
- $inbox_in_list = false;
+ $delimiter, $noselect_fix_enable, $imap_server_type,
+ $show_only_subscribed_folders;
$inbox_subscribed = false;
$listsubscribed = sqimap_capability($imap_stream,'LIST-SUBSCRIBED');
require_once(SM_PATH . 'include/load_prefs.php');
-
- if ($listsubscribed) {
+ if (!$show_only_subscribed_folders) {
+ $lsub = 'LIST';
+ } elseif ($listsubscribed) {
$lsub = 'LIST (SUBSCRIBED)';
} else {
$lsub = 'LSUB';
}
if ($noselect_fix_enable) {
-
$lsub_args = "$lsub \"$folder_prefix\" \"*%\"";
} else {
$lsub_args = "$lsub \"$folder_prefix\" \"*\"";
$read_ary = compact_mailboxes_response($read_ary);
$g = 0;
- $phase = 'inbox';
$fld_pre_length = strlen($folder_prefix);
for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
/* Store the raw IMAP reply */
}
function sqimap_mailbox_tree($imap_stream) {
- global $default_folder_prefix, $unseen_notify, $unseen_type;
+ global $default_folder_prefix;
if (true) {
-
global $data_dir, $username, $list_special_folders_first,
$folder_prefix, $delimiter, $trash_folder, $move_to_trash,
- $imap_server_type;
-
+ $imap_server_type, $show_only_subscribed_folders;
- $inbox_in_list = false;
- $inbox_subscribed = false;
$noselect = false;
$noinferiors = false;
require_once(SM_PATH . 'include/load_prefs.php');
+ if ($show_only_subscribed_folders) {
+ $lsub_cmd = 'LSUB';
+ } else {
+ $lsub_cmd = 'LIST';
+ }
+
/* LSUB array */
- $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
+ $lsub_ary = sqimap_run_command ($imap_stream, "$lsub_cmd \"$folder_prefix\" \"*\"",
true, $response, $message);
$lsub_ary = compact_mailboxes_response($lsub_ary);
$has_inbox = false;
for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
- if (preg_match("/^\*\s+LSUB.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
- $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
+ if (preg_match("/^\*\s+$lsub_cmd.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
+ $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
// in case of an unsubscribed inbox an imap server can
// return the inbox in the lsub results with a \NoSelect
// flag.
- if (!preg_match("/\*\s+LSUB\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
+ if (!preg_match("/\*\s+$lsub_cmd\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
$has_inbox = true;
} else {
// remove the result and request it again with a list
if ($has_inbox == false) {
// do a list request for inbox because we should always show
// inbox even if the user isn't subscribed to it.
- $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
+ $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" "INBOX"',
true, $response, $message);
$inbox_ary = compact_mailboxes_response($inbox_ary);
if (count($inbox_ary)) {
$cnt = count($sorted_lsub_ary);
}
$sorted_lsub_ary = array_values($sorted_lsub_ary);
- array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
+ usort($sorted_lsub_ary, 'mbxSort');
$boxestree = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
return $boxestree;
}
}
+function mbxSort($a, $b) {
+ return strnatcasecmp($a['mbx'], $b['mbx']);
+}
+
function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
global $data_dir, $username, $list_special_folders_first,
$folder_prefix, $trash_folder, $sent_folder, $draft_folder,
$move_to_trash, $move_to_sent, $save_as_draft,
$delimiter, $imap_server_type;
- $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
+ // $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
/* create virtual root node */
$mailboxes= new mailboxes();
if (isset($folder_prefix) && ($folder_prefix != '')) {
$start = substr_count($folder_prefix,$delimiter);
if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
- $trail_del = true;
$mailboxes->mailboxname_full = substr($folder_prefix,0, (strlen($folder_prefix)-1));
} else {
$mailboxes->mailboxname_full = $folder_prefix;
$start = 0;
}
- $cnt = count($mbx_ary);
+ $cnt = count($mbx_ary);
for ($i=0; $i < $cnt; $i++) {
if ($mbx_ary[$i]['mbx'] !='' ) {
$mbx = new mailboxes();
function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
- $aMbxs = $aQuery = $aTag = array();
+ $aMbxs = $aQuery = array();
sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
// remove the root node
array_shift($aMbxs);
}
}
-?>
\ No newline at end of file
+?>