Ignore:
Timestamp:
Nov 26, 2009 6:11:27 AM (4 years ago)
Author:
alec
Message:
  • code cleanup (mostly whitespaces)
File:
1 edited

Legend:

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

    r3088 r3138  
    183183            } 
    184184        } 
    185          
     185 
    186186        if (isset($contentType['type'])) { 
    187187            $headers['Content-Type'] = $contentType['type']; 
    188             if (isset($contentType['charset'])) { 
     188        if (isset($contentType['charset'])) { 
    189189                $headers['Content-Type'] .= "; charset={$contentType['charset']}"; 
    190190            } 
     
    192192                $headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF; 
    193193                $headers['Content-Type'] .= 
    194                     $this->_buildHeaderParam('name', $contentType['name'],  
    195                         isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII',  
     194                    $this->_buildHeaderParam('name', $contentType['name'], 
     195                        isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII', 
    196196                        isset($contentType['language']) ? $contentType['language'] : NULL, 
    197                         isset($params['name-encoding']) ?  $params['name-encoding'] : NULL); 
     197                        isset($params['name-encoding']) ?  $params['name-encoding'] : NULL); 
    198198            } 
    199199        } 
     
    205205                $headers['Content-Disposition'] .= ';' . MAIL_MIMEPART_CRLF; 
    206206                $headers['Content-Disposition'] .= 
    207                     $this->_buildHeaderParam('filename', $contentDisp['filename'],  
    208                         isset($contentDisp['charset']) ? $contentDisp['charset'] : 'US-ASCII',  
     207                    $this->_buildHeaderParam('filename', $contentDisp['filename'], 
     208                        isset($contentDisp['charset']) ? $contentDisp['charset'] : 'US-ASCII', 
    209209                        isset($contentDisp['language']) ? $contentDisp['language'] : NULL, 
    210                         isset($params['filename-encoding']) ? $params['filename-encoding'] : NULL); 
     210                        isset($params['filename-encoding']) ? $params['filename-encoding'] : NULL); 
    211211            } 
    212212        } 
     
    258258 
    259259            $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF .  
    260                                 implode('--' . $boundary . MAIL_MIMEPART_CRLF , $subparts) . 
    261                                 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF; 
     260                        implode('--' . $boundary . MAIL_MIMEPART_CRLF , $subparts) . 
     261                        '--' . $boundary.'--' . MAIL_MIMEPART_CRLF; 
    262262 
    263263        } else { 
     
    399399    { 
    400400        // RFC 2045:  
    401         // value needs encoding if contains non-ASCII chars or is longer than 78 chars 
     401        // value needs encoding if contains non-ASCII chars or is longer than 78 chars 
    402402        if (!preg_match('#[^\x20-\x7E]#', $value)) { // ASCII 
    403             // token 
    404             if (!preg_match('#([^\x21,\x23-\x27,\x2A,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#', $value)) { 
    405                 if (strlen($name) + strlen($value) + 3 <= $maxLength) 
    406                     return " {$name}={$value};"; 
    407             } else { // quoted-string 
    408                 $quoted = addcslashes($value, '\\"'); 
    409                 if (strlen($name) + strlen($quoted) + 5 <= $maxLength) 
    410                     return " {$name}=\"{$quoted}\";"; 
    411             } 
    412         } 
    413  
    414         // RFC2047: use quoted-printable/base64 encoding 
    415         if ($paramEnc == 'quoted-printable' || $paramEnc == 'base64') 
    416             return $this->_buildRFC2047Param($name, $value, $charset, $paramEnc); 
    417  
    418         // RFC2231: 
    419         $encValue = preg_replace('#([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#e', 
    420                         '"%" . strtoupper(dechex(ord("\1")))', $value); 
     403            // token 
     404            if (!preg_match('#([^\x21,\x23-\x27,\x2A,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#', $value)) { 
     405                if (strlen($name) + strlen($value) + 3 <= $maxLength) 
     406                    return " {$name}={$value};"; 
     407            } else { // quoted-string 
     408                $quoted = addcslashes($value, '\\"'); 
     409                if (strlen($name) + strlen($quoted) + 5 <= $maxLength) 
     410                    return " {$name}=\"{$quoted}\";"; 
     411            } 
     412        } 
     413 
     414        // RFC2047: use quoted-printable/base64 encoding 
     415        if ($paramEnc == 'quoted-printable' || $paramEnc == 'base64') 
     416            return $this->_buildRFC2047Param($name, $value, $charset, $paramEnc); 
     417 
     418        // RFC2231: 
     419        $encValue = preg_replace( 
     420            '#([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#e', 
     421            '"%" . strtoupper(dechex(ord("\1")))', 
     422            $value); 
    421423        $value = "$charset'$language'$encValue"; 
    422424 
     
    462464    function _buildRFC2047Param($name, $value, $charset, $encoding='quoted-printable', $maxLength=75) 
    463465    { 
    464         // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in 
    465         // parameter of a MIME Content-Type or Content-Disposition field" 
    466         // but... it's supported by many clients/servers 
    467      
    468         if ($encoding == 'base64') 
    469         { 
    470             $value = base64_encode($value); 
     466        // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in 
     467        // parameter of a MIME Content-Type or Content-Disposition field" 
     468        // but... it's supported by many clients/servers 
     469 
     470        if ($encoding == 'base64') 
     471        { 
     472            $value = base64_encode($value); 
    471473            $prefix = '=?' . $charset . '?B?'; 
    472474            $suffix = '?='; 
    473             $quoted = ''; 
    474  
    475             $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 
    476             $len = $add_len + strlen($value); 
    477  
    478             while ($len > $maxLength) {  
    479                 // We can cut base64-encoded string every 4 characters 
    480                 $real_len = floor(($maxLength - $add_len) / 4) * 4; 
    481                 $_quote = substr($value, 0, $real_len); 
    482                 $value = substr($value, $real_len); 
    483  
    484                 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 
    485                 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 
    486                 $len = strlen($value) + $add_len; 
    487             }  
     475            $quoted = ''; 
     476 
     477            $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 
     478            $len = $add_len + strlen($value); 
     479 
     480            while ($len > $maxLength) {  
     481                // We can cut base64-encoded string every 4 characters 
     482                $real_len = floor(($maxLength - $add_len) / 4) * 4; 
     483                $_quote = substr($value, 0, $real_len); 
     484                $value = substr($value, $real_len); 
     485 
     486                $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 
     487                $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 
     488                $len = strlen($value) + $add_len; 
     489            } 
    488490            $quoted .= $prefix . $value . $suffix; 
    489491 
    490492        } 
    491         else // quoted-printable 
    492         { 
    493             // Replace all special characters used by the encoder. 
     493        else // quoted-printable 
     494        { 
     495            // Replace all special characters used by the encoder. 
    494496            $search  = array('=',   '_',   '?',   ' '); 
    495             $replace = array('=3D', '=5F', '=3F', '_'); 
    496             $value = str_replace($search, $replace, $value); 
    497  
    498             // Replace all extended characters (\x80-xFF) with their 
    499             // ASCII values. 
    500             $value = preg_replace('/([\x80-\xFF])/e',  
    501                 '"=" . strtoupper(dechex(ord("\1")))', $value); 
     497            $replace = array('=3D', '=5F', '=3F', '_'); 
     498            $value = str_replace($search, $replace, $value); 
     499 
     500            // Replace all extended characters (\x80-xFF) with their 
     501            // ASCII values. 
     502            $value = preg_replace('/([\x80-\xFF])/e', 
     503                '"=" . strtoupper(dechex(ord("\1")))', $value); 
    502504 
    503505            $prefix = '=?' . $charset . '?Q?'; 
    504506            $suffix = '?='; 
    505507 
    506             $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 
    507             $len = $add_len + strlen($value); 
    508              
    509             while ($len > $maxLength) {  
    510                 $length = $maxLength - $add_len; 
    511                 // not break any encoded letters 
    512                 if(preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) 
    513                     $_quote = $matches[1]; 
    514                  
    515                 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 
    516                 $value = substr($value, strlen($_quote)); 
    517                 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 
    518                 $len = strlen($value) + $add_len; 
    519             } 
    520          
    521             $quoted .= $prefix . $value . $suffix; 
     508            $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 
     509            $len = $add_len + strlen($value); 
     510 
     511            while ($len > $maxLength) { 
     512                $length = $maxLength - $add_len; 
     513                // not break any encoded letters 
     514                if(preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) 
     515                    $_quote = $matches[1]; 
     516 
     517                $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 
     518                $value = substr($value, strlen($_quote)); 
     519                $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 
     520                $len = strlen($value) + $add_len; 
     521            } 
     522 
     523            $quoted .= $prefix . $value . $suffix; 
    522524        } 
    523525 
Note: See TracChangeset for help on using the changeset viewer.