// And after all that mucking around, update the sort list!
// Remind me why the hell we need those two arrays again?!
+
+ sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+
+
if ( $allow_thread_sort && $thread_sort_messages ) {
$server_sort_array = get_thread_sort($imapConnection);
} elseif ( $allow_server_sort ) {
- $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response);
- } else {
+ $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 = sqimap_get_php_sort_order($imapConnection, $mbx_response);
}
+ sqsession_register('server_sort_array',$server_sort_array);
return $cnt;
}
* Returns sorted mailbox lists in several different ways.
* See comment on sqimap_mailbox_parse() for info about the returned array.
*/
-function sqimap_mailbox_list($imap_stream) {
+
+
+function sqimap_mailbox_list($imap_stream, $force=false) {
global $default_folder_prefix;
- if (!isset($boxesnew)) {
+ 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;
-
$inbox_in_list = false;
$inbox_subscribed = false;
/* LSUB array */
$lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
true, $response, $message);
- $lsub_ary = compact_mailboxes_response($lsub_ary);
$sorted_lsub_ary = array();
for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
+ /*
+ * Workaround for mailboxes returned as literal
+ * Doesn't work if the mailbox name is multiple lines
+ * (larger then fgets buffer)
+ */
+ if (isset($lsub_ary[$i + 1]) && substr($lsub_ary[$i],-3) == "}\r\n") {
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ $lsub_ary[$i], $regs)) {
+ $i++;
+ $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
+ }
+ }
$temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
$sorted_lsub_ary[] = $temp_mailbox_name;
if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
$inbox_subscribed = true;
}
}
+ /* remove duplicates */
+ $sorted_lsub_ary = array_unique($sorted_lsub_ary);
/* natural sort mailboxes */
if (isset($sorted_lsub_ary)) {
- usort($sorted_lsub_ary, 'strnatcasecmp');
+ usort($sorted_lsub_ary, 'user_strcasecmp');
}
/*
* The LSUB response doesn't provide us information about \Noselect
* call to retrieve the flags for the mailbox
* Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
* in other words, we cannot rely on it.
- */
+ */
$sorted_list_ary = array();
for ($i=0; $i < count($sorted_lsub_ary); $i++) {
if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
else {
$mbx = $sorted_lsub_ary[$i];
}
- $mbx = stripslashes($mbx);
- $read = sqimap_run_command ($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx),
+
+ $read = sqimap_run_command ($imap_stream, "LIST \"\" \"$mbx\"",
true, $response, $message);
- $read = compact_mailboxes_response($read);
+
+ /* Another workaround for literals */
+
+ if (isset($read[1]) && substr($read[1],-3) == "}\r\n") {
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ $read[0], $regs)) {
+ $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
+ }
+ }
+
if (isset($read[0])) {
$sorted_list_ary[$i] = $read[0];
} else {
* we'll get it for them anyway
*/
if (!$inbox_subscribed) {
- $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
+ $inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
true, $response, $message);
- $sorted_list_ary[] = implode('', compact_mailboxes_response($inbox_ary));
+ /* Another workaround for literals */
+ if (isset($inbox_ary[1]) && substr($inbox_ary[0],-3) == "}\r\n") {
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ $inbox_ary[0], $regs)) {
+ $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
+ '"' . $regs[2];
+ }
+ }
+ $sorted_list_ary[] = $inbox_ary[0];
$sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
}
}
}
}
-
- /* Rest of the folders */
+ /* Rest of the folders */
for($k = 0; $k < $cnt; $k++) {
if (!$used[$k]) {
$boxesnew[] = $boxesall[$k];
}
}
+ sqsession_register($boxesnew,'boxesnew');
}
-
return $boxesnew;
}
do_hook ('generic_header');
$aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
+$aMbxResponse['SORT_ARRAY'] = false;
+
+sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
+
+if ($aLastSelectedMailbox && !isset($newsort)) {
+ // check if we deal with the same mailbox
+ if ($aLastSelectedMailbox['NAME'] == $mailbox) {
+ if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
+ $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
+ $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
+ // sort is still valid
+ sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+ $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
+ }
+ }
+}
+
+$aLastSelectedMailbox['NAME'] = $mailbox;
+$aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
+$aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
+$aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
if ($composenew) {
$comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
unset($numMessages);
}
- $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
+ $numMessages = $aMbxResponse['EXISTS'];
showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
$startMessage, $sort, $color, $show_num,
}
do_hook('right_main_bottom');
sqimap_logout ($imapConnection);
-
echo '</body></html>';
+sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox');
+
?>