diff --git a/core/lib/Drupal/Component/Utility/Unicode.php b/core/lib/Drupal/Component/Utility/Unicode.php index 75ffa1b..923edca 100644 --- a/core/lib/Drupal/Component/Utility/Unicode.php +++ b/core/lib/Drupal/Component/Utility/Unicode.php @@ -569,8 +569,7 @@ public static function strcasecmp($str1 , $str2) { * - Only encode strings that contain non-ASCII characters. * - We progressively cut-off a chunk with self::truncateBytes(). This ensures * 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. + * - According to the RFC 2047, we use \r\n as the chunk separator. * * @param string $string * The header to encode. @@ -580,12 +579,12 @@ public static function strcasecmp($str1 , $str2) { */ public static function mimeHeaderEncode($string) { if (preg_match('/[^\x20-\x7E]/', $string)) { - $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75); + $chunk_size = 45; // floor((75 - strlen("=?UTF-8?B??=\r\n ")) * 0.75); $len = strlen($string); $output = ''; while ($len > 0) { $chunk = static::truncateBytes($string, $chunk_size); - $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\n"; + $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\r\n "; $c = strlen($chunk); $string = substr($string, $c); $len -= $c; diff --git a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php index 724d875..1a8a08a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php @@ -90,8 +90,14 @@ public function testMimeHeader($value, $encoded) { public function providerTestMimeHeader() { return array( array('tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='), + // String longer than 47 characters including special characters. The + // result is an encoded chunk splitted in two parts separated by a CLRF + // and a space. + array('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaà', "=?UTF-8?B?YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh?=\r\n =?UTF-8?B?YWHDoA==?="), // Simple ASCII characters. array('ASCII', 'ASCII'), + // Long ASCII string (more than 47 characters). + array('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), ); }