From e5d68a9599c0cd64fa2e61148ddd95ecb870834b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 21 Apr 2010 15:00:28 -0600 Subject: [PATCH] escape() should only add quotes if string needs to be quoted --- framework/Imap_Client/lib/Horde/Imap/Client/Utils.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Utils.php b/framework/Imap_Client/lib/Horde/Imap/Client/Utils.php index 7d8dff53c..105b675de 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Utils.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Utils.php @@ -161,15 +161,25 @@ class Horde_Imap_Client_Utils } /** - * Escape IMAP output via a quoted string (see RFC 3501 [4.3]). + * Escape IMAP output via a quoted string (see RFC 3501 [4.3]). Note that + * IMAP quoted strings support 7-bit characters only and can not contain + * either CR or LF. * - * @param string $str The unescaped string. + * @param string $str The unescaped string. + * @param boolean $force Always add quotes? * * @return string The escaped string. */ - public function escape($str) + public function escape($str, $force = false) { - return '"' . addcslashes($str, '"\\') . '"'; + if (!strlen($str)) { + return '""'; + } + + $newstr = addcslashes($str, '"\\'); + return (!$force && ($str == $newstr)) + ? $str + : '"' . $newstr . '"'; } /** -- 2.11.0