Index: includes/unicode.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/unicode.inc,v retrieving revision 1.26 diff -u -p -r1.26 unicode.inc --- includes/unicode.inc 12 May 2007 06:08:56 -0000 1.26 +++ includes/unicode.inc 19 Jun 2007 00:41:25 -0000 @@ -236,13 +236,21 @@ function truncate_utf8($string, $len, $w * See http://www.rfc-editor.org/rfc/rfc2047.txt for more information. * * Notes: - * - Only encode strings that contain non-ASCII characters. + * - Only encode strings that contain non-ASCII characters, unless the + * optional second parameter is defined, in which case quoted-string + * encoding will be performed on strings containing non-alphanumeric + * characters. * - We progressively cut-off a chunk with truncate_utf8(). This is to ensure * each chunk starts and ends on a character boundary. * - Using \n as the chunk separator may cause problems on some systems and may * have to be changed to \r\n or \r. + * + * @param $string + * The string to encode. + * @param $quoted + * If set, perform quoted-string encoding of non-alphanumeric ASCII. */ -function mime_header_encode($string) { +function mime_header_encode($string, $quoted = FALSE) { if (preg_match('/[^\x20-\x7E]/', $string)) { $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75); $len = strlen($string); @@ -256,6 +264,12 @@ function mime_header_encode($string) { } return trim($output); } + // Strings containing spaces and certain other characters must in some + // cases be quoted-string encoded. + if ($quoted && preg_match('/[^A-Za-z0-9_]/', $string)) { + // Escape double-quotes and backslashes. + return '"'. addcslashes($string, '\"') .'"'; + } return $string; }