From f171f05a946fd875802d3cc8e41147a9bfeb7e3a Mon Sep 17 00:00:00 2001 From: stekkel Date: Sun, 29 Jan 2006 10:36:06 +0000 Subject: [PATCH] Request a sqimap_run_command_list instead of a sqimap_run_command because in case of unsollicited responses sqimap_run_command only returns the first response and if that's the unsollicited one instead of the SORT or SEARCH response we loose the requested response git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@10604 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_asearch.php | 4 ++-- functions/imap_messages.php | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/functions/imap_asearch.php b/functions/imap_asearch.php index b1da9532..88684694 100644 --- a/functions/imap_asearch.php +++ b/functions/imap_asearch.php @@ -313,12 +313,12 @@ function sqimap_run_search($imapConnection, $search_string, $search_charset) $query = 'SEARCH CHARSET "' . strtoupper($search_charset) . '" ' . $search_string; else $query = 'SEARCH ' . $search_string; - $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, TRUE); + $readin = sqimap_run_command_list($imapConnection, $query, false, $response, $message, TRUE); /* 6.4.4 try US-ASCII charset if we tried an OPTIONAL [CHARSET] and received a tagged NO response (SHOULD be [BADCHARSET]) */ if (($search_charset != '') && (strtoupper($response) == 'NO')) { $query = 'SEARCH CHARSET US-ASCII ' . $search_string; - $readin = sqimap_run_command($imapConnection, $query, false, $response, $message, TRUE); + $readin = sqimap_run_command_list($imapConnection, $query, false, $response, $message, TRUE); } if (strtoupper($response) != 'OK') { sqimap_asearch_error_box($response, $query, $message); diff --git a/functions/imap_messages.php b/functions/imap_messages.php index a8bd46b8..2bdf5e79 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -39,7 +39,7 @@ function sqimap_msgs_list_copy($imap_stream, $id, $mailbox, $handle_errors = tru * @param string $id The list of messages to move * @param string $mailbox The destination to move to * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response - * @param string $source_mailbox (since 1.5.1) name of source mailbox. It is used to + * @param string $source_mailbox (since 1.5.1) name of source mailbox. It is used to * validate that target mailbox != source mailbox. * @return bool If the move completed without errors */ @@ -162,14 +162,16 @@ function sqimap_get_sort_order($imap_stream, $sSortField, $reverse, $search='ALL } $query = "SORT ($sSortField) ".strtoupper($default_charset)." $search"; // FIX ME sqimap_run_command should return the parsed data accessible by $aDATA['SORT'] - $aData = sqimap_run_command ($imap_stream, $query, false, $response, $message, TRUE); + // use sqimap_run_command_list in case of unsollicited responses. If we don't we could loose the SORT response + $aData = sqimap_run_command_list ($imap_stream, $query, false, $response, $message, TRUE); /* fallback to default charset */ if ($response == 'NO' && strpos($message,'[BADCHARSET]') !== false) { $query = "SORT ($sSortField) US-ASCII $search"; - $aData = sqimap_run_command ($imap_stream, $query, true, $response, $message, TRUE); + $aData = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, TRUE); } } + if ($response == 'OK') { return parseUidList($aData,'SORT'); } else { @@ -180,7 +182,7 @@ function sqimap_get_sort_order($imap_stream, $sSortField, $reverse, $search='ALL /** * Parses a UID list returned on a SORT or SEARCH request - * @param array $aData imap response + * @param array $aData imap response (retrieved from sqimap_run_command_list) * @param string $sCommand issued imap command (SEARCH or SORT) * @return array $aUid uid list */ @@ -188,8 +190,10 @@ function parseUidList($aData,$sCommand) { $aUid = array(); if (isset($aData) && count($aData)) { for ($i=0,$iCnt=count($aData);$i<$iCnt;++$i) { - if (preg_match("/^\* $sCommand (.+)$/", $aData[$i], $aMatch)) { - $aUid += preg_split("/ /", trim($aMatch[1])); + for ($j=0,$jCnt=count($aData[$i]);$j<$jCnt;++$j) { + if (preg_match("/^\* $sCommand (.+)$/", $aData[$i][$j], $aMatch)) { + $aUid += preg_split("/ /", trim($aMatch[1])); + } } } } -- 2.25.1