Ignore:
Timestamp:
10/10/13 11:39:53 (10 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/mime.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: mime.php 305690 2010-11-23 12:41:00Z alec $ 
     51 * @version   CVS: $Id$ 
    5252 * @link      http://pear.php.net/package/Mail_mime 
    5353 * 
     
    6464 * This package depends on PEAR to raise errors. 
    6565 */ 
    66 require_once dirname(__FILE__).'/../PEAR/PEAR.php'; 
     66require_once 'PEAR.php'; 
    6767 
    6868/** 
     
    7373 * consist of. 
    7474 */ 
    75 //require_once 'Mail/mimePart.php'; 
     75require_once 'Mail/mimePart.php'; 
    7676 
    7777 
     
    246246        } else { 
    247247            $cont = $this->_file2str($data); 
    248             if (PEAR::isError($cont)) { 
     248            if ($this->_isError($cont)) { 
    249249                return $cont; 
    250250            } 
     
    255255            } 
    256256        } 
     257 
    257258        return true; 
    258259    } 
     
    287288        } else { 
    288289            $cont = $this->_file2str($data); 
    289             if (PEAR::isError($cont)) { 
     290            if ($this->_isError($cont)) { 
    290291                return $cont; 
    291292            } 
     
    337338                $bodyfile = $file; 
    338339            } else { 
    339                 if (PEAR::isError($filedata = $this->_file2str($file))) { 
     340                if ($this->_isError($filedata = $this->_file2str($file))) { 
    340341                    return $filedata; 
    341342                } 
     
    348349 
    349350        if (!$content_id) { 
    350             $content_id = md5(uniqid(time())); 
     351            $content_id = preg_replace('/[^0-9a-zA-Z]/', '', uniqid(time(), true)); 
    351352        } 
    352353 
     
    388389     * @param string $h_charset   The character set of the headers e.g. filename 
    389390     *                            If not specified, $charset will be used 
     391     * @param array  $add_headers Additional part headers. Array keys can be in form 
     392     *                            of <header_name>:<parameter_name> 
    390393     * 
    391394     * @return mixed              True on success or PEAR_Error object 
     
    404407        $f_encoding  = null, 
    405408        $description = '', 
    406         $h_charset   = null 
     409        $h_charset   = null, 
     410        $add_headers = array() 
    407411    ) { 
    408412        $bodyfile = null; 
     
    414418                $bodyfile = $file; 
    415419            } else { 
    416                 if (PEAR::isError($filedata = $this->_file2str($file))) { 
     420                if ($this->_isError($filedata = $this->_file2str($file))) { 
    417421                    return $filedata; 
    418422                } 
    419423            } 
    420424            // Force the name the user supplied, otherwise use $file 
    421             $filename = ($name ? $name : $this->_basename($file ));         
     425            $filename = ($name ? $name : $this->_basename($file)); 
    422426        } else { 
    423427            $filedata = $file; 
     
    427431        if (!strlen($filename)) { 
    428432            $msg = "The supplied filename for the attachment can't be empty"; 
    429             $err = PEAR::raiseError($msg); 
    430             return $err; 
    431         } 
    432          
     433            return $this->_raiseError($msg); 
     434        } 
     435 
    433436        $this->_parts[] = array( 
    434437            'body'        => $filedata, 
     
    442445            'disposition' => $disposition, 
    443446            'description' => $description, 
     447            'add_headers' => $add_headers, 
    444448            'name_encoding'     => $n_encoding, 
    445449            'filename_encoding' => $f_encoding, 
     
    458462     * @access private 
    459463     */ 
    460     function &_file2str($file_name) 
     464    function _file2str($file_name) 
    461465    { 
    462466        // Check state of file and raise an error properly 
    463467        if (!file_exists($file_name)) { 
    464             $err = PEAR::raiseError('File not found: ' . $file_name); 
    465             return $err; 
     468            return $this->_raiseError('File not found: ' . $file_name); 
    466469        } 
    467470        if (!is_file($file_name)) { 
    468             $err = PEAR::raiseError('Not a regular file: ' . $file_name); 
    469             return $err; 
     471            return $this->_raiseError('Not a regular file: ' . $file_name); 
    470472        } 
    471473        if (!is_readable($file_name)) { 
    472             $err = PEAR::raiseError('File is not readable: ' . $file_name); 
    473             return $err; 
     474            return $this->_raiseError('File is not readable: ' . $file_name); 
    474475        } 
    475476 
     
    497498     * @access private 
    498499     */ 
    499     function &_addTextPart(&$obj, $text) 
     500    function &_addTextPart(&$obj = null, $text = '') 
    500501    { 
    501502        $params['content_type'] = 'text/plain'; 
     
    506507        if (is_object($obj)) { 
    507508            $ret = $obj->addSubpart($text, $params); 
    508             return $ret; 
    509509        } else { 
    510510            $ret = new Mail_mimePart($text, $params); 
    511             return $ret; 
    512         } 
     511        } 
     512 
     513        return $ret; 
    513514    } 
    514515 
     
    523524     * @access private 
    524525     */ 
    525     function &_addHtmlPart(&$obj) 
     526    function &_addHtmlPart(&$obj = null) 
    526527    { 
    527528        $params['content_type'] = 'text/html'; 
     
    532533        if (is_object($obj)) { 
    533534            $ret = $obj->addSubpart($this->_htmlbody, $params); 
    534             return $ret; 
    535535        } else { 
    536536            $ret = new Mail_mimePart($this->_htmlbody, $params); 
    537             return $ret; 
    538         } 
     537        } 
     538 
     539        return $ret; 
    539540    } 
    540541 
     
    549550    function &_addMixedPart() 
    550551    { 
    551         $params                 = array(); 
    552552        $params['content_type'] = 'multipart/mixed'; 
    553553        $params['eol']          = $this->_build_params['eol']; 
     
    569569     * @access private 
    570570     */ 
    571     function &_addAlternativePart(&$obj) 
     571    function &_addAlternativePart(&$obj = null) 
    572572    { 
    573573        $params['content_type'] = 'multipart/alternative'; 
     
    575575 
    576576        if (is_object($obj)) { 
    577             return $obj->addSubpart('', $params); 
     577            $ret = $obj->addSubpart('', $params); 
    578578        } else { 
    579579            $ret = new Mail_mimePart('', $params); 
    580             return $ret; 
    581         } 
     580        } 
     581 
     582        return $ret; 
    582583    } 
    583584 
     
    593594     * @access private 
    594595     */ 
    595     function &_addRelatedPart(&$obj) 
     596    function &_addRelatedPart(&$obj = null) 
    596597    { 
    597598        $params['content_type'] = 'multipart/related'; 
     
    599600 
    600601        if (is_object($obj)) { 
    601             return $obj->addSubpart('', $params); 
     602            $ret = $obj->addSubpart('', $params); 
    602603        } else { 
    603604            $ret = new Mail_mimePart('', $params); 
    604             return $ret; 
    605         } 
     605        } 
     606 
     607        return $ret; 
    606608    } 
    607609 
     
    679681        if (!empty($value['description'])) { 
    680682            $params['description'] = $value['description']; 
     683        } 
     684        if (is_array($value['add_headers'])) { 
     685            $params['headers'] = $value['add_headers']; 
    681686        } 
    682687 
     
    694699     * @param string $separation The separation between these two parts. 
    695700     * @param array  $params     The Build parameters passed to the 
    696      *                           &get() function. See &get for more info. 
     701     *                           get() function. See get() for more info. 
    697702     * @param array  $headers    The extra headers that should be passed 
    698      *                           to the &headers() function. 
     703     *                           to the headers() method. 
    699704     *                           See that function for more info. 
    700705     * @param bool   $overwrite  Overwrite the existing headers with new. 
     
    712717        $body = $this->get($params); 
    713718 
    714         if (PEAR::isError($body)) { 
     719        if ($this->_isError($body)) { 
    715720            return $body; 
    716721        } 
    717722 
    718         $head = $this->txtHeaders($headers, $overwrite); 
    719         $mail = $head . $separation . $body; 
    720         return $mail; 
     723        return $this->txtHeaders($headers, $overwrite) . $separation . $body; 
    721724    } 
    722725 
     
    726729     *  
    727730     * @param array $params The Build parameters passed to the 
    728      *                      &get() function. See &get for more info. 
     731     *                      get() method. See get() for more info. 
    729732     * 
    730733     * @return mixed The e-mail body or PEAR error object 
     
    742745     * @param string $filename  Output file location 
    743746     * @param array  $params    The Build parameters passed to the 
    744      *                          &get() function. See &get for more info. 
     747     *                          get() method. See get() for more info. 
    745748     * @param array  $headers   The extra headers that should be passed 
    746      *                          to the &headers() function. 
     749     *                          to the headers() function. 
    747750     *                          See that function for more info. 
    748751     * @param bool   $overwrite Overwrite the existing headers with new. 
     
    756759        // Check state of file and raise an error properly 
    757760        if (file_exists($filename) && !is_writable($filename)) { 
    758             $err = PEAR::raiseError('File is not writable: ' . $filename); 
    759             return $err; 
     761            return $this->_raiseError('File is not writable: ' . $filename); 
    760762        } 
    761763 
     
    766768 
    767769        if (!($fh = fopen($filename, 'ab'))) { 
    768             $err = PEAR::raiseError('Unable to open file: ' . $filename); 
    769             return $err; 
     770            return $this->_raiseError('Unable to open file: ' . $filename); 
    770771        } 
    771772 
     
    773774        $head = $this->txtHeaders($headers, $overwrite, true); 
    774775        if (fwrite($fh, $head) === false) { 
    775             $err = PEAR::raiseError('Error writing to file: ' . $filename); 
    776             return $err; 
     776            return $this->_raiseError('Error writing to file: ' . $filename); 
    777777        } 
    778778 
     
    791791    /** 
    792792     * Writes (appends) the complete e-mail body into file. 
    793      *  
     793     * 
    794794     * @param string $filename Output file location 
    795795     * @param array  $params   The Build parameters passed to the 
    796      *                         &get() function. See &get for more info. 
     796     *                         get() method. See get() for more info. 
    797797     * 
    798798     * @return mixed True or PEAR error object 
     
    804804        // Check state of file and raise an error properly 
    805805        if (file_exists($filename) && !is_writable($filename)) { 
    806             $err = PEAR::raiseError('File is not writable: ' . $filename); 
    807             return $err; 
     806            return $this->_raiseError('File is not writable: ' . $filename); 
    808807        } 
    809808 
     
    814813 
    815814        if (!($fh = fopen($filename, 'ab'))) { 
    816             $err = PEAR::raiseError('Unable to open file: ' . $filename); 
    817             return $err; 
     815            return $this->_raiseError('Unable to open file: ' . $filename); 
    818816        } 
    819817 
     
    838836     * @access public 
    839837     */ 
    840     function &get($params = null, $filename = null, $skip_head = false) 
     838    function get($params = null, $filename = null, $skip_head = false) 
    841839    { 
    842840        if (isset($params)) { 
     
    872870                $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3'; 
    873871                $rep[] = 'url(\1cid:' . $value['cid'] . '\1)'; 
    874                               
     872 
    875873                $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody); 
    876874                $this->_html_images[$key]['name'] 
    877875                    = $this->_basename($this->_html_images[$key]['name']); 
    878                              
    879876            } 
    880877        } 
     
    895892        case !$text && !$html && $attachments: 
    896893            $message =& $this->_addMixedPart(); 
    897             $parts_count = count($this->_parts); 
    898             for ($i = 0; $i < $parts_count; ++$i) { 
     894            for ($i = 0; $i < count($this->_parts); $i++) { 
    899895                $this->_addAttachmentPart($message, $this->_parts[$i]); 
    900896            } 
     
    904900            $message =& $this->_addMixedPart(); 
    905901            $this->_addTextPart($message, $this->_txtbody); 
    906             $parts_count = count($this->_parts); 
    907             for ($i = 0; $i < $parts_count; ++$i) { 
     902            for ($i = 0; $i < count($this->_parts); $i++) { 
    908903                $this->_addAttachmentPart($message, $this->_parts[$i]); 
    909904            } 
     
    932927                $ht =& $this->_addRelatedPart($message); 
    933928                $this->_addHtmlPart($ht); 
    934                 $html_images_count = count($this->_html_images); 
    935                 for ($i = 0; $i < $html_images_count; ++$i) { 
     929                for ($i = 0; $i < count($this->_html_images); $i++) { 
    936930                    $this->_addHtmlImagePart($ht, $this->_html_images[$i]); 
    937931                } 
     
    942936                $message =& $this->_addRelatedPart($null); 
    943937                $this->_addHtmlPart($message); 
    944                 $html_images_count = count($this->_html_images); 
    945                 for ($i = 0; $i < $html_images_count; ++$i) { 
     938                for ($i = 0; $i < count($this->_html_images); $i++) { 
    946939                    $this->_addHtmlImagePart($message, $this->_html_images[$i]); 
    947940                } 
     
    962955                $this->_addHtmlPart($message); 
    963956            } 
    964             $html_images_count = count($this->_html_images); 
    965             for ($i = 0; $i < $html_images_count; ++$i) { 
     957            for ($i = 0; $i < count($this->_html_images); $i++) { 
    966958                $this->_addHtmlImagePart($message, $this->_html_images[$i]); 
    967959            } 
     
    978970                $this->_addHtmlPart($message); 
    979971            } 
    980             $parts_count = count($this->_parts); 
    981             for ($i = 0; $i < $parts_count; ++$i) { 
     972            for ($i = 0; $i < count($this->_parts); $i++) { 
    982973                $this->_addAttachmentPart($message, $this->_parts[$i]); 
    983974            } 
    984975            break; 
    985                 /* 
    986                  * Original: 
    987                  * case $html && $attachments && $html_images: 
     976 
     977        case $html && $attachments && $html_images: 
    988978            $message =& $this->_addMixedPart(); 
    989979            if (isset($this->_txtbody)) { 
     
    995985            } 
    996986            $this->_addHtmlPart($rel); 
    997                     $html_images_count = count($this->_html_images); 
    998             for ($i = 0; $i < $html_images_count; ++$i) { 
     987            for ($i = 0; $i < count($this->_html_images); $i++) { 
    999988                $this->_addHtmlImagePart($rel, $this->_html_images[$i]); 
    1000989            } 
    1001                     $parts_count = count($this->_parts); 
    1002             for ($i = 0; $i < $parts_count; ++$i) { 
     990            for ($i = 0; $i < count($this->_parts); $i++) { 
    1003991                $this->_addAttachmentPart($message, $this->_parts[$i]); 
    1004992            } 
    1005                  *      break; 
    1006                  * Alteração feita para que as imagens senjam inseridas junto com os anexos e não em uma alternate part. 
    1007                  * Para compatibilização com a fomra do expresso anexar imagens no copo do e-mail 
    1008                  *  
    1009                  */ 
    1010                 case $html && $attachments && $html_images: 
    1011             $message =& $this->_addMixedPart(); 
    1012             if (isset($this->_txtbody)) { 
    1013                 $alt =& $this->_addAlternativePart($message); 
    1014                 $this->_addTextPart($alt, $this->_txtbody); 
    1015             } else { 
    1016                                 $this->_addHtmlPart($message); 
    1017             } 
    1018  
    1019                         $html_images_count = count($this->_html_images); 
    1020             for ($i = 0; $i < $html_images_count; ++$i) { 
    1021                 $this->_addHtmlImagePart($message, $this->_html_images[$i]); 
    1022             } 
    1023             $parts_count = count($this->_parts); 
    1024             for ($i = 0; $i < $parts_count; ++$i) { 
    1025                 $this->_addAttachmentPart($message, $this->_parts[$i]); 
    1026             } 
    1027993            break; 
    1028                 /* 
    1029                  * Fim da alteração 
    1030                  */      
    1031994 
    1032995        } 
    1033996 
    1034997        if (!isset($message)) { 
    1035             $ret = null; 
    1036             return $ret; 
     998            return null; 
    1037999        } 
    10381000 
     
    10481010            // Append mimePart message headers and body into file 
    10491011            $headers = $message->encodeToFile($filename, $boundary, $skip_head); 
    1050             if (PEAR::isError($headers)) { 
     1012            if ($this->_isError($headers)) { 
    10511013                return $headers; 
    10521014            } 
    10531015            $this->_headers = array_merge($this->_headers, $headers); 
    1054             $ret = null; 
    1055             return $ret; 
     1016            return null; 
    10561017        } else { 
    10571018            $output = $message->encode($boundary, $skip_head); 
    1058             if (PEAR::isError($output)) { 
     1019            if ($this->_isError($output)) { 
    10591020                return $output; 
    10601021            } 
    10611022            $this->_headers = array_merge($this->_headers, $output['headers']); 
    1062             $body = $output['body']; 
    1063             return $body; 
     1023            return $output['body']; 
    10641024        } 
    10651025    } 
     
    10791039     * @access public 
    10801040     */ 
    1081     function &headers($xtra_headers = null, $overwrite = false, $skip_content = false) 
     1041    function headers($xtra_headers = null, $overwrite = false, $skip_content = false) 
    10821042    { 
    10831043        // Add mime version header 
     
    11771137 
    11781138        // add parameters 
    1179         $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D' 
    1180             . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#'; 
     1139        $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D' 
     1140            . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#'; 
    11811141        if (is_array($params)) { 
    11821142            foreach ($params as $name => $value) { 
     
    13541314    function encodeHeader($name, $value, $charset, $encoding) 
    13551315    { 
    1356         return Mail_mimePart::encodeHeader( 
     1316        $mime_part = new Mail_mimePart; 
     1317        return $mime_part->encodeHeader( 
    13571318            $name, $value, $charset, $encoding, $this->_build_params['eol'] 
    13581319        ); 
     
    15001461    } 
    15011462 
     1463    /** 
     1464     * PEAR::isError implementation 
     1465     * 
     1466     * @param mixed $data Object 
     1467     * 
     1468     * @return bool True if object is an instance of PEAR_Error 
     1469     * @access private 
     1470     */ 
     1471    function _isError($data) 
     1472    { 
     1473        // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473) 
     1474        if (is_object($data) && is_a($data, 'PEAR_Error')) { 
     1475            return true; 
     1476        } 
     1477 
     1478        return false; 
     1479    } 
     1480 
     1481    /** 
     1482     * PEAR::raiseError implementation 
     1483     * 
     1484     * @param $message A text error message 
     1485     * 
     1486     * @return PEAR_Error Instance of PEAR_Error 
     1487     * @access private 
     1488     */ 
     1489    function _raiseError($message) 
     1490    { 
     1491        // PEAR::raiseError() is not PHP 5.4 compatible 
     1492        return new PEAR_Error($message); 
     1493    } 
     1494 
    15021495} // End of class 
Note: See TracChangeset for help on using the changeset viewer.