comparison core/lib/Drupal/Component/Utility/Unicode.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
601 * - Using \n as the chunk separator may cause problems on some systems and 601 * - Using \n as the chunk separator may cause problems on some systems and
602 * may have to be changed to \r\n or \r. 602 * may have to be changed to \r\n or \r.
603 * 603 *
604 * @param string $string 604 * @param string $string
605 * The header to encode. 605 * The header to encode.
606 * @param bool $shorten
607 * If TRUE, only return the first chunk of a multi-chunk encoded string.
606 * 608 *
607 * @return string 609 * @return string
608 * The mime-encoded header. 610 * The mime-encoded header.
609 */ 611 */
610 public static function mimeHeaderEncode($string) { 612 public static function mimeHeaderEncode($string, $shorten = FALSE) {
611 if (preg_match('/[^\x20-\x7E]/', $string)) { 613 if (preg_match('/[^\x20-\x7E]/', $string)) {
612 // floor((75 - strlen("=?UTF-8?B??=")) * 0.75); 614 // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
613 $chunk_size = 47; 615 $chunk_size = 47;
614 $len = strlen($string); 616 $len = strlen($string);
615 $output = ''; 617 $output = '';
616 while ($len > 0) { 618 while ($len > 0) {
617 $chunk = static::truncateBytes($string, $chunk_size); 619 $chunk = static::truncateBytes($string, $chunk_size);
618 $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\n"; 620 $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\n";
621 if ($shorten) {
622 break;
623 }
619 $c = strlen($chunk); 624 $c = strlen($chunk);
620 $string = substr($string, $c); 625 $string = substr($string, $c);
621 $len -= $c; 626 $len -= $c;
622 } 627 }
623 return trim($output); 628 return trim($output);