Ignore:
Timestamp:
10/10/13 11:39:53 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/library/mime/mimePart.php

    r7673 r8235  
    4949 * @copyright 2003-2006 PEAR <pear-group@php.net> 
    5050 * @license   http://www.opensource.org/licenses/bsd-license.php BSD License 
    51  * @version   CVS: $Id: mimePart.php 314695 2011-08-10 07:18:07Z alec $ 
     51 * @version   CVS: $Id$ 
    5252 * @link      http://pear.php.net/package/Mail_mime 
    5353 */ 
     
    131131    */ 
    132132    var $_eol = "\r\n"; 
     133 
    133134 
    134135    /** 
     
    156157    *                         If not set, 'charset' will be used 
    157158    *     eol               - End of line sequence. Default: "\r\n" 
     159    *     headers           - Hash array with additional part headers. Array keys can be 
     160    *                         in form of <header_name>:<parameter_name> 
    158161    *     body_file         - Location of file with part's body (instead of $body) 
    159162    * 
     
    166169        } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat. 
    167170            $this->_eol = MAIL_MIMEPART_CRLF; 
     171        } 
     172 
     173        // Additional part headers 
     174        if (!empty($params['headers']) && is_array($params['headers'])) { 
     175            $headers = $params['headers']; 
    168176        } 
    169177 
     
    216224            } 
    217225        } 
     226 
     227        // header values encoding parameters 
     228        $h_charset  = !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII'; 
     229        $h_language = !empty($params['language']) ? $params['language'] : null; 
     230        $h_encoding = !empty($params['name_encoding']) ? $params['name_encoding'] : null; 
     231 
     232 
    218233        if (!empty($params['filename'])) { 
    219234            $headers['Content-Type'] .= ';' . $this->_eol; 
    220235            $headers['Content-Type'] .= $this->_buildHeaderParam( 
    221                 'name', $params['filename'], 
    222                 !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
    223                 !empty($params['language']) ? $params['language'] : null, 
    224                 !empty($params['name_encoding']) ? $params['name_encoding'] : null 
     236                'name', $params['filename'], $h_charset, $h_language, $h_encoding 
    225237            ); 
    226238        } 
     
    232244                $headers['Content-Disposition'] .= ';' . $this->_eol; 
    233245                $headers['Content-Disposition'] .= $this->_buildHeaderParam( 
    234                     'filename', $params['filename'], 
    235                     !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
    236                     !empty($params['language']) ? $params['language'] : null, 
     246                    'filename', $params['filename'], $h_charset, $h_language, 
    237247                    !empty($params['filename_encoding']) ? $params['filename_encoding'] : null 
    238248                ); 
    239249            } 
     250 
     251            // add attachment size 
     252            $size = $this->_body_file ? filesize($this->_body_file) : strlen($body); 
     253            if ($size) { 
     254                $headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size; 
     255            } 
    240256        } 
    241257 
    242258        if (!empty($params['description'])) { 
    243259            $headers['Content-Description'] = $this->encodeHeader( 
    244                 'Content-Description', $params['description'], 
    245                 !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 
    246                 !empty($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable', 
     260                'Content-Description', $params['description'], $h_charset, $h_encoding, 
    247261                $this->_eol 
    248262            ); 
     263        } 
     264 
     265        // Search and add existing headers' parameters 
     266        foreach ($headers as $key => $value) { 
     267            $items = explode(':', $key); 
     268            if (count($items) == 2) { 
     269                $header = $items[0]; 
     270                $param  = $items[1]; 
     271                if (isset($headers[$header])) { 
     272                    $headers[$header] .= ';' . $this->_eol; 
     273                } 
     274                $headers[$header] .= $this->_buildHeaderParam( 
     275                    $param, $value, $h_charset, $h_language, $h_encoding 
     276                ); 
     277                unset($headers[$key]); 
     278            } 
    249279        } 
    250280 
     
    283313            $encoded['body'] = '';  
    284314 
    285             $subparts_count = count($this->_subparts); 
    286             for ($i = 0; $i < $subparts_count; ++$i) { 
     315            for ($i = 0; $i < count($this->_subparts); $i++) { 
    287316                $encoded['body'] .= '--' . $boundary . $eol; 
    288317                $tmp = $this->_subparts[$i]->encode(); 
    289                 if (PEAR::isError($tmp)) { 
     318                if ($this->_isError($tmp)) { 
    290319                    return $tmp; 
    291320                } 
     
    310339            } 
    311340 
    312             if (PEAR::isError($body)) { 
     341            if ($this->_isError($body)) { 
    313342                return $body; 
    314343            } 
     
    340369    { 
    341370        if (file_exists($filename) && !is_writable($filename)) { 
    342             $err = PEAR::raiseError('File is not writeable: ' . $filename); 
     371            $err = $this->_raiseError('File is not writeable: ' . $filename); 
    343372            return $err; 
    344373        } 
    345374 
    346375        if (!($fh = fopen($filename, 'ab'))) { 
    347             $err = PEAR::raiseError('Unable to open file: ' . $filename); 
     376            $err = $this->_raiseError('Unable to open file: ' . $filename); 
    348377            return $err; 
    349378        } 
     
    362391        } 
    363392 
    364         return PEAR::isError($res) ? $res : $this->_headers; 
     393        return $this->_isError($res) ? $res : $this->_headers; 
    365394    } 
    366395 
     
    394423 
    395424        if (count($this->_subparts)) { 
    396             $subparts_count = count($this->_subparts); 
    397             for ($i = 0; $i < $subparts_count; ++$i) { 
     425            for ($i = 0; $i < count($this->_subparts); $i++) { 
    398426                fwrite($fh, $f_eol . '--' . $boundary . $eol); 
    399427                $res = $this->_subparts[$i]->_encodePartToFile($fh); 
    400                 if (PEAR::isError($res)) { 
     428                if ($this->_isError($res)) { 
    401429                    return $res; 
    402430                } 
     
    413441                $this->_body_file, $this->_encoding, $fh 
    414442            ); 
    415             if (PEAR::isError($res)) { 
     443            if ($this->_isError($res)) { 
    416444                return $res; 
    417445            } 
     
    429457     *                       as the $params argument for constructor. 
    430458     * 
    431      * @return Mail_mimePart A reference to the part you just added. It is 
     459     * @return Mail_mimePart A reference to the part you just added. In PHP4, it is 
    432460     *                       crucial if using multipart/* in your subparts that 
    433461     *                       you use =& in your script when calling this function, 
     
    437465    function &addSubpart($body, $params) 
    438466    { 
    439         $this->_subparts[] = new Mail_mimePart($body, $params); 
    440         return $this->_subparts[count($this->_subparts) - 1]; 
     467        $this->_subparts[] = $part = new Mail_mimePart($body, $params); 
     468        return $part; 
    441469    } 
    442470 
     
    484512    { 
    485513        if (!is_readable($filename)) { 
    486             $err = PEAR::raiseError('Unable to read file: ' . $filename); 
     514            $err = $this->_raiseError('Unable to read file: ' . $filename); 
    487515            return $err; 
    488516        } 
    489517 
    490518        if (!($fd = fopen($filename, 'rb'))) { 
    491             $err = PEAR::raiseError('Could not open file: ' . $filename); 
     519            $err = $this->_raiseError('Could not open file: ' . $filename); 
    492520            return $err; 
    493521        } 
     
    572600        } 
    573601        */ 
    574         $lines  = preg_split('/\r?\n/', $input); 
     602        $lines  = preg_split("/\r?\n/", $input); 
    575603        $escape = '='; 
    576604        $output = ''; 
     
    583611                $char = $line[$i]; 
    584612                $dec  = ord($char); 
    585                 ++$i; 
     613                $i++; 
    586614 
    587615                if (($dec == 32) && (!isset($line[$i]))) { 
     
    621649 
    622650    /** 
    623      * Encodes the paramater of a header. 
     651     * Encodes the parameter of a header. 
    624652     * 
    625653     * @param string $name      The name of the header-parameter 
     
    641669        // value needs encoding if contains non-ASCII chars or is longer than 78 chars 
    642670        if (!preg_match('#[^\x20-\x7E]#', $value)) { 
    643             $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D' 
    644                 . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#'; 
     671            $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D' 
     672                . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#'; 
    645673            if (!preg_match($token_regexp, $value)) { 
    646674                // token 
     
    664692        // RFC2231: 
    665693        $encValue = preg_replace_callback( 
    666             '/([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])/', 
     694            '/([^\x21\x23\x24\x26\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])/', 
    667695            array($this, '_encodeReplaceCallback'), $value 
    668696        ); 
     
    690718                $value = ''; 
    691719            } 
    692             ++$headCount; 
     720            $headCount++; 
    693721        } 
    694722 
     
    788816            'resent-from', 'resent-to', 'resent-cc', 'resent-bcc', 
    789817            'resent-sender', 'resent-reply-to', 
     818            'mail-reply-to', 'mail-followup-to', 
    790819            'return-receipt-to', 'disposition-notification-to', 
    791820        ); 
     
    809838        if (!empty($separator)) { 
    810839            // Simple e-mail address regexp 
    811             $email_regexp = '(\S+|("[^\r\n"]+"))@\S+'; 
     840            $email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+'; 
    812841 
    813842            $parts = Mail_mimePart::_explodeQuotedString($separator, $value); 
     
    923952        $strlen = strlen($string); 
    924953 
    925         for ($q=$p=$i=0; $i < $strlen; ++$i) { 
     954        for ($q=$p=$i=0; $i < $strlen; $i++) { 
    926955            if ($string[$i] == "\"" 
    927956                && (empty($string[$i-1]) || $string[$i-1] != "\\") 
     
    9851014                $cutpoint = $maxLength; 
    9861015                // RFC 2047 specifies that any split header should 
    987                 // be seperated by a CRLF SPACE. 
     1016                // be separated by a CRLF SPACE. 
    9881017                if ($output) { 
    9891018                    $output .= $eol . ' '; 
     
    10271056 
    10281057                    // RFC 2047 specifies that any split header should 
    1029                     // be seperated by a CRLF SPACE 
     1058                    // be separated by a CRLF SPACE 
    10301059                    if ($output) { 
    10311060                        $output .= $eol . ' '; 
     
    11051134            $prev  = ''; 
    11061135 
    1107             for ($i=1; $i<=$length; ++$i) { 
     1136            for ($i=1; $i<=$length; $i++) { 
    11081137                // See #17311 
    11091138                $chunk = mb_substr($str, $start, $i-$start, $charset); 
     
    11361165            $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/'; 
    11371166 
    1138             for ($i=0; $i<=$length; ++$i) { 
     1167            for ($i=0; $i<=$length; $i++) { 
    11391168                $char = mb_substr($str, $i, 1, $charset); 
    11401169                // RFC recommends underline (instead of =20) in place of the space 
     
    11981227    } 
    11991228 
     1229    /** 
     1230     * PEAR::isError implementation 
     1231     * 
     1232     * @param mixed $data Object 
     1233     * 
     1234     * @return bool True if object is an instance of PEAR_Error 
     1235     * @access private 
     1236     */ 
     1237    function _isError($data) 
     1238    { 
     1239        // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473) 
     1240        if (is_object($data) && is_a($data, 'PEAR_Error')) { 
     1241            return true; 
     1242        } 
     1243 
     1244        return false; 
     1245    } 
     1246 
     1247    /** 
     1248     * PEAR::raiseError implementation 
     1249     * 
     1250     * @param $message A text error message 
     1251     * 
     1252     * @return PEAR_Error Instance of PEAR_Error 
     1253     * @access private 
     1254     */ 
     1255    function _raiseError($message) 
     1256    { 
     1257        // PEAR::raiseError() is not PHP 5.4 compatible 
     1258        return new PEAR_Error($message); 
     1259    } 
     1260 
    12001261} // End of class 
Note: See TracChangeset for help on using the changeset viewer.