Ticket #1485151: tspecials.patch

File tspecials.patch, 1.5 kB (added by arekm, 3 months ago)

Part of solution. Revert wrong commit r1576 and quote tspecials as defined in RFC2045.

  • program/lib/Mail/mimePart.php

     
    398398        //is not any of the defaults, we need to encode the value. 
    399399        $shouldEncode = 0; 
    400400        $secondAsterisk = ''; 
    401         if (preg_match('#([ \x80-\xFF \*\'\\%\t(\)\<\>\@\,\;\:\\\"/\[\]\?\=]){1}#', $value)) { 
     401        if (preg_match('#([\x80-\xFF]){1}#', $value)) { 
    402402            $shouldEncode = 1; 
    403403        } elseif ($charset && (strtolower($charset) != 'us-ascii')) { 
    404404            $shouldEncode = 1; 
     
    406406            $shouldEncode = 1; 
    407407        } 
    408408        if ($shouldEncode) { 
    409             $encValue = preg_replace('#([\x80-\xFF \*\'\%\t\(\)\<\>\@\,\;\:\\\"/\[\]\?\=])#e', '"%" . strtoupper(dechex(ord("\1")))', $value); 
     409            $search  = array('%',   ' ',   "\t"); 
     410            $replace = array('%25', '%20', '%09'); 
     411            $encValue = str_replace($search, $replace, $value); 
     412            $encValue = preg_replace('#([\x80-\xFF])#e', '"%" . strtoupper(dechex(ord("\1")))', $encValue); 
    410413            $value = "$charset'$language'$encValue"; 
    411414            $secondAsterisk = '*'; 
    412         } 
     415        } else { 
     416            $value = preg_replace('#([\(\)\<\>\@\,\;\:\\\"\/\[\[\?\=])#', '\\\\\\1', $value); 
     417        } 
    413418        $header = " {$name}{$secondAsterisk}=\"{$value}\"; "; 
    414419        if (strlen($header) <= $maxLength) { 
    415420            return $header;