Index: sandbox/2.5.1-evolucao/library/mime/mime.php
===================================================================
--- sandbox/2.5.1-evolucao/library/mime/mime.php	(revision 7673)
+++ sandbox/2.5.1-evolucao/library/mime/mime.php	(revision 8235)
@@ -49,5 +49,5 @@
  * @copyright 2003-2006 PEAR <pear-group@php.net>
  * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version   CVS: $Id: mime.php 305690 2010-11-23 12:41:00Z alec $
+ * @version   CVS: $Id$
  * @link      http://pear.php.net/package/Mail_mime
  *
@@ -64,5 +64,5 @@
  * This package depends on PEAR to raise errors.
  */
-require_once dirname(__FILE__).'/../PEAR/PEAR.php';
+require_once 'PEAR.php';
 
 /**
@@ -73,5 +73,5 @@
  * consist of.
  */
-//require_once 'Mail/mimePart.php';
+require_once 'Mail/mimePart.php';
 
 
@@ -246,5 +246,5 @@
         } else {
             $cont = $this->_file2str($data);
-            if (PEAR::isError($cont)) {
+            if ($this->_isError($cont)) {
                 return $cont;
             }
@@ -255,4 +255,5 @@
             }
         }
+
         return true;
     }
@@ -287,5 +288,5 @@
         } else {
             $cont = $this->_file2str($data);
-            if (PEAR::isError($cont)) {
+            if ($this->_isError($cont)) {
                 return $cont;
             }
@@ -337,5 +338,5 @@
                 $bodyfile = $file;
             } else {
-                if (PEAR::isError($filedata = $this->_file2str($file))) {
+                if ($this->_isError($filedata = $this->_file2str($file))) {
                     return $filedata;
                 }
@@ -348,5 +349,5 @@
 
         if (!$content_id) {
-            $content_id = md5(uniqid(time()));
+            $content_id = preg_replace('/[^0-9a-zA-Z]/', '', uniqid(time(), true));
         }
 
@@ -388,4 +389,6 @@
      * @param string $h_charset   The character set of the headers e.g. filename
      *                            If not specified, $charset will be used
+     * @param array  $add_headers Additional part headers. Array keys can be in form
+     *                            of <header_name>:<parameter_name>
      *
      * @return mixed              True on success or PEAR_Error object
@@ -404,5 +407,6 @@
         $f_encoding  = null,
         $description = '',
-        $h_charset   = null
+        $h_charset   = null,
+        $add_headers = array()
     ) {
         $bodyfile = null;
@@ -414,10 +418,10 @@
                 $bodyfile = $file;
             } else {
-                if (PEAR::isError($filedata = $this->_file2str($file))) {
+                if ($this->_isError($filedata = $this->_file2str($file))) {
                     return $filedata;
                 }
             }
             // Force the name the user supplied, otherwise use $file
-            $filename = ($name ? $name : $this->_basename($file ));	   
+            $filename = ($name ? $name : $this->_basename($file));
         } else {
             $filedata = $file;
@@ -427,8 +431,7 @@
         if (!strlen($filename)) {
             $msg = "The supplied filename for the attachment can't be empty";
-            $err = PEAR::raiseError($msg);
-            return $err;
-        }
-	
+            return $this->_raiseError($msg);
+        }
+
         $this->_parts[] = array(
             'body'        => $filedata,
@@ -442,4 +445,5 @@
             'disposition' => $disposition,
             'description' => $description,
+            'add_headers' => $add_headers,
             'name_encoding'     => $n_encoding,
             'filename_encoding' => $f_encoding,
@@ -458,18 +462,15 @@
      * @access private
      */
-    function &_file2str($file_name)
+    function _file2str($file_name)
     {
         // Check state of file and raise an error properly
         if (!file_exists($file_name)) {
-            $err = PEAR::raiseError('File not found: ' . $file_name);
-            return $err;
+            return $this->_raiseError('File not found: ' . $file_name);
         }
         if (!is_file($file_name)) {
-            $err = PEAR::raiseError('Not a regular file: ' . $file_name);
-            return $err;
+            return $this->_raiseError('Not a regular file: ' . $file_name);
         }
         if (!is_readable($file_name)) {
-            $err = PEAR::raiseError('File is not readable: ' . $file_name);
-            return $err;
+            return $this->_raiseError('File is not readable: ' . $file_name);
         }
 
@@ -497,5 +498,5 @@
      * @access private
      */
-    function &_addTextPart(&$obj, $text)
+    function &_addTextPart(&$obj = null, $text = '')
     {
         $params['content_type'] = 'text/plain';
@@ -506,9 +507,9 @@
         if (is_object($obj)) {
             $ret = $obj->addSubpart($text, $params);
-            return $ret;
         } else {
             $ret = new Mail_mimePart($text, $params);
-            return $ret;
-        }
+        }
+
+        return $ret;
     }
 
@@ -523,5 +524,5 @@
      * @access private
      */
-    function &_addHtmlPart(&$obj)
+    function &_addHtmlPart(&$obj = null)
     {
         $params['content_type'] = 'text/html';
@@ -532,9 +533,9 @@
         if (is_object($obj)) {
             $ret = $obj->addSubpart($this->_htmlbody, $params);
-            return $ret;
         } else {
             $ret = new Mail_mimePart($this->_htmlbody, $params);
-            return $ret;
-        }
+        }
+
+        return $ret;
     }
 
@@ -549,5 +550,4 @@
     function &_addMixedPart()
     {
-        $params                 = array();
         $params['content_type'] = 'multipart/mixed';
         $params['eol']          = $this->_build_params['eol'];
@@ -569,5 +569,5 @@
      * @access private
      */
-    function &_addAlternativePart(&$obj)
+    function &_addAlternativePart(&$obj = null)
     {
         $params['content_type'] = 'multipart/alternative';
@@ -575,9 +575,10 @@
 
         if (is_object($obj)) {
-            return $obj->addSubpart('', $params);
+            $ret = $obj->addSubpart('', $params);
         } else {
             $ret = new Mail_mimePart('', $params);
-            return $ret;
-        }
+        }
+
+        return $ret;
     }
 
@@ -593,5 +594,5 @@
      * @access private
      */
-    function &_addRelatedPart(&$obj)
+    function &_addRelatedPart(&$obj = null)
     {
         $params['content_type'] = 'multipart/related';
@@ -599,9 +600,10 @@
 
         if (is_object($obj)) {
-            return $obj->addSubpart('', $params);
+            $ret = $obj->addSubpart('', $params);
         } else {
             $ret = new Mail_mimePart('', $params);
-            return $ret;
-        }
+        }
+
+        return $ret;
     }
 
@@ -679,4 +681,7 @@
         if (!empty($value['description'])) {
             $params['description'] = $value['description'];
+        }
+        if (is_array($value['add_headers'])) {
+            $params['headers'] = $value['add_headers'];
         }
 
@@ -694,7 +699,7 @@
      * @param string $separation The separation between these two parts.
      * @param array  $params     The Build parameters passed to the
-     *                           &get() function. See &get for more info.
+     *                           get() function. See get() for more info.
      * @param array  $headers    The extra headers that should be passed
-     *                           to the &headers() function.
+     *                           to the headers() method.
      *                           See that function for more info.
      * @param bool   $overwrite  Overwrite the existing headers with new.
@@ -712,11 +717,9 @@
         $body = $this->get($params);
 
-        if (PEAR::isError($body)) {
+        if ($this->_isError($body)) {
             return $body;
         }
 
-        $head = $this->txtHeaders($headers, $overwrite);
-        $mail = $head . $separation . $body;
-        return $mail;
+        return $this->txtHeaders($headers, $overwrite) . $separation . $body;
     }
 
@@ -726,5 +729,5 @@
      * 
      * @param array $params The Build parameters passed to the
-     *                      &get() function. See &get for more info.
+     *                      get() method. See get() for more info.
      *
      * @return mixed The e-mail body or PEAR error object
@@ -742,7 +745,7 @@
      * @param string $filename  Output file location
      * @param array  $params    The Build parameters passed to the
-     *                          &get() function. See &get for more info.
+     *                          get() method. See get() for more info.
      * @param array  $headers   The extra headers that should be passed
-     *                          to the &headers() function.
+     *                          to the headers() function.
      *                          See that function for more info.
      * @param bool   $overwrite Overwrite the existing headers with new.
@@ -756,6 +759,5 @@
         // Check state of file and raise an error properly
         if (file_exists($filename) && !is_writable($filename)) {
-            $err = PEAR::raiseError('File is not writable: ' . $filename);
-            return $err;
+            return $this->_raiseError('File is not writable: ' . $filename);
         }
 
@@ -766,6 +768,5 @@
 
         if (!($fh = fopen($filename, 'ab'))) {
-            $err = PEAR::raiseError('Unable to open file: ' . $filename);
-            return $err;
+            return $this->_raiseError('Unable to open file: ' . $filename);
         }
 
@@ -773,6 +774,5 @@
         $head = $this->txtHeaders($headers, $overwrite, true);
         if (fwrite($fh, $head) === false) {
-            $err = PEAR::raiseError('Error writing to file: ' . $filename);
-            return $err;
+            return $this->_raiseError('Error writing to file: ' . $filename);
         }
 
@@ -791,8 +791,8 @@
     /**
      * Writes (appends) the complete e-mail body into file.
-     * 
+     *
      * @param string $filename Output file location
      * @param array  $params   The Build parameters passed to the
-     *                         &get() function. See &get for more info.
+     *                         get() method. See get() for more info.
      *
      * @return mixed True or PEAR error object
@@ -804,6 +804,5 @@
         // Check state of file and raise an error properly
         if (file_exists($filename) && !is_writable($filename)) {
-            $err = PEAR::raiseError('File is not writable: ' . $filename);
-            return $err;
+            return $this->_raiseError('File is not writable: ' . $filename);
         }
 
@@ -814,6 +813,5 @@
 
         if (!($fh = fopen($filename, 'ab'))) {
-            $err = PEAR::raiseError('Unable to open file: ' . $filename);
-            return $err;
+            return $this->_raiseError('Unable to open file: ' . $filename);
         }
 
@@ -838,5 +836,5 @@
      * @access public
      */
-    function &get($params = null, $filename = null, $skip_head = false)
+    function get($params = null, $filename = null, $skip_head = false)
     {
         if (isset($params)) {
@@ -872,9 +870,8 @@
                 $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';
                 $rep[] = 'url(\1cid:' . $value['cid'] . '\1)';
-                             
+
                 $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
                 $this->_html_images[$key]['name']
                     = $this->_basename($this->_html_images[$key]['name']);
-                            
             }
         }
@@ -895,6 +892,5 @@
         case !$text && !$html && $attachments:
             $message =& $this->_addMixedPart();
-            $parts_count = count($this->_parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
+            for ($i = 0; $i < count($this->_parts); $i++) {
                 $this->_addAttachmentPart($message, $this->_parts[$i]);
             }
@@ -904,6 +900,5 @@
             $message =& $this->_addMixedPart();
             $this->_addTextPart($message, $this->_txtbody);
-            $parts_count = count($this->_parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
+            for ($i = 0; $i < count($this->_parts); $i++) {
                 $this->_addAttachmentPart($message, $this->_parts[$i]);
             }
@@ -932,6 +927,5 @@
                 $ht =& $this->_addRelatedPart($message);
                 $this->_addHtmlPart($ht);
-                $html_images_count = count($this->_html_images);
-                for ($i = 0; $i < $html_images_count; ++$i) {
+                for ($i = 0; $i < count($this->_html_images); $i++) {
                     $this->_addHtmlImagePart($ht, $this->_html_images[$i]);
                 }
@@ -942,6 +936,5 @@
                 $message =& $this->_addRelatedPart($null);
                 $this->_addHtmlPart($message);
-                $html_images_count = count($this->_html_images);
-                for ($i = 0; $i < $html_images_count; ++$i) {
+                for ($i = 0; $i < count($this->_html_images); $i++) {
                     $this->_addHtmlImagePart($message, $this->_html_images[$i]);
                 }
@@ -962,6 +955,5 @@
                 $this->_addHtmlPart($message);
             }
-            $html_images_count = count($this->_html_images);
-            for ($i = 0; $i < $html_images_count; ++$i) {
+            for ($i = 0; $i < count($this->_html_images); $i++) {
                 $this->_addHtmlImagePart($message, $this->_html_images[$i]);
             }
@@ -978,12 +970,10 @@
                 $this->_addHtmlPart($message);
             }
-            $parts_count = count($this->_parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
+            for ($i = 0; $i < count($this->_parts); $i++) {
                 $this->_addAttachmentPart($message, $this->_parts[$i]);
             }
             break;
-		/*
-		 * Original:
-		 * case $html && $attachments && $html_images:
+
+        case $html && $attachments && $html_images:
             $message =& $this->_addMixedPart();
             if (isset($this->_txtbody)) {
@@ -995,44 +985,16 @@
             }
             $this->_addHtmlPart($rel);
-		    $html_images_count = count($this->_html_images);
-            for ($i = 0; $i < $html_images_count; ++$i) {
+            for ($i = 0; $i < count($this->_html_images); $i++) {
                 $this->_addHtmlImagePart($rel, $this->_html_images[$i]);
             }
-		    $parts_count = count($this->_parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
+            for ($i = 0; $i < count($this->_parts); $i++) {
                 $this->_addAttachmentPart($message, $this->_parts[$i]);
             }
-		 *	break;
-		 * Alteração feita para que as imagens senjam inseridas junto com os anexos e não em uma alternate part.
-		 * Para compatibilização com a fomra do expresso anexar imagens no copo do e-mail
-		 * 
-		 */
-		case $html && $attachments && $html_images:
-            $message =& $this->_addMixedPart();
-            if (isset($this->_txtbody)) {
-                $alt =& $this->_addAlternativePart($message);
-                $this->_addTextPart($alt, $this->_txtbody);
-            } else {
-				$this->_addHtmlPart($message);
-            }
-
-			$html_images_count = count($this->_html_images);
-            for ($i = 0; $i < $html_images_count; ++$i) {
-                $this->_addHtmlImagePart($message, $this->_html_images[$i]);
-            }
-            $parts_count = count($this->_parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
-                $this->_addAttachmentPart($message, $this->_parts[$i]);
-            }
             break;
-		/*
-		 * Fim da alteração
-		 */	
 
         }
 
         if (!isset($message)) {
-            $ret = null;
-            return $ret;
+            return null;
         }
 
@@ -1048,18 +1010,16 @@
             // Append mimePart message headers and body into file
             $headers = $message->encodeToFile($filename, $boundary, $skip_head);
-            if (PEAR::isError($headers)) {
+            if ($this->_isError($headers)) {
                 return $headers;
             }
             $this->_headers = array_merge($this->_headers, $headers);
-            $ret = null;
-            return $ret;
+            return null;
         } else {
             $output = $message->encode($boundary, $skip_head);
-            if (PEAR::isError($output)) {
+            if ($this->_isError($output)) {
                 return $output;
             }
             $this->_headers = array_merge($this->_headers, $output['headers']);
-            $body = $output['body'];
-            return $body;
+            return $output['body'];
         }
     }
@@ -1079,5 +1039,5 @@
      * @access public
      */
-    function &headers($xtra_headers = null, $overwrite = false, $skip_content = false)
+    function headers($xtra_headers = null, $overwrite = false, $skip_content = false)
     {
         // Add mime version header
@@ -1177,6 +1137,6 @@
 
         // add parameters
-        $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
-            . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
+        $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D'
+            . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#';
         if (is_array($params)) {
             foreach ($params as $name => $value) {
@@ -1354,5 +1314,6 @@
     function encodeHeader($name, $value, $charset, $encoding)
     {
-        return Mail_mimePart::encodeHeader(
+        $mime_part = new Mail_mimePart;
+        return $mime_part->encodeHeader(
             $name, $value, $charset, $encoding, $this->_build_params['eol']
         );
@@ -1500,3 +1461,35 @@
     }
 
+    /**
+     * PEAR::isError implementation
+     *
+     * @param mixed $data Object
+     *
+     * @return bool True if object is an instance of PEAR_Error
+     * @access private
+     */
+    function _isError($data)
+    {
+        // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473)
+        if (is_object($data) && is_a($data, 'PEAR_Error')) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * PEAR::raiseError implementation
+     *
+     * @param $message A text error message
+     *
+     * @return PEAR_Error Instance of PEAR_Error
+     * @access private
+     */
+    function _raiseError($message)
+    {
+        // PEAR::raiseError() is not PHP 5.4 compatible
+        return new PEAR_Error($message);
+    }
+
 } // End of class
