From 267b2e40ac4bcbd2baabf89594d9e8a2e7e5372e Mon Sep 17 00:00:00 2001 From: stekkel Date: Fri, 23 May 2003 11:51:05 +0000 Subject: [PATCH] Minor fixes in parseAddress and limit the returned results to 1 address (performance) in case we are displaying the sent folder git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4902 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_general.php | 27 +++++++++++++++------------ functions/mailbox_display.php | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/functions/imap_general.php b/functions/imap_general.php index 16f84a27..8d58c48b 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -432,30 +432,33 @@ function sqimap_get_num_messages ($imap_stream, $mailbox) { } -function parseAddress($address, $max=0, $addr_ar = array(), $group = '', $host='') { +function parseAddress($address, $max=0, $addr_ar = array(), $group = '', $host='', $limit=0) { $pos = 0; $j = strlen($address); $personal = ''; $addr = ''; $comment = ''; - if ($max && $max = count($addr_ar)) { + if ($max && $max == count($addr_ar)) { return $addr_ar; } while ($pos < $j) { - if ($max && $max = count($addr_ar)) { + if ($max && $max == count($addr_ar)) { return $addr_ar; } $char = $address{$pos}; switch ($char) { case '=': + /* check if it is an encoded string */ if (preg_match('/^(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',substr($address,$pos),$reg)) { + /* add stringpart before the encoded string to the personal var */ if (!$personal) { $personal = substr($address,0,$pos); } $personal .= $reg[1]; - $pos += strlen($personal); - } - ++$pos; + $pos += strlen($reg[1]); + } else { + ++$pos; + } break; case '"': /* get the personal name */ ++$pos; @@ -498,6 +501,12 @@ function parseAddress($address, $max=0, $addr_ar = array(), $group = '', $host=' $j = strlen($address); $pos = $addr_start + 1; break; + case ';': /* we reached a non rfc2822 compliant delimiter */ + if ($group) { + $address = substr($address, 0, $pos - 1); + ++$pos; + break; + } case ',': /* we reached a delimiter */ if ($addr == '') { $addr = substr($address, 0, $pos); @@ -524,12 +533,6 @@ function parseAddress($address, $max=0, $addr_ar = array(), $group = '', $host=' $j = strlen($address); $group = ''; break; - case ';': - if ($group) { - $address = substr($address, 0, $pos - 1); - } - ++$pos; - break; default: ++$pos; break; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 30d36f71..426609ed 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -73,7 +73,7 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox, if (handleAsSent($mailbox)) { $msg['FROM'] = $msg['TO']; } - $msg['FROM'] = parseAddress($msg['FROM']); + $msg['FROM'] = parseAddress($msg['FROM'],1); /* * This is done in case you're looking into Sent folders, -- 2.25.1