Index: sandbox/2.5.1-evolucao/phpgwapi/inc/class.db.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/class.db.inc.php	(revision 8234)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/class.db.inc.php	(revision 8235)
@@ -209,5 +209,5 @@
 					$GLOBALS[ 'phpgw' ]->ADOdb = NULL;
 				}
-				if (!is_object($GLOBALS['phpgw']->ADOdb) ||	// we have no connection so far
+				if (!isset($GLOBALS[ 'phpgw' ]->ADOdb) /*!is_object($GLOBALS['phpgw']->ADOdb)*/ ||	// we have no connection so far
 					(isset($GLOBALS['phpgw']->db) && is_object($GLOBALS['phpgw']->db) &&	// we connect to a different db, then the global one
 						($this->Type != $GLOBALS['phpgw']->db->Type ||
@@ -217,5 +217,5 @@
 						$this->Port != $GLOBALS['phpgw']->db->Port)))
 				{
-					if (!is_object($GLOBALS['phpgw']->ADOdb))	// use the global object to store the connection
+					if (isset($GLOBALS[ 'phpgw' ]->ADOdb)/*!is_object($GLOBALS['phpgw']->ADOdb)*/)	// use the global object to store the connection
 					{
 						$this->Link_ID = &$GLOBALS['phpgw']->ADOdb;
Index: sandbox/2.5.1-evolucao/header.inc.php.template
===================================================================
--- sandbox/2.5.1-evolucao/header.inc.php.template	(revision 8142)
+++ sandbox/2.5.1-evolucao/header.inc.php.template	(revision 8235)
@@ -19,6 +19,6 @@
 	\**************************************************************************/
 	ob_start();
-	define('PHPGW_SERVER_ROOT','{SERVER_ROOT}');
-	define('PHPGW_INCLUDE_ROOT','{INCLUDE_ROOT}');
+	if (!defined('PHPGW_SERVER_ROOT')) define('PHPGW_SERVER_ROOT','{SERVER_ROOT}');
+	if (!defined('PHPGW_INCLUDE_ROOT')) define('PHPGW_INCLUDE_ROOT','{INCLUDE_ROOT}');
 	$GLOBALS['phpgw_info']['server']['header_admin_user'] = '{HEADER_ADMIN_USER}';
 	$GLOBALS['phpgw_info']['server']['header_admin_password'] = '{HEADER_ADMIN_PASSWORD}';
@@ -114,5 +114,5 @@
 	* Do not edit these lines                                                  *
 	\**************************************************************************/
-	define('PHPGW_API_INC',PHPGW_INCLUDE_ROOT.'/phpgwapi/inc');
+	if (!defined('PHPGW_API_INC')) define('PHPGW_API_INC',PHPGW_INCLUDE_ROOT.'/phpgwapi/inc');
 	include(PHPGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php');
 	$GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] = $setup_info['phpgwapi']['version'];
Index: sandbox/2.5.1-evolucao/library/mime/mimeDecode.php
===================================================================
--- sandbox/2.5.1-evolucao/library/mime/mimeDecode.php	(revision 7673)
+++ sandbox/2.5.1-evolucao/library/mime/mimeDecode.php	(revision 8235)
@@ -63,5 +63,5 @@
  * This package depends on PEAR to raise errors.
  */
-//require_once 'PEAR.php';
+require_once 'PEAR.php';
 
 
@@ -89,5 +89,5 @@
  * @link       http://pear.php.net/package/Mail_mime
  */
-class Mail_mimeDecode 
+class Mail_mimeDecode extends PEAR
 {
     /**
@@ -194,5 +194,5 @@
      * @return object Decoded results
      * @access public
-     */ 
+     */
     function decode($params = null)
     {
@@ -326,6 +326,5 @@
 
                     $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
-                    $parts_count = count($parts);
-                    for ($i = 0; $i < $parts_count; ++$i) {
+                    for ($i = 0; $i < count($parts); $i++) {
                         list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
                         $part = $this->_decode($part_header, $part_body, $default_ctype);
@@ -337,8 +336,8 @@
 
                 case 'message/rfc822':
-                    if ($this->_rfc822_bodies) {
-                            $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
-                            $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body);
-                    }
+					if ($this->_rfc822_bodies) {
+						$encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
+						$return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body);
+					}
                     $obj = new Mail_mimeDecode($body);
                     $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies,
@@ -348,10 +347,4 @@
                     break;
 
-                case 'message/delivery-status':
-                    if(!isset($content_transfer_encoding['value']))
-                        $content_transfer_encoding['value'] = '7bit';
-                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;
-                     break;
-                     
                 default:
                     if(!isset($content_transfer_encoding['value']))
@@ -387,6 +380,6 @@
                 $return[$prepend . $mime_number] = &$structure;
             }
-            $structure_parts_count = count($structure->parts);
-            for ($i = 0; $i < $structure_parts_count; ++$i) {
+            for ($i = 0; $i < count($structure->parts); $i++) {
+
             
                 if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
@@ -522,5 +515,5 @@
             $escaped = false;
             if ($c == '\\') {
-                ++$i;
+                $i++;
                 if ($i == $l-1) { // end of string.
                     break;
@@ -536,5 +529,5 @@
                     $val = '';
                     $key = trim($key);
-                    ++$i;
+                    $i++;
                     continue;
                 }
@@ -548,5 +541,5 @@
                 }
                 $key .= $c;
-                ++$i;
+                $i++;
                 continue;
             }
@@ -557,5 +550,5 @@
                 // not in quote yet.
                 if ((!strlen($val) || $lq !== false) && $c == ' ' ||  $c == "\t") {
-                    ++$i;
+                    $i++;
                     continue; // skip leading spaces after '=' or after '"'
                 }
@@ -566,5 +559,5 @@
                     // but we will handle it as a merged part of the string..
                     $val = !strlen(trim($val)) ? '' : trim($val);
-                    ++$i;
+                    $i++;
                     continue;
                 }
@@ -594,10 +587,10 @@
                     $key = '';
                     $lq = false;
-                    ++$i;
+                    $i++;
                     continue;
                 }
 
                 $val .= $c;
-                ++$i;
+                $i++;
                 continue;
             }
@@ -609,5 +602,5 @@
                 $lq = $q;
                 $q = false;
-                ++$i;
+                $i++;
                 continue;
             }
@@ -615,5 +608,5 @@
             // normal char inside of quoted string..
             $val.= $c;
-            ++$i;
+            $i++;
         }
         
@@ -669,5 +662,5 @@
 
         $len = count($tmp) -1;
-        for ($i = 1; $i < $len; ++$i) {
+        for ($i = 1; $i < $len; $i++) {
             if (strlen(trim($tmp[$i]))) {
                 $parts[] = $tmp[$i];
@@ -789,10 +782,8 @@
     function &uudecode($input)
     {
-
         // Find all uuencoded sections
         preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);
 
-        $matches_count = count($matches[3]);
-        for ($j = 0; $j < $matches_count; ++$j) {
+        for ($j = 0; $j < count($matches[3]); $j++) {
 
             $str      = $matches[3][$j];
@@ -801,8 +792,8 @@
 
             $file = '';
-            $str = preg_split('/\r?\n/', trim($str));
+            $str = preg_split("/\r?\n/", trim($str));
             $strlen = count($str);
 
-            for ($i = 0; $i < $strlen; ++$i) {
+            for ($i = 0; $i < $strlen; $i++) {
                 $pos = 1;
                 $d = 0;
@@ -945,6 +936,5 @@
             // Multiple headers with this name
             if (is_array($headers[$hdr_name])) {
-                $hdr_value_count = count($hdr_value);
-                for ($i = 0; $i < $hdr_value_count; ++$i) {
+                for ($i = 0; $i < count($hdr_value); $i++) {
                     $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);
                 }
@@ -957,6 +947,5 @@
 
         if (!empty($input->parts)) {
-            $parts_count = count($input->parts);
-            for ($i = 0; $i < $parts_count; ++$i) {
+            for ($i = 0; $i < count($input->parts); $i++) {
                 $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .
                            Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .
Index: sandbox/2.5.1-evolucao/library/mime/mimePart.php
===================================================================
--- sandbox/2.5.1-evolucao/library/mime/mimePart.php	(revision 7673)
+++ sandbox/2.5.1-evolucao/library/mime/mimePart.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: mimePart.php 314695 2011-08-10 07:18:07Z alec $
+ * @version   CVS: $Id$
  * @link      http://pear.php.net/package/Mail_mime
  */
@@ -131,4 +131,5 @@
     */
     var $_eol = "\r\n";
+
 
     /**
@@ -156,4 +157,6 @@
     *                         If not set, 'charset' will be used
     *     eol               - End of line sequence. Default: "\r\n"
+    *     headers           - Hash array with additional part headers. Array keys can be
+    *                         in form of <header_name>:<parameter_name>
     *     body_file         - Location of file with part's body (instead of $body)
     *
@@ -166,4 +169,9 @@
         } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat.
             $this->_eol = MAIL_MIMEPART_CRLF;
+        }
+
+        // Additional part headers
+        if (!empty($params['headers']) && is_array($params['headers'])) {
+            $headers = $params['headers'];
         }
 
@@ -216,11 +224,15 @@
             }
         }
+
+        // header values encoding parameters
+        $h_charset  = !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII';
+        $h_language = !empty($params['language']) ? $params['language'] : null;
+        $h_encoding = !empty($params['name_encoding']) ? $params['name_encoding'] : null;
+
+
         if (!empty($params['filename'])) {
             $headers['Content-Type'] .= ';' . $this->_eol;
             $headers['Content-Type'] .= $this->_buildHeaderParam(
-                'name', $params['filename'],
-                !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
-                !empty($params['language']) ? $params['language'] : null,
-                !empty($params['name_encoding']) ? $params['name_encoding'] : null
+                'name', $params['filename'], $h_charset, $h_language, $h_encoding
             );
         }
@@ -232,19 +244,37 @@
                 $headers['Content-Disposition'] .= ';' . $this->_eol;
                 $headers['Content-Disposition'] .= $this->_buildHeaderParam(
-                    'filename', $params['filename'],
-                    !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
-                    !empty($params['language']) ? $params['language'] : null,
+                    'filename', $params['filename'], $h_charset, $h_language,
                     !empty($params['filename_encoding']) ? $params['filename_encoding'] : null
                 );
             }
+
+            // add attachment size
+            $size = $this->_body_file ? filesize($this->_body_file) : strlen($body);
+            if ($size) {
+                $headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size;
+            }
         }
 
         if (!empty($params['description'])) {
             $headers['Content-Description'] = $this->encodeHeader(
-                'Content-Description', $params['description'],
-                !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
-                !empty($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable',
+                'Content-Description', $params['description'], $h_charset, $h_encoding,
                 $this->_eol
             );
+        }
+
+        // Search and add existing headers' parameters
+        foreach ($headers as $key => $value) {
+            $items = explode(':', $key);
+            if (count($items) == 2) {
+                $header = $items[0];
+                $param  = $items[1];
+                if (isset($headers[$header])) {
+                    $headers[$header] .= ';' . $this->_eol;
+                }
+                $headers[$header] .= $this->_buildHeaderParam(
+                    $param, $value, $h_charset, $h_language, $h_encoding
+                );
+                unset($headers[$key]);
+            }
         }
 
@@ -283,9 +313,8 @@
             $encoded['body'] = ''; 
 
-            $subparts_count = count($this->_subparts);
-            for ($i = 0; $i < $subparts_count; ++$i) {
+            for ($i = 0; $i < count($this->_subparts); $i++) {
                 $encoded['body'] .= '--' . $boundary . $eol;
                 $tmp = $this->_subparts[$i]->encode();
-                if (PEAR::isError($tmp)) {
+                if ($this->_isError($tmp)) {
                     return $tmp;
                 }
@@ -310,5 +339,5 @@
             }
 
-            if (PEAR::isError($body)) {
+            if ($this->_isError($body)) {
                 return $body;
             }
@@ -340,10 +369,10 @@
     {
         if (file_exists($filename) && !is_writable($filename)) {
-            $err = PEAR::raiseError('File is not writeable: ' . $filename);
+            $err = $this->_raiseError('File is not writeable: ' . $filename);
             return $err;
         }
 
         if (!($fh = fopen($filename, 'ab'))) {
-            $err = PEAR::raiseError('Unable to open file: ' . $filename);
+            $err = $this->_raiseError('Unable to open file: ' . $filename);
             return $err;
         }
@@ -362,5 +391,5 @@
         }
 
-        return PEAR::isError($res) ? $res : $this->_headers;
+        return $this->_isError($res) ? $res : $this->_headers;
     }
 
@@ -394,9 +423,8 @@
 
         if (count($this->_subparts)) {
-            $subparts_count = count($this->_subparts);
-            for ($i = 0; $i < $subparts_count; ++$i) {
+            for ($i = 0; $i < count($this->_subparts); $i++) {
                 fwrite($fh, $f_eol . '--' . $boundary . $eol);
                 $res = $this->_subparts[$i]->_encodePartToFile($fh);
-                if (PEAR::isError($res)) {
+                if ($this->_isError($res)) {
                     return $res;
                 }
@@ -413,5 +441,5 @@
                 $this->_body_file, $this->_encoding, $fh
             );
-            if (PEAR::isError($res)) {
+            if ($this->_isError($res)) {
                 return $res;
             }
@@ -429,5 +457,5 @@
      *                       as the $params argument for constructor.
      *
-     * @return Mail_mimePart A reference to the part you just added. It is
+     * @return Mail_mimePart A reference to the part you just added. In PHP4, it is
      *                       crucial if using multipart/* in your subparts that
      *                       you use =& in your script when calling this function,
@@ -437,6 +465,6 @@
     function &addSubpart($body, $params)
     {
-        $this->_subparts[] = new Mail_mimePart($body, $params);
-        return $this->_subparts[count($this->_subparts) - 1];
+        $this->_subparts[] = $part = new Mail_mimePart($body, $params);
+        return $part;
     }
 
@@ -484,10 +512,10 @@
     {
         if (!is_readable($filename)) {
-            $err = PEAR::raiseError('Unable to read file: ' . $filename);
+            $err = $this->_raiseError('Unable to read file: ' . $filename);
             return $err;
         }
 
         if (!($fd = fopen($filename, 'rb'))) {
-            $err = PEAR::raiseError('Could not open file: ' . $filename);
+            $err = $this->_raiseError('Could not open file: ' . $filename);
             return $err;
         }
@@ -572,5 +600,5 @@
         }
         */
-        $lines  = preg_split('/\r?\n/', $input);
+        $lines  = preg_split("/\r?\n/", $input);
         $escape = '=';
         $output = '';
@@ -583,5 +611,5 @@
                 $char = $line[$i];
                 $dec  = ord($char);
-                ++$i;
+                $i++;
 
                 if (($dec == 32) && (!isset($line[$i]))) {
@@ -621,5 +649,5 @@
 
     /**
-     * Encodes the paramater of a header.
+     * Encodes the parameter of a header.
      *
      * @param string $name      The name of the header-parameter
@@ -641,6 +669,6 @@
         // value needs encoding if contains non-ASCII chars or is longer than 78 chars
         if (!preg_match('#[^\x20-\x7E]#', $value)) {
-            $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 (!preg_match($token_regexp, $value)) {
                 // token
@@ -664,5 +692,5 @@
         // RFC2231:
         $encValue = preg_replace_callback(
-            '/([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])/',
+            '/([^\x21\x23\x24\x26\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])/',
             array($this, '_encodeReplaceCallback'), $value
         );
@@ -690,5 +718,5 @@
                 $value = '';
             }
-            ++$headCount;
+            $headCount++;
         }
 
@@ -788,4 +816,5 @@
             'resent-from', 'resent-to', 'resent-cc', 'resent-bcc',
             'resent-sender', 'resent-reply-to',
+            'mail-reply-to', 'mail-followup-to',
             'return-receipt-to', 'disposition-notification-to',
         );
@@ -809,5 +838,5 @@
         if (!empty($separator)) {
             // Simple e-mail address regexp
-            $email_regexp = '(\S+|("[^\r\n"]+"))@\S+';
+            $email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+';
 
             $parts = Mail_mimePart::_explodeQuotedString($separator, $value);
@@ -923,5 +952,5 @@
         $strlen = strlen($string);
 
-        for ($q=$p=$i=0; $i < $strlen; ++$i) {
+        for ($q=$p=$i=0; $i < $strlen; $i++) {
             if ($string[$i] == "\""
                 && (empty($string[$i-1]) || $string[$i-1] != "\\")
@@ -985,5 +1014,5 @@
                 $cutpoint = $maxLength;
                 // RFC 2047 specifies that any split header should
-                // be seperated by a CRLF SPACE.
+                // be separated by a CRLF SPACE.
                 if ($output) {
                     $output .= $eol . ' ';
@@ -1027,5 +1056,5 @@
 
                     // RFC 2047 specifies that any split header should
-                    // be seperated by a CRLF SPACE
+                    // be separated by a CRLF SPACE
                     if ($output) {
                         $output .= $eol . ' ';
@@ -1105,5 +1134,5 @@
             $prev  = '';
 
-            for ($i=1; $i<=$length; ++$i) {
+            for ($i=1; $i<=$length; $i++) {
                 // See #17311
                 $chunk = mb_substr($str, $start, $i-$start, $charset);
@@ -1136,5 +1165,5 @@
             $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
 
-            for ($i=0; $i<=$length; ++$i) {
+            for ($i=0; $i<=$length; $i++) {
                 $char = mb_substr($str, $i, 1, $charset);
                 // RFC recommends underline (instead of =20) in place of the space
@@ -1198,3 +1227,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
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
Index: sandbox/2.5.1-evolucao/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 8234)
+++ sandbox/2.5.1-evolucao/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 8235)
@@ -10,6 +10,6 @@
 		\**************************************************************************/ 
 		
-define('PHPGW_INCLUDE_ROOT','../');
-define('PHPGW_API_INC','../phpgwapi/inc');	
+if (!defined('PHPGW_INCLUDE_ROOT')) define('PHPGW_INCLUDE_ROOT','../');
+if (!defined('PHPGW_API_INC')) define('PHPGW_API_INC','../phpgwapi/inc');	
 include_once(PHPGW_API_INC.'/class.common.inc.php');
 include_once('class.functions.inc.php');
@@ -178,5 +178,5 @@
 			$info['accountStatus'] = 'active';
 		}
-		if ($params['phpgwAccountVisible'] == 'on')
+		if (isset($params['phpgwAccountVisible']) && $params['phpgwAccountVisible'] == 'on')
 		{
 			$info['phpgwAccountVisible'] = '-1';
@@ -556,5 +556,5 @@
 				$info['accountStatus'] = 'active';
 			}
-			if ($params['phpgwAccountVisible'] == 'on')
+			if ( isset($params['phpgwAccountVisible']) && ($params['phpgwAccountVisible'] == 'on') )
 			{
 				$info['phpgwAccountVisible'] = '-1';
@@ -2718,5 +2718,5 @@
 			$return['status'] = 'true';
 			$return['accountStatus']		= $entrie[0]['accountstatus'][0];
-			$return['phpgwAccountVisible']	= $entrie[0]['phpgwaccountvisible'][0];
+			$return['phpgwAccountVisible']	= isset($entrie[0]['phpgwaccountvisible']) ? $entrie[0]['phpgwaccountvisible'][0] : '';
 			$return['cn']					= utf8_decode($entrie[0]['cn'][0]);
 			$return['mail']					= $entrie[0]['mail'][0];
@@ -2734,4 +2734,5 @@
 				}
 				natcasesort($a_cn);
+				$return['owners'] = '';
 				foreach($a_cn as $uidnumber => $cn)
 				{
