<?php
+
/**
* 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;
}
return $cnt;
}
-
-/**
- * Expunge specified message, updated $msgs and $msort
- *
- * Until Marc and I come up with a better way to maintain
- * these stupid arrays, we'll use this wrapper function to
- * remove the message with the matching UID .. the order
- * won't be changed - the array element for the message
- * will just be removed.
- */
-function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array)
-{
- global $msgs, $msort, $sort, $imapConnection,
- $mailbox, $auto_expunge,
- $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
- $username, $data_dir;
- $cnt = 0;
-
- if (!isset($sort) || $sort === false) {
- sqgetGlobalVar('sort',$sort,SQ_GET);
- }
-
- if ($auto_expunge) {
- $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
- } else {
- return $cnt;
- }
-
- // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
- if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
- $mode = 'thread';
- } else if ($allow_server_sort) {
- $mode = 'server_sort';
- } else {
- $mode = '';
- }
- $error = '';
- if (is_array($server_sort_array)) {
- $key = array_search($message_id,$server_sort_array,true);
- if ($key !== false) {
- unset($server_sort_array[$key]);
- $server_sort_array = array_values($server_sort_array);
- } else {
- $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
- }
- } else {
- $server_sort_array = get_sorted_msgs_list($imapConnection,$sort,$mode,$error);
- }
- sqsession_register($server_sort_array,'server_sort_array');
- return $cnt;
-}
-
/**
* Checks whether or not the specified mailbox exists
*/
$boxesall = sqimap_mailbox_list($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);
/**
* Returns list of options (to be echoed into select statement
* based on available mailboxes and separators
- * Caller should surround options with <SELECT..> </SELECT> and
+ * Caller should surround options with <select ...> </select> and
* any formatting.
* $imap_stream - $imapConnection to query for mailboxes
* $show_selected - array containing list of mailboxes to pre-select (0 if none)
}
foreach ($boxes as $boxes_part) {
- if ($flag == NULL || !in_array($flag, $boxes_part['flags'])) {
+ if ($flag == NULL || (is_array($boxes_part['flags'])
+ && !in_array($flag, $boxes_part['flags']))) {
$box = $boxes_part['unformatted'];
if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
switch ($shorten_box_names)
{
case 2: /* delimited, style = 2 */
- $box2 = str_replace(' ', '. ', $boxes_part['formatted']);
+ $box2 = str_replace('&nbsp;&nbsp;', '. ', htmlspecialchars($boxes_part['formatted']));
break;
case 1: /* indent, style = 1 */
- $box2 = $boxes_part['formatted'];
+ $box2 = str_replace('&nbsp;&nbsp;', ' ', htmlspecialchars($boxes_part['formatted']));
break;
default: /* default, long names, style = 0 */
$box2 = str_replace(' ', ' ', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
}
}
if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
- $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'" SELECTED>'.$box2.'</OPTION>' . "\n";
+ $mbox_options .= '<option value="' . htmlspecialchars($box) .'" selected="selected">'.$box2.'</option>' . "\n";
} else {
- $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'">'.$box2.'</OPTION>' . "\n";
+ $mbox_options .= '<option value="' . htmlspecialchars($box) .'">'.$box2.'</option>' . "\n";
}
}
}
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 $boxesnew, $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);
- $boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
- return $boxesnew;
+ 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);