From: Michael M Slusarz Date: Wed, 21 Apr 2010 21:00:28 +0000 (-0600) Subject: escape() should only add quotes if string needs to be quoted X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e5d68a9599c0cd64fa2e61148ddd95ecb870834b;p=horde.git escape() should only add quotes if string needs to be quoted --- 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 . '"'; } /**