Changeset f7f9346 in github


Ignore:
Timestamp:
Nov 26, 2009 6:11:27 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
539df6b
Parents:
a5f430d
Message:
  • code cleanup (mostly whitespaces)
Location:
program/lib/Mail
Files:
2 edited

Legend:

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

    rc9ca6ad rf7f9346  
    333333                           $c_type      = 'application/octet-stream', 
    334334                           $name        = '', 
    335                             $isfile     = true, 
     335                           $isfile      = true, 
    336336                           $encoding    = 'base64', 
    337337                           $disposition = 'attachment', 
    338338                           $charset     = '', 
    339                             $language   = '', 
     339                           $language    = '', 
    340340                           $location    = '', 
    341                            $n_encoding  = NULL, 
    342                            $f_encoding   = NULL) 
    343     { 
    344         $filedata = ($isfile === true) ? $this->_file2str($file) 
    345                                            : $file; 
     341                           $n_encoding  = NULL, 
     342                           $f_encoding  = NULL) 
     343    { 
     344        $filedata = ($isfile === true) ? $this->_file2str($file) : $file; 
     345 
     346        if (PEAR::isError($filedata)) { 
     347            return $filedata; 
     348        } 
     349 
    346350        if ($isfile === true) { 
    347351            // Force the name the user supplied, otherwise use $file 
     
    356360        } 
    357361        $filename = $this->_basename($filename); 
    358         if (PEAR::isError($filedata)) { 
    359             return $filedata; 
    360         } 
    361362 
    362363        $this->_parts[] = array( 
     
    369370                                'location'    => $location, 
    370371                                'disposition' => $disposition, 
    371                                 'name-encoding'    => $n_encoding, 
    372                                 'filename-encoding'=> $f_encoding 
     372                                'name-encoding'     => $n_encoding, 
     373                                'filename-encoding' => $f_encoding 
    373374                               ); 
    374375        return true; 
     
    398399            return $err; 
    399400        } 
    400          
     401 
    401402        //Temporarily reset magic_quotes_runtime and read file contents 
    402403        if ($magic_quote_setting = get_magic_quotes_runtime()) { 
    403404            set_magic_quotes_runtime(0); 
    404405        } 
    405         $cont = file_get_contents($file_name);         
     406        $cont = file_get_contents($file_name); 
    406407        if ($magic_quote_setting) { 
    407408            set_magic_quotes_runtime($magic_quote_setting); 
    408409        } 
    409          
     410 
    410411        return $cont; 
    411412    } 
     
    472473        $params                 = array(); 
    473474        $params['content_type'] = 'multipart/mixed'; 
    474          
     475 
    475476        //Create empty multipart/mixed Mail_mimePart object to return 
    476477        $ret = new Mail_mimePart('', $params); 
     
    539540        $params['dfilename']    = $value['name']; 
    540541        $params['cid']          = $value['cid']; 
    541         if ($value['name-encoding']) { 
    542             $params['name-encoding'] = $value['name-encoding']; 
    543         } 
    544         if ($value['filename-encoding']) { 
    545             $params['filename-encoding'] = $value['filename-encoding']; 
    546         } 
    547          
     542 
     543        if (!empty($value['name-encoding'])) { 
     544            $params['name-encoding'] = $value['name-encoding']; 
     545        } 
     546        if (!empty($value['filename-encoding'])) { 
     547            $params['filename-encoding'] = $value['filename-encoding']; 
     548        } 
     549 
    548550        $ret = $obj->addSubpart($value['body'], $params); 
    549551        return $ret; 
    550      
     552 
    551553    } 
    552554 
     
    574576            $params['location'] = $value['location']; 
    575577        } 
    576         if ($value['name-encoding']) { 
    577             $params['name-encoding'] = $value['name-encoding']; 
    578         } 
    579         if ($value['filename-encoding']) { 
    580             $params['filename-encoding'] = $value['filename-encoding']; 
    581         } 
     578        if ($value['name-encoding']) { 
     579            $params['name-encoding'] = $value['name-encoding']; 
     580        } 
     581        if ($value['filename-encoding']) { 
     582            $params['filename-encoding'] = $value['filename-encoding']; 
     583        } 
    582584        $params['content_type'] = $value['c_type']; 
    583585        $params['disposition']  = isset($value['disposition']) ?  
     
    606608     */ 
    607609    function getMessage( 
    608                         $separation   = null,  
    609                         $build_params = null,  
    610                         $xtra_headers = null,  
     610                        $separation   = null, 
     611                        $build_params = null, 
     612                        $xtra_headers = null, 
    611613                        $overwrite    = false 
    612614                       ) 
     
    659661            } 
    660662        } 
    661          
     663 
    662664        if (isset($this->_headers['From'])){ 
    663665            //Bug #11381: Illegal characters in domain ID 
     
    671673            } 
    672674        } 
    673          
     675 
    674676        if (count($this->_html_images) AND isset($this->_htmlbody)) { 
    675677            foreach ($this->_html_images as $key => $value) { 
     
    685687 
    686688                $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody); 
    687                 $this->_html_images[$key]['name'] =  
     689                $this->_html_images[$key]['name'] = 
    688690                    $this->_basename($this->_html_images[$key]['name']); 
    689691            } 
     
    776778        if (isset($message)) { 
    777779            $output = $message->encode(); 
    778              
     780 
    779781            $this->_headers = array_merge($this->_headers, 
    780782                                          $output['headers']); 
     
    832834    { 
    833835        $headers = $this->headers($xtra_headers, $overwrite); 
    834          
     836 
    835837        $ret = ''; 
    836838        foreach ($headers as $key => $val) { 
     
    944946        //Note: Atom as specified here is not exactly the same as an RFC822 atom, 
    945947        //as $atom's may contain just a single space. 
    946                  
    947         $useIconv = true;         
     948 
     949        $useIconv = true; 
    948950        if (isset($build_params['ignore-iconv'])) { 
    949951            $useIconv = !$build_params['ignore-iconv']; 
    950         }             
     952        } 
    951953        foreach ($input as $hdr_name => $hdr_value) { 
    952954            /* 
     
    978980                    $imePrefs['line-length'] = 74; 
    979981                    $imePrefs['line-break-chars'] = "\r\n"; //Specified in RFC2047 
    980                      
     982 
    981983                    $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs); 
    982984                    $hdr_value = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_value); 
     
    985987                    //Base64 encode the entire string 
    986988                    $hdr_value = base64_encode($hdr_value); 
    987                      
     989 
    988990                    //Generate the header using the specified params and dynamicly  
    989991                    //determine the maximum length of such strings. 
     
    10011003                    $maxLength = $maxLength - ($maxLength % 4); 
    10021004                    $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4); 
    1003                      
     1005 
    10041006                    $cutpoint = $maxLength1stLine; 
    10051007                    $hdr_value_out = $hdr_value; 
     
    10101012                        $hdr_value_out = substr($hdr_value_out, $cutpoint); 
    10111013                        $cutpoint = $maxLength; 
    1012                         //RFC 2047 specifies that any split header should  
     1014                        //RFC 2047 specifies that any split header should 
    10131015                        //be seperated by a CRLF SPACE.  
    10141016                        if ($output) { 
    1015                             $output .=  "\r\n "; 
     1017                            $output .= "\r\n "; 
    10161018                        } 
    10171019                        $output .= $prefix . $part . $suffix; 
     
    10371039                        $quoteSuffix = '"'; 
    10381040                    } 
    1039                      
     1041 
    10401042                    //Generate the header using the specified params and dynamicly  
    10411043                    //determine the maximum length of such strings. 
     
    10491051                    $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; 
    10501052                    $maxLength = $maxLength - 1; 
    1051                      
     1053 
    10521054                    //Replace all special characters used by the encoder. 
    10531055                    $search  = array('=',   '_',   '?',   ' '); 
    10541056                    $replace = array('=3D', '=5F', '=3F', '_'); 
    10551057                    $hdr_value = str_replace($search, $replace, $hdr_value); 
    1056                      
     1058 
    10571059                    //Replace all extended characters (\x80-xFF) with their 
    10581060                    //ASCII values. 
     
    10681070                    //Concat the double quotes and encoded string together 
    10691071                    $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix; 
    1070                      
     1072 
    10711073                    $hdr_value_out = $hdr_value; 
    10721074                    $realMax = $maxLength1stLine + strlen($prefix . $suffix); 
     
    10791081                            //But make sure not to break any translated chars. 
    10801082                            $found = preg_match($reg, $hdr_value_out, $matches); 
    1081                              
     1083 
    10821084                            //After this first line, we need to use a different 
    10831085                            //regexp for the first line. 
    10841086                            $reg = $reg2nd; 
    1085                              
     1087 
    10861088                            //Save the found part and encapsulate it in the 
    10871089                            //prefix & suffix. Then remove the part from the 
     
    10951097                                $hdr_value_out = ""; 
    10961098                            } 
    1097                              
     1099 
    10981100                            //RFC 2047 specifies that any split header should  
    10991101                            //be seperated by a CRLF SPACE 
    11001102                            if ($output) { 
    1101                                 $output .=  "\r\n "; 
     1103                                $output .= "\r\n "; 
    11021104                            } 
    11031105                            $output .= $prefix . $part . $suffix; 
     
    11411143    function _basename($filename) 
    11421144    { 
    1143         // basename() is not unicode safe and locale dependent 
    1144         if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) 
    1145             return preg_replace('/^.*[\\\\\\/]/', '', $filename); 
    1146         else 
    1147             return preg_replace('/^.*[\/]/', '', $filename); 
     1145        // basename() is not unicode safe and locale dependent 
     1146        if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) 
     1147            return preg_replace('/^.*[\\\\\\/]/', '', $filename); 
     1148        else 
     1149            return preg_replace('/^.*[\/]/', '', $filename); 
    11481150    } 
    11491151 
  • program/lib/Mail/mimePart.php

    r31ddb5e rf7f9346  
    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.