From fe6efa94e2459e20055b081ad7af82bdc04d260c Mon Sep 17 00:00:00 2001 From: stekkel Date: Mon, 17 May 2004 19:48:57 +0000 Subject: [PATCH] temp fixes, as long as we didn't adapt our mailbox tree code, cache the list. Make use of the sorted list with id's from the session if the mailbox state didn't change. All performance related imap fixes were found after playing with thetereal. If you want to try itt yourself: tethereal -t a -ni lo -f 'port 143' -R 'imap.request' with lo the interface. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7476 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 71 +++++++++++++++++++++++++++-------- functions/mailbox_display.php | 6 ++- src/right_main.php | 26 ++++++++++++- 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 6d0b3404..db1ad69c 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -294,13 +294,22 @@ function sqimap_mailbox_expunge_dmn($message_id) // 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; } @@ -608,15 +617,16 @@ function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_sk * 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; @@ -630,20 +640,33 @@ function sqimap_mailbox_list($imap_stream) { /* 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 @@ -651,7 +674,7 @@ function sqimap_mailbox_list($imap_stream) { * 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) { @@ -660,10 +683,19 @@ function sqimap_mailbox_list($imap_stream) { 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 { @@ -675,9 +707,17 @@ function sqimap_mailbox_list($imap_stream) { * 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]); } @@ -705,15 +745,14 @@ function sqimap_mailbox_list($imap_stream) { } } } - - /* 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; } diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index a48daf4c..9eee2887 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -460,7 +460,11 @@ function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) { */ function getServerSortMessages($imapConnection, $start_msg, $show_num, $num_msgs, $server_sort_order, $mbxresponse) { - $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); + if (isset($mbxresponse['SORT_ARRAY']) && $mbxresponse['SORT_ARRAY']) { + $id = $mbxresponse['SORT_ARRAY']; + } else { + $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); + } return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); } diff --git a/src/right_main.php b/src/right_main.php index 53840768..b07aec7a 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -152,6 +152,27 @@ else { 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). @@ -219,7 +240,7 @@ if ($use_mailbox_cache && sqsession_is_registered('msgs')) { unset($numMessages); } - $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox); + $numMessages = $aMbxResponse['EXISTS']; showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, @@ -237,7 +258,8 @@ if ($use_mailbox_cache && sqsession_is_registered('msgs')) { } do_hook('right_main_bottom'); sqimap_logout ($imapConnection); - echo ''; +sqsession_register($aLastSelectedMailbox,'aLastSelectedMailbox'); + ?> -- 2.25.1