From 26e90c74aeb5d8728f4fa08bea938064730f41bf Mon Sep 17 00:00:00 2001 From: stekkel Date: Wed, 19 May 2004 22:36:41 +0000 Subject: [PATCH] * Request UID and UIDVALIDITY from the status response if not available in the select response. * Tried to fix the broken del move next function and added a few arguments to the dmn_expunge function because the globals scared me when I couldn't get the job done. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7496 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_general.php | 39 +++++++++++++++++++++-------------- functions/imap_mailbox.php | 33 ++++++++++++++++++----------- functions/mailbox_display.php | 2 +- src/read_body.php | 5 ++--- src/right_main.php | 32 +++++++++++++++++++--------- 5 files changed, 70 insertions(+), 41 deletions(-) diff --git a/functions/imap_general.php b/functions/imap_general.php index 73f6d619..05880e12 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -1039,27 +1039,26 @@ function parseAddress($address, $max=0) { /** * Returns the number of unseen messages in this folder. + * obsoleted by sqimap_status_messages ! */ function sqimap_unseen_messages ($imap_stream, $mailbox) { - $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (UNSEEN)', false, $result, $message); - $i = 0; - $regs = array(false, false); - while (isset($read_ary[$i])) { - if (ereg("UNSEEN ([0-9]+)", $read_ary[$i], $regs)) { - break; - } - $i++; - } - return $regs[1]; + $aStatus = sqimap_status_messages($imap_stream,$mailbox,array('UNSEEN')); + return $aStatus['UNSEEN']; } /** - * Returns the number of total/unseen/recent messages in this folder + * Returns the status items of a mailbox. + * Default it returns MESSAGES,UNSEEN and RECENT + * Supported status items are MESSAGES, UNSEEN, RECENT, UIDNEXT and UIDVALIDITY */ -function sqimap_status_messages ($imap_stream, $mailbox) { - $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (MESSAGES UNSEEN RECENT)', false, $result, $message); +function sqimap_status_messages ($imap_stream, $mailbox, + $aStatusItems = array('MESSAGES','UNSEEN','RECENT')) { + + $aStatusItems = implode(' ',$aStutusItems); + $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . + " ($aStatusItems)", false, $result, $message); $i = 0; - $messages = $unseen = $recent = false; + $messages = $unseen = $recent = $uidnext = $uidvalidity = false; $regs = array(false,false); while (isset($read_ary[$i])) { if (preg_match('/UNSEEN\s+([0-9]+)/i', $read_ary[$i], $regs)) { @@ -1071,9 +1070,19 @@ function sqimap_status_messages ($imap_stream, $mailbox) { if (preg_match('/RECENT\s+([0-9]+)/i', $read_ary[$i], $regs)) { $recent = $regs[1]; } + if (preg_match('/UIDNEXT\s+([0-9]+)/i', $read_ary[$i], $regs)) { + $uidnext = $regs[1]; + } + if (preg_match('/UIDVALIDITY\s+([0-9]+)/i', $read_ary[$i], $regs)) { + $uidvalidity = $regs[1]; + } $i++; } - return array('MESSAGES' => $messages, 'UNSEEN'=>$unseen, 'RECENT' => $recent); + return array('MESSAGES' => $messages, + 'UNSEEN'=>$unseen, + 'RECENT' => $recent, + 'UIDNEXT' => $uidnext, + 'UIDVALIDITY' => $uidvalidity); } diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index a3b41957..51149e30 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -257,14 +257,17 @@ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, * won't be changed - the array element for the message * will just be removed. */ -function sqimap_mailbox_expunge_dmn($message_id) +function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array) { global $msgs, $msort, $sort, $imapConnection, - $mailbox, $mbx_response, $auto_expunge, + $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); + } // Got to grab this out of prefs, since it isn't saved from mailbox_view.php if ($allow_thread_sort) { $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0); @@ -290,26 +293,32 @@ function sqimap_mailbox_expunge_dmn($message_id) if ($auto_expunge) { $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); + } else { + return $cnt; } // 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 ) { - $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); + 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 = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse); + } + } else { + $server_sort_array = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse); } - } else { - $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response); + } else { + $server_sort_array = sqimap_get_php_sort_order($imapConnection, + $sort,$aMbxResponse); } - sqsession_register('server_sort_array',$server_sort_array); + sqsession_register($server_sort_array,'server_sort_array'); return $cnt; } diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 9eee2887..48fbb313 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -460,7 +460,7 @@ function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) { */ function getServerSortMessages($imapConnection, $start_msg, $show_num, $num_msgs, $server_sort_order, $mbxresponse) { - if (isset($mbxresponse['SORT_ARRAY']) && $mbxresponse['SORT_ARRAY']) { + if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) { $id = $mbxresponse['SORT_ARRAY']; } else { $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); diff --git a/src/read_body.php b/src/read_body.php index 77f34d87..99cb4ce8 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -830,8 +830,7 @@ $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, */ if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) { sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox); - - sqimap_mailbox_expunge_dmn($delete_id); + sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array); } /** @@ -844,7 +843,7 @@ $uidvalidity = $mbx_response['UIDVALIDITY']; if (!isset($messages[$uidvalidity])) { $messages[$uidvalidity] = array(); } -if (!isset($messages[$uidvalidity][$passed_id])) { +if (!isset($messages[$uidvalidity][$passed_id]) || $delete_id) { $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $FirstTimeSee = !$message->is_seen; $message->is_seen = true; diff --git a/src/right_main.php b/src/right_main.php index b07aec7a..e3d5a505 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -156,17 +156,29 @@ $aMbxResponse['SORT_ARRAY'] = false; sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION); +// deal with imap servers that do not return the required UIDNEXT or +// UIDVALIDITY response +// from a SELECT call (since rfc 3501 it's required) +if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) { + $aStatus = sqimap_status_messages($imapConnection,$mailbox, + array('UIDNEXT','UIDVALIDITY')); + $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT']; + $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY']; +} + 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; - } - } + // 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); + if ($server_sort_array && is_array($server_sort_array)) { + $aMbxResponse['SORT_ARRAY'] = $server_sort_array; + } + } + } } $aLastSelectedMailbox['NAME'] = $mailbox; -- 2.25.1