Changeset e8a1b7e in github for program/lib/Mail/mimePart.php


Ignore:
Timestamp:
Sep 5, 2008 2:53:51 AM (5 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
5ec762a
Parents:
0dbac32
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/Mail/mimePart.php

    r1c25366 re8a1b7e  
    389389     * @param $charset      The characterset of $value 
    390390     * @param $language     The language used in $value 
    391      * @param $maxLength    The maximum length of a line. Defauls to 75 
     391     * @param $maxLength    The maximum length of a line. Defauls to 78 
    392392     * 
    393393     * @access private 
    394394     */ 
    395     function _buildHeaderParam($name, $value, $charset=NULL, $language=NULL, $maxLength=75) 
    396     { 
    397         //If we find chars to encode, or if charset or language 
    398         //is not any of the defaults, we need to encode the value. 
    399         $shouldEncode = 0; 
    400         $secondAsterisk = ''; 
    401         if (preg_match('#([ \x80-\xFF \*\'\\%\t(\)\<\>\@\,\;\:\\\"/\[\]\?\=]){1}#', $value)) { 
    402             $shouldEncode = 1; 
    403         } elseif ($charset && (strtolower($charset) != 'us-ascii')) { 
    404             $shouldEncode = 1; 
    405         } elseif ($language && ($language != 'en' && $language != 'en-us')) { 
    406             $shouldEncode = 1; 
    407         } 
    408         if ($shouldEncode) { 
    409             $encValue = preg_replace('#([\x80-\xFF \*\'\%\t\(\)\<\>\@\,\;\:\\\"/\[\]\?\=])#e', '"%" . strtoupper(dechex(ord("\1")))', $value); 
    410             $value = "$charset'$language'$encValue"; 
    411             $secondAsterisk = '*'; 
    412         } 
    413         $header = " {$name}{$secondAsterisk}=\"{$value}\"; "; 
     395    function _buildHeaderParam($name, $value, $charset=NULL, $language=NULL, $maxLength=78) 
     396    { 
     397        // RFC 2183/2184/2822:  
     398        // value needs encoding if contains non-ASCII chars or is longer than 78 chars 
     399 
     400        if (preg_match('#[\x20-\x7E]#', $value)) { // ASCII 
     401            $quoted = addcslashes($value, '\\"'); 
     402            if (strlen($name) + strlen($quoted) + 6 <= $maxLength) 
     403                return " {$name}=\"{$quoted}\"; "; 
     404        } 
     405 
     406        $encValue = preg_replace('#([^\x20-\x7E])#e', '"%" . strtoupper(dechex(ord("\1")))', $value); 
     407        $value = "$charset'$language'$encValue"; 
     408 
     409        $header = " {$name}*=\"{$value}\"; "; 
    414410        if (strlen($header) <= $maxLength) { 
    415411            return $header; 
    416412        } 
    417413 
    418         $preLength = strlen(" {$name}*0{$secondAsterisk}=\""); 
     414        $preLength = strlen(" {$name}*0*=\""); 
    419415        $sufLength = strlen("\";"); 
    420416        $maxLength = MAX(16, $maxLength - $preLength - $sufLength - 2); 
     
    427423            $found = preg_match($maxLengthReg, $value, $matches); 
    428424            if ($found) { 
    429                 $headers[] = " {$name}*{$headCount}{$secondAsterisk}=\"{$matches[0]}\""; 
     425                $headers[] = " {$name}*{$headCount}*=\"{$matches[0]}\""; 
    430426                $value = substr($value, strlen($matches[0])); 
    431427            } else { 
    432                 $headers[] = " {$name}*{$headCount}{$secondAsterisk}=\"{$value}\""; 
     428                $headers[] = " {$name}*{$headCount}*=\"{$value}\""; 
    433429                $value = ""; 
    434430            } 
Note: See TracChangeset for help on using the changeset viewer.