From 2c300e0bd43c97cc97a76b2bd5d4af72bc6e4999 Mon Sep 17 00:00:00 2001 From: alex-brainstorm Date: Fri, 30 Apr 2004 22:54:10 +0000 Subject: [PATCH] Handle KMG for LARGER and SMALLER, and add default value for asearch_nz() git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7333 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_asearch.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/functions/imap_asearch.php b/functions/imap_asearch.php index b6b3a7db..48ce5ead 100644 --- a/functions/imap_asearch.php +++ b/functions/imap_asearch.php @@ -14,7 +14,7 @@ * @package squirrelmail * @subpackage imap * @see search.php - * @link ftp://ftp.rfc-editor.org/in-notes/rfc3501.txt + * @link http://www.ietf.org/rfc/rfc3501.txt * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr */ @@ -31,7 +31,7 @@ $imap_asearch_debug_dump = FALSE; * @global array $imap_asearch_opcodes */ $imap_asearch_opcodes = array( -/* => 'asequence', */ +/* => 'asequence', */ // Special handling, @see sqimap_asearch_build_criteria() /*'ALL' is binary operator */ 'ANSWERED' => '', 'BCC' => 'astring', @@ -42,7 +42,7 @@ $imap_asearch_opcodes = array( 'DRAFT' => '', 'FLAGGED' => '', 'FROM' => 'astring', - 'HEADER' => 'afield', /* Special syntax for this one, see below */ + 'HEADER' => 'afield', // Special syntax for this one, @see sqimap_asearch_build_criteria() 'KEYWORD' => 'akeyword', 'LARGER' => 'anum', 'NEW' => '', @@ -141,15 +141,16 @@ function sqimap_asearch_error_box($response, $query, $message, $link = '') } /** - * This is to avoid the E_NOTICE warnings signaled by marc AT squirrelmail.org. Thanks Marc! + * This is a convenient way to avoid spreading if (isset(... all over the code * @param mixed $var any variable (reference) - * @return mixed zls ('') if $var is not defined, otherwise $var + * @param mixed $def default value to return if unset (default is zls (''), pass 0 if required) + * @return mixed $def if $var is unset, otherwise $var */ -function asearch_nz(&$var) +function asearch_nz(&$var, $def = '') { if (isset($var)) return $var; - return ''; + return $def; } /** @@ -268,10 +269,22 @@ function sqimap_asearch_build_criteria($opcode, $what, $charset) switch ($imap_asearch_opcodes[$opcode]) { default: case 'anum': -// $what = str_replace(' ', '', $what); - $what = ereg_replace('[^0-9]+', '', $what); - if ($what != '') + $what = str_replace(' ', '', $what); + $what = ereg_replace('[^0-9]+[^KMG]$', '', strtoupper($what)); + if ($what != '') { + switch (substr($what, -1)) { + case 'G': + $what <<= 10; + //nobreak; + case 'M': + $what <<= 10; + //nobreak; + case 'K': + $what <<= 10; + break; + } $criteria = $opcode . ' ' . $what . ' '; + } break; case '': //aflag $criteria = $opcode . ' '; @@ -321,7 +334,7 @@ function sqimap_array_merge_unique(&$to, $from) /** * Run the imap SEARCH command as defined in rfc 3501 - * @link ftp://ftp.rfc-editor.org/in-notes/rfc3501.txt + * @link http://www.ietf.org/rfc/rfc3501.txt * @param resource $imapConnection the current imap stream * @param string $search_string the full search expression eg "ALL RECENT" * @param string $search_charset charset to use or zls ('') -- 2.25.1