Index: trunk/services/class.memCache.php
===================================================================
--- trunk/services/class.memCache.php	(revision 5359)
+++ trunk/services/class.memCache.php	(revision 5359)
@@ -0,0 +1,58 @@
+<?php
+/**
+*
+* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+*
+*  This program is free software; you can redistribute it and/or
+*  modify it under the terms of the GNU General Public License
+*  as published by the Free Software Foundation; either version 2
+*  of the License, or (at your option) any later version.
+*
+*  This program is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  You should have received a copy of the GNU General Public License
+*  along with this program; if not, write to the Free Software
+*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
+*
+* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,
+* 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at
+* e-mail address prognus@prognus.com.br.
+*
+*
+* @package    MemCacheService
+* @license    http://www.gnu.org/copyleft/gpl.html GPL
+* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+* @author     Cristiano Corrêa Schmidt
+* @sponsor    Caixa Econômica Federal
+* @version    1.0
+* @since      2.4.0
+*/
+class MemCacheService extends Memcache
+{
+    var $expiration = 86400;
+
+    /**
+    * Adiciona objeto ao cache, com tratamento de erros no compress.
+    *
+    * @license    http://www.gnu.org/copyleft/gpl.html GPL
+    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+    * @sponsor    Caixa Econômica Federal
+    * @author     Cristiano Corrêa Schmidt
+    * @return     bool
+    * @access     public
+    */
+    public function set( $key, $value, $expiration = false)
+    {
+        return  parent::set($key, 
+                            $value,
+                            ( is_bool( $value ) || is_int( $value ) || is_float( $value ) ) ? false : MEMCACHE_COMPRESSED,
+                            ( $expiration !== false ) ? $expiration : $this->expiration );
+    }
+    
+}
+
+ServiceLocator::register( 'memCache', new MemCacheService() );
+
Index: trunk/setup/templates/default/config.tpl
===================================================================
--- trunk/setup/templates/default/config.tpl	(revision 392)
+++ trunk/setup/templates/default/config.tpl	(revision 5359)
@@ -108,4 +108,14 @@
     <td>{lang_Enter_your_HTTP_proxy_server_password}:</td>
     <td><input name="newsettings[httpproxy_server_password]" value="{value_httpproxy_server_password}"></td>
+   </tr>
+      
+   <tr class="row_off">
+    <td>{lang_Enter_your_MemCache_server}:</td>
+    <td><input name="newsettings[server_memcache]" value="{value_server_memcache}"></td>
+   </tr>
+   
+   <tr class="row_off">
+    <td>{lang_Enter_your_MemCache_server_port}:</td>
+    <td><input name="newsettings[port_server_memcache]" value="{value_port_server_memcache}"></td>
    </tr>
 
Index: trunk/expressoMail1_2/templates/default/config.tpl
===================================================================
--- trunk/expressoMail1_2/templates/default/config.tpl	(revision 5346)
+++ trunk/expressoMail1_2/templates/default/config.tpl	(revision 5359)
@@ -185,4 +185,33 @@
 	   </tr> 
 
+  <tr bgcolor="{th_bg}"> 
+    <td colspan="2"> 
+        &nbsp; 
+    </td> 
+  </tr>
+  
+  <tr bgcolor="{row_on}"> 
+    <td colspan="2"> 
+        <label style="font-weight:bold;">MemCache</label> 
+    </td> 
+  </tr>
+  
+    <tr bgcolor="{row_off}">
+        <td>{lang_Using_cache_for_list_of_messages}</td>
+        <td>
+            <select id="useCache" name="newsettings[expressoMail_enable_memcache]">
+                <option value="false" {selected_expressoMail_enable_memcache_false}>{lang_No}</option>
+                <option value="true" {selected_expressoMail_enable_memcache_true}>{lang_Yes}</option>
+            </select>
+        </td>
+    </tr>
+    <tr bgcolor="{row_on}">
+        <td>{lang_Maximum_time_for_the_list_of_messages_keep_in_cache} </td>
+        <td>
+            <input size="5" name="newsettings[expressoMail_time_memcache]" value="{value_expressoMail_time_memcache}">
+            <span>s</span> 
+        </td>
+    </tr>
+
 <!-- END body -->
 <!-- BEGIN footer -->
Index: trunk/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 5350)
+++ trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 5359)
@@ -740,2 +740,4 @@
 Error marking messages.	expressoMail1_2	pt-br	Erro ao marcar as mensagens.
 Error importing.	expressoMail1_2	pt-br	Erro ao Importar.
+Using cache for list of messages	admin	pt-br	Tempo maximo para listagem de mensagems ficar no cache
+Maximum time for the list of messages keep in cache	admin	pt-br	Tempo maximo para listagem de mensagems ficar no cache
Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5346)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5359)
@@ -20,4 +20,5 @@
 	var $ldap;
 	var $mbox;
+        var $mboxFolder;
 	var $imap_port;
 	var $has_cid;
@@ -29,10 +30,12 @@
 	var $rawMessage;
 	var $folders;
-
-	
+        var $cache = false;
+        var $useCache = false;
+        var $expirationCache = false;
+        
 	function imap_functions (){
 		$this->init();
 	} 
-	
+        
 	function init(){
 		$this->foldersLimit    = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] ?  $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] : 20000; //Limit of folders (mailboxes) user can see
@@ -53,12 +56,15 @@
 		$this->folders['trash']   =  empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ? 'Trash' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];
 
+                if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache']) && $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache'] === 'true')
+                    $this->useCache = true;
+                 
+                if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) && trim($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) != '')
+                    $this->expirationCache = $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache'];
+                
 		if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
-		{
 			$this->imap_options = '/tls/novalidate-cert';
-		}
 		else
-		{
 			$this->imap_options = '/notls/novalidate-cert';
-		}
+		      
 	}
 	
@@ -68,31 +74,21 @@
 	
 	// BEGIN of functions.
-	function open_mbox($folder = False,$force_die=true)
-	{
-		$folder = mb_convert_encoding($folder, "UTF7-IMAP",'UTF-8, ISO-8859-1, UTF7-IMAP');
-		if (is_resource($this->mbox))
-                {
-                     if ($force_die)
-                     {
-                        @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error()))));
-                     }
-                     else
-                        {
-                            @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder);
-                        }
-                }
+	function open_mbox( $folder = false, $force_die = true)
+	{
+            $this->mboxFolder =  mb_convert_encoding($folder, 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP');
+            $url = '{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$this->mboxFolder;
+            
+            if (is_resource($this->mbox))
+                 if ($force_die)
+                    imap_reopen($this->mbox, $url ) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error()))));
+                 else
+                    imap_reopen($this->mbox, $url );
+            else
+                if($force_die)
+                    $this->mbox = imap_open( $url , $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error()))));
                 else
-                    {
-                        if($force_die)
-                        {
-                            $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error()))));
-                        }
-                        else
-                            {
-                                $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password);
-                            }
-                        
-                    }
-                    return $this->mbox;
+                    $this->mbox = imap_open( $url , $this->username, $this->password);
+
+            return $this->mbox;
 	 }
 
@@ -127,47 +123,44 @@
 	function get_range_msgs2($params)
 	{ 
-		// Free others requests
-                session_write_close();
-                $folder = $params['folder'];
-		$msg_range_begin = $params['msg_range_begin'];
-		$msg_range_end = $params['msg_range_end'];
-                $sort_box_type		= isset($params['sort_box_type']) ? $params['sort_box_type'] : '';
-                $sort_box_reverse	= isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : '';
-                $search_box_type	= (isset($params['search_box_type']) && $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" )? $params['search_box_type'] : false;
-
-                if( !$this->mbox || !is_resource( $this->mbox ) )
-			$this->mbox = $this->open_mbox($folder);
-
-        $return = array();
-
-	$return['folder'] = $folder;
-
-        //Para enviar o offset entre o timezone definido pelo usuário e GMT
-        $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
-
-        if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") {
-			$msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, "UTF7-IMAP", "ISO_8859-1" ) ,SA_ALL);
-
-
-			$return['tot_unseen'] = $search_box_type == "SEEN" ? 0 : $msgs_info->unseen;
-
-			$sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end);
-
-			$num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages);
-
-			$i = 0;
-			if(is_array($sort_array_msg)){
-				foreach($sort_array_msg as $msg_number => $value)
-				{
-					$temp = $this->get_info_head_msg($msg_number);
-					$temp['msg_sample'] = $this->get_msg_sample($msg_number,$folder);
-					if(!$temp)
-						return false;
-
-					$return[$i] = $temp;
-					$i++;
-				}
-			}
-			$return['num_msgs'] =  $num_msgs;
+            // Free others requests
+            session_write_close();
+            $folder = $params['folder'];
+            $msg_range_begin = $params['msg_range_begin'];
+            $msg_range_end = $params['msg_range_end'];
+            $sort_box_type		= isset($params['sort_box_type']) ? $params['sort_box_type'] : '';
+            $sort_box_reverse	= isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : '';
+            $search_box_type	= (isset($params['search_box_type']) && $params['search_box_type'] != 'ALL' && $params['search_box_type'] != '' )? $params['search_box_type'] : false;
+
+            if( !$this->mbox || !is_resource( $this->mbox ) )
+                $this->mbox = $this->open_mbox($folder);
+
+            $return = array();
+            $return['folder'] = $folder;
+            //Para enviar o offset entre o timezone definido pelo usuário e GMT
+            $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
+
+            if(!$search_box_type || $search_box_type == 'UNSEEN' || $search_box_type == 'SEEN') {
+                    $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, 'UTF7-IMAP', 'ISO_8859-1' ) ,SA_ALL);
+
+                    $return['tot_unseen'] = ($search_box_type == 'SEEN') ? 0 : $msgs_info->unseen;
+
+                    $sort_array_msg = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end);
+
+                    $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages);
+
+                    $i = 0;
+                    if(is_array($sort_array_msg)){
+                            foreach($sort_array_msg as $msg_number => $value)
+                            {
+                                $sample = false;
+                                if( (isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] === '1')) &&
+                                    (isset($this->prefs['preview_msg_tip']    ) || ($this->prefs['preview_msg_tip']     === '1')) )
+                                    $sample = true;
+                                            
+                                    $return[$i] = $this->get_info_head_msg( $msg_number , $sample ) ;
+                                    $i++;
+                            }
+                    }
+                    $return['num_msgs'] =  $num_msgs;
 		}
 		else {
@@ -200,126 +193,141 @@
                 return $return;
     }
-
-	function get_info_head_msg($msg_number)
-	{
-		$head_array = array();
-		include_once("class.imap_attachment.inc.php");
-
-		$imap_attachment = new imap_attachment();
-		//if ($this->prefs['use_important_flag'] )
-		//{
-			/*Como eu preciso do atributo Importance para saber se o email é
-			 * importante ou não, uso abaixo a função imap_fetchheader e busco
-			 * o atributo importance nela. Isso faz com que eu acesse o cabeçalho
-			 * duas vezes e de duas formas diferentes, mas em contrapartida, eu
-			 * não preciso reimplementar o método utilizando o fetchheader.
-			 * Como as mensagens são renderizadas em um número pequeno por vez,
-			 * não parece ter perda considerável de performance.
-			 */
-
-			$tempHeader = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number));
-			$flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance);
-                //}
-                // Reimplementado código para identificação dos e-mails assinados e cifrados
-                // no método getMessageType(). Mário César Kolling <mario.kolling@serpro.gov.br>
-                $head_array['ContentType'] = $this->getMessageType($msg_number, $tempHeader);
-                $head_array['Importance'] = $flag==0?"Normal":$importance[1];
-
-		$header = $this->get_header($msg_number);
-		if (!is_object($header))
-			return false;
-		$head_array['Recent'] = $header->Recent;
-		$head_array['Unseen'] = $header->Unseen;
-		if($header->Answered =='A' && $header->Draft == 'X'){
-			$head_array['Forwarded'] = 'F';
-		}
-		else {
-			$head_array['Answered']	= $header->Answered;
-			$head_array['Draft']	= $header->Draft;
-		}
-		$head_array['Deleted'] = $header->Deleted;
-		$head_array['Flagged'] = $header->Flagged;
-		$head_array['msg_number'] = $msg_number;
-		$head_array['udate'] = $header->udate;
-		$head_array['offsetToGMT'] = $this->functions->CalculateDateOffset();
-
-		$msgTimestamp = $header->udate + $head_array['offsetToGMT'];
-		$head_array['timestamp'] = $msgTimestamp;
-		
-		$date_msg = gmdate("d/m/Y",$msgTimestamp);
-//		if (date("d/m/Y") == $date_msg)
-//			$return['udate'] = $header->udate;
-//		else
-
-		if (date("d/m/Y") == $date_msg) //no dia
-		{
-			$head_array['smalldate'] = gmdate("H:i",$msgTimestamp);
+    
+        /**
+        *  Decodifica uma string no formato mime RFC2047
+        *
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Cristiano Corrêa Schmidt
+        * @param      string $string string no formato mime RFC2047
+        * @return     string
+        * @access     public
+        */
+        static function decodeMimeString( $string )
+        {
+          return preg_replace_callback( '/\=\?([^\?]*)\?([qb])\?([^\?]*)\?=/i' ,array( self , 'decodeMimeStringCallback'), $string);
+        }
+      
+        /**
+        *  Decodifica os tokens encontrados na função decodeMimeString
+        *
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Cristiano Corrêa Schmidt
+        * @param      array $mathes array retornado pelo preg_replace_callback da função decodeMimeString
+        * @return     string
+        * @access     public
+        */
+        static function decodeMimeStringCallback( $mathes )
+        {
+           $str = (strtolower($mathes[2]) == 'q') ?  quoted_printable_decode(str_replace('_','=20',$mathes[3])) : base64_decode( $mathes[3]) ;
+           return ( strtoupper($mathes[1]) == 'UTF-8' ) ? mb_convert_encoding(  $str , 'ISO-8859-1' , 'UTF-8') : $str;
+        }
+        
+        /**
+        *  Formata um mailObject para um array com name e email
+        *
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Cristiano Corrêa Schmidt
+        * @return     bool
+        * @access     public
+        */
+        static function formatMailObject( $obj )
+        {
+            $return = array();
+            $return['email'] = self::decodeMimeString($obj->mailbox) . (isset( $obj->host ) ? '@'. $obj->host : '');
+            $return['name'] = ( isset( $obj->personal ) && trim($obj->personal) !== '' ) ? self::decodeMimeString($obj->personal) :  $return['email'];
+            return $return;
+        }
+        
+        /**
+        *   Retorna informações do cabeçario da mensagem e um preview caso appendSample = true
+        *   Utiliza memCache caso esta preferencia esteja ativada.
+        *
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Cristiano Corrêa Schmidt
+        * @return     bool
+        * @access     public
+        */
+	function get_info_head_msg( $msg_number , $appendSample = false )
+	{             
+            $return = false;
+            $cached = false;
+            if( $this->useCache === true )
+            {
+                if( $this->cache === false )
+                {
+                    $this->cache = ServiceLocator::getService( 'memCache' ); //Serviço Cache
+                    $this->cache->connect( $_SESSION['phpgw_info']['expressomail']['server']['server_memcache'] , $_SESSION['phpgw_info']['expressomail']['server']['port_server_memcache'] );
                 }
-                else
-                {
-			$head_array['smalldate'] = gmdate("d/m/Y",$msgTimestamp);
-                }
-
-		if(isset($header->from))
-		$from = $header->from;
-		$head_array['from'] = array();
-		$head_array['from']['name'] = ( isset( $from[0]->personal ) ) ? $this->decode_string($from[0]->personal) : NULL;
-		if(isset($from))
-		$head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host;
-		else
-			$head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@";
-		if(!$head_array['from']['name'] || trim($head_array['from']['name']) === '' )
-			$head_array['from']['name'] = $head_array['from']['email'];
-		if(isset($header->to))
-		$to = $header->to;
-		$head_array['to'] = array();
-		if(isset($to[1]) && isset($to[1]->host) && $to[1]->host == ".SYNTAX-ERROR.") { //E-mails que não possuem o campo "para", vêm com o recipiente preenchido, porém com um recipiente a mais alegando erro de sintaxe.
-			$head_array['to']['name'] = $head_array['to']['email'] = NULL;
-		}
-		else {
-			$tmp = ( isset( $to[0]->personal ) ) ? imap_mime_header_decode($to[0]->personal) : NULL;
-			$head_array['to']['name'] = ( isset( $tmp[0]->text ) ) ? $this->decode_string($this->decode_string($tmp[0]->text)) : NULL;
-			$head_array['to']['email'] = ( isset( $to[0]->mailbox ) ) ? ( $this->decode_string($to[0]->mailbox) . "@" . ( ( isset( $to[0]->host ) ) ? $to[0]->host : '' ) ) : NULL;
-			if(!$head_array['to']['name'])
-				$head_array['to']['name'] = $head_array['to']['email'];
-		}
-		$cc = null;
-		$cco = null;
-		if(isset($header->cc)){
-		$cc = $header->cc;
-		}
-		if(isset($header->bcc)){
-		$cco = $header->bcc;
-		}
-		if ( ($cc) && (!$head_array['to']['name']) ){
-			$head_array['to']['name'] = ( isset( $cc[0]->personal ) ) ? $this->decode_string($cc[0]->personal) : NULL;
-			$head_array['to']['email'] = $this->decode_string($cc[0]->mailbox) . "@" . $cc[0]->host;
-			if(!$head_array['to']['name']){
-				$head_array['to']['name'] = $head_array['from']['name'];
-				//$head_array['to']['email'] = $head_array['from']['email'];
-			}
-		}
-		else if ( ($cco) && (!$head_array['to']['name']) ){
-			$head_array['to']['name'] = ( isset( $cco[0]->personal ) ) ? $this->decode_string($cco[0]->personal) : NULL;
-			$head_array['to']['email'] = $this->decode_string($cco[0]->mailbox) . "@" . $cco[0]->host;
-			if(!$head_array['to']['name'])
-				$head_array['to']['name'] = $head_array['from']['name'];
-		}
-		$head_array['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : '';
-		if($head_array['subject'] == "" || $head_array['subject'] == '' || $head_array['subject'] == null ){
-			$head_array['subject'] = $this->functions->getLang("(no subject)   ");
-		}
-	
-		if($head_array['to']['name'] == 'undisclosed-recipients@' || $head_array['to']['name'] == '@'){
-			$head_array['to']['name'] = $head_array['from']['name'];
-			$head_array['to']['email'] = $head_array['from']['email'];
-		}
-
-		$head_array['Size'] = $header->Size;
-
-		$head_array['attachment'] = array();
-		$head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);
-
-		return $head_array;
+                
+                if( $return = $this->cache->get( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number ))
+                   $cached = true;   
+            }
+            
+            $header = imap_headerinfo($this->mbox, imap_msgno( $this->mbox , $msg_number )); //Resgata o objeto Header da mensagem , nescessario mesmo com o cache pois as flags podem ser atualizadas por outro cliente de email
+            $return['Recent'] = $header->Recent;
+            $return['Unseen'] = $header->Unseen;
+            $return['Deleted'] = $header->Deleted;
+            $return['Flagged'] = $header->Flagged;
+            if($header->Answered =='A' && $header->Draft == 'X')
+                $return['Forwarded'] = 'F';
+            else 
+            {
+                $return['Answered']	= $header->Answered;
+                $return['Draft']	= $header->Draft;
+            }    
+            
+            if( $cached === true ) //Caso a mensagem ja tenha vindo do cache da o return
+            {
+                if($appendSample !== false && !isset($return['msg_sample'])) //verifica o msg_sample caso seja alterada a preferencia e não esteja em cache carregar
+                   $return['msg_sample'] = $this->get_msg_sample($msg_number);
+               
+                return $return;
+            }
+            
+            $importance = array();
+            $mimeHeader = imap_fetchheader( $this->mbox, $msg_number , FT_UID ); //Resgata o Mime Header da mensagem
+            $mimeBody = imap_body( $this->mbox, $msg_number  , FT_UID  ); //Resgata o Mime Body da mensagem
+            $offsetToGMT =  $this->functions->CalculateDateOffset();
+            $return['ContentType'] = $this->getMessageType( $msg_number , $mimeHeader , $mimeBody ); 
+            $return['Importance'] = ( preg_match('/importance *: *(.*)\r/i', $mimeHeader , $importance) === 0 ) ? 'Normal' : $importance[1];
+            $return['msg_number'] = $msg_number;
+            $return['udate'] = $header->udate;
+            $return['offsetToGMT'] = $offsetToGMT;
+            $return['timestamp'] = $header->udate + $return['offsetToGMT'];
+            $return['smalldate'] = (date('d/m/Y') == gmdate( 'd/m/Y', $return['timestamp'] )) ?  gmdate("H:i", $return['timestamp'] ) : gmdate("d/m/Y", $return['timestamp'] );
+            $return['Size'] = $header->Size;
+            $return['from'] =  (isset( $header->from[0] )) ? self::formatMailObject( $header->from[0] ) : array( 'name' => '' , 'email' => '');
+            $return['subject']  =  ( isset($header->subject) && trim($header->subject) !== '' ) ?  self::decodeMimeString($header->subject) : $this->functions->getLang('(no subject)   ');
+            $return['attachment'] = ( preg_match('/((Content-Disposition:(.)*(\r\n filename=|filename=))|(Content-Type:(.)*(\r\n name=|name=)))/', $mimeBody) ) ? '1' : '0'; //Verifica se a anexos na mensagem
+            $return['reply_toaddress'] = isset($header->reply_toaddress) ? $header->reply_toaddress : '';
+            $return['flag'] = $header->Unseen.$header->Recent.$header->Flagged.$header->Draft.$header->Answered.$header->Deleted.( $return['attachment'] === '1' ? 'T': '' );
+
+            if( isset( $header->to[0] ))
+                $return['to'] = self::formatMailObject( $header->to[0] );
+            else if( isset( $header->cc[0] ))
+                $return['to'] = self::formatMailObject( $header->cc[0] );
+            else if( isset( $header->bcc[0] ))
+                $return['to'] = self::formatMailObject( $header->bcc[0] );
+            else
+                $return['to'] = array( 'name' => '' , 'email' => '');
+                 
+            if($return['to']['name'] == 'undisclosed-recipients@' || $return['to']['name'] == '@')
+                $return['to'] = $return['from'];
+ 
+            if($appendSample !== false)
+                $return['msg_sample'] = $this->get_msg_sample($msg_number);
+            
+            if( $this->useCache === true )
+                $this->cache->set( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number , $return , $this->expirationCache);
+            
+            return $return;
 	}
 
@@ -880,15 +888,8 @@
 	function get_msg_sample($msg_number)
 	{
-        $content = '';
-
-		$return = ""; 
-		if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) &&
-			(!isset($this->prefs['preview_msg_tip']    ) || ($this->prefs['preview_msg_tip']     != "1")) )
-		{ 
-			$return['body'] = ""; 
-			return $return; 
-		} 
-
-		include_once("class.message_components.inc.php");
+                $content = '';
+		$return = array(); 
+
+		include_once('class.message_components.inc.php');
 		$msg = new message_components($this->mbox);
 		$msg->fetch_structure($msg_number);  
@@ -896,30 +897,28 @@
 		if(!isset($msg->structure[$msg_number]->parts))
 		{
-			$content = '';
-			if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html")
-			{
-				$content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]);
-			}
+                    $content = '';
+                    if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html")
+                        $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]);
 		}
 		else
 		{
-			foreach($msg->pid[$msg_number] as $values => $msg_part)
-			{
-
-				$file_type = strtolower($msg->file_type[$msg_number][$values]);
-				if($file_type == "text/plain" || $file_type == "text/html") {
-					$content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]);
-					break;
-				}
-			}
-		}
-      
+                    foreach($msg->pid[$msg_number] as $values => $msg_part)
+                    {
+                        $file_type = strtolower($msg->file_type[$msg_number][$values]);
+                        if($file_type == "text/plain" || $file_type == "text/html") {
+                                $content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]);
+                                break;
+                        }
+                    }
+		}
+   
 		$tags_replace = array("<br>","<br/>","<br />");
 		$content = str_replace($tags_replace," ", nl2br($content));
 		$content = $this->html2txt($content);	
 		$content != "" ? $return['body'] = " - " . $content: $return['body'] = "";
-                $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1'));
+                $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1' , 'UTF-8,ISO-8859-1'));
 		return $return;
 	}
+        
     function html2txt($document){
         $search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
@@ -1265,5 +1264,5 @@
 		if($return['toaddress2'] == 'undisclosed-recipients@, @'){
 			$return['toaddress2'] = $this->functions->getLang('without destination');
-		}
+		}       
 		return $return;
 	}
@@ -1276,16 +1275,16 @@
 	* @author     luka8088 <luka8088@gmail.com> 
 	*/	
- 	function utf8_to_html ($data) 
-	{
- 	    return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '$this->_utf8_to_html("\\1")', $data); 
+ 	static function utf8_to_html ($data) 
+	{
+ 	    return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", 'self::_utf8_to_html("\\1")', $data); 
  	} 
 
- 	function _utf8_to_html ($data) 
-		{ 
+ 	static function _utf8_to_html ($data) 
+	{ 
  	    $ret = 0; 
 		foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) 
 			$ret += (ord($v) % 128) * pow(64, $k); 
  		    return html_entity_decode("&#$ret;" , ENT_QUOTES); 
-		} 
+	} 
  	//------------------------------------------------------------------------------// 
 
@@ -1298,21 +1297,19 @@
 		*/
         function decodeMailPart($part, $encode, $html = true)
-		{
+	{
             switch (strtolower($encode))
-			{
+            {
                 case 'iso-8859-1':
                     return $part;
                     break;
-
                 case 'utf-8':
-                    if ($html) return  $this->utf8_to_html($part);
+                    if ($html) return  self::utf8_to_html($part);
                     else       return  utf8_decode ($part);
                     break;
-
                 default:
                     return mb_convert_encoding($part, 'iso-8859-1');
-					break;
-				}
-			}
+                    break;
+            }
+	}
 
 	
@@ -1864,4 +1861,6 @@
                         
             foreach ($regs_found as $block_found) {
+                if(!isset($block_found[0])) continue;
+                
                 $n_start = strpos($block_found[0], '>') + 1;
                 $n_length = strrpos($block_found[0], '<') - $n_start;
@@ -2141,7 +2140,5 @@
 		$msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end);
 		$msgs_in_the_server = array_keys($msgs_in_the_server);
-
 		$num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox));
-
 		$dif = ($params['msg_range_end'] - $params['msg_range_begin']) +1;
 		if(!count($msgs_in_the_server)){
@@ -2192,107 +2189,27 @@
 		foreach($msgs_to_exec as $msg_number)
 		{
-			/*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns
-			* atributos do cabeçalho. Como eu preciso do atributo Importance
-			* para saber se o email é importante ou não, uso abaixo a função
-			* imap_fetchheader e busco o atributo importance nela para passar
-			* para as funções ajax. Isso faz com que eu acesse o cabeçalho
-			* duas vezes e de duas formas diferentes, mas em contrapartida, eu
-			* não preciso reimplementar o método utilizando o fetchheader.
-			*/
-    
-			$tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number));
-			$flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance);
-			$return[$i]['Importance'] = $flag==0?"Normal":$importance[1];
-
-			$msg_sample = $this->get_msg_sample($msg_number);
-			$return[$i]['msg_sample'] = $msg_sample;
-
-			$header = $this->get_header($msg_number);
-			if (!is_object($header))
-				continue;
-
-			$return[$i]['msg_number']	= $msg_number;
+                    $sample = false;
+                    if( (isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] === '1')) && (isset($this->prefs['preview_msg_tip']    ) || ($this->prefs['preview_msg_tip']     === '1')) )
+                          $sample = true;
+                    
+                    $return[$i] = $this->get_info_head_msg($msg_number , $sample );
+                    
+                    //get the next msg number to append this msg in the view in a correct place
+                    $msg_key_position = array_search($msg_number, $msgs_in_the_server);
 			
-			//get the next msg number to append this msg in the view in a correct place
-			$msg_key_position = array_search($msg_number, $msgs_in_the_server);
-			
-			$return[$i]['msg_key_position'] = $msg_key_position;
-			if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false)
-				$return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1];
-			else
-				$return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position];
-
-			$return[$i]['msg_folder']	= $folder;
-			// Atribui o tipo (normal, signature ou cipher) ao campo Content-Type
-			$return[$i]['ContentType']  = $this->getMessageType($msg_number, $tempHeader);
-			$return[$i]['Recent']		= $header->Recent;
-			$return[$i]['Unseen']		= $header->Unseen;
-			$return[$i]['Answered']		= $header->Answered;
-			$return[$i]['Deleted']		= $header->Deleted;
-			$return[$i]['Draft']		= $header->Draft;
-			$return[$i]['Flagged']		= $header->Flagged;
-
-			$return[$i]['udate'] = $header->udate;
-		
-			$from = $header->from;
-			$return[$i]['from'] = array();
-			$tmp = imap_mime_header_decode($from[0]->personal);
-			$return[$i]['from']['name'] = $tmp[0]->text;
-			$return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host;
-			//$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>';
-			if(!$return[$i]['from']['name'] || trim($return[$i]['from']['name']) === '')
-				$return[$i]['from']['name'] = $return[$i]['from']['email'];
-
-			/*$toaddress = imap_mime_header_decode($header->toaddress);
-			$return[$i]['toaddress'] = '';
-			foreach ($toaddress as $tmp)
-				$return[$i]['toaddress'] .= $tmp->text;*/
-			$to = $header->to;
-			$return[$i]['to'] = array();
-			if(isset($to[0]->personal))
-			$tmp = imap_mime_header_decode($to[0]->personal);
-			if(trim($return[$i]['to']['name']) === '')
-				$return[$i]['to']['name'] = $to[0]->mailbox . "@" . $to[0]->host;
-			else
-			$return[$i]['to']['name'] = $tmp[0]->text;
-			$return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host;
-			$return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>';
-			if(isset($header->cc))
-			$cc = $header->cc;
-
-			if ( isset($cc) && (!$return[$i]['to']['name'] || $return[$i]['to']['name'] == '@') ){
-				$return[$i]['to']['name'] =  $cc[0]->personal;
-				$return[$i]['to']['email'] = $cc[0]->mailbox . "@" . $cc[0]->host;
-			}
-                        $return[$i]['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : '';
-                        if($return[$i]['subject'] == "" || $return[$i]['subject'] == '' || $return[$i]['subject'] == null ){
-				$return[$i]['subject'] = $this->functions->getLang("(no subject)   ");
-			}
-			$return[$i]['Size'] = $header->Size;
-			$return[$i]['reply_toaddress'] = $header->reply_toaddress;
-
-			if($return[$i]['to']['email'] == '@' || $return[$i]['to']['email'] =='undisclosed-recipients@' || $return[$i]['to']['name'] =='undisclosed-recipients@'
-				|| $return[$i]['to']['name'] == null){
-				$return[$i]['to']['email'] = $return[$i]['from']['email'];
-				$return[$i]['to']['name'] = $return[$i]['from']['name'];
-				$return[$i]['to']['full'] = $return[$i]['reply_toaddress'];
-			}
-			
-			$return[$i]['attachment'] = array();
-			if (!isset($imap_attachment))
-			{
-				include_once("class.imap_attachment.inc.php");
-				$imap_attachment = new imap_attachment();
-			}
-			$return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);
-			$i++;
+                    $return[$i]['msg_key_position'] = $msg_key_position;
+                    if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false)
+                        $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1];
+                    else
+                        $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position];
+
+                    $return[$i]['msg_folder'] = $folder;
+                    $i++;
 		}
 		$return['quota'] = $this->get_quota(array('folder_id' => $folder));
 		$return['sort_box_type'] = $params['sort_box_type'];
                 if(!$this->mbox || !is_resource($this->mbox))
-                {
                     $this->open_mbox($folder);
-                }
-
+                
 		$return['msgs_to_delete'] = $msg_to_delete;
                 $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
@@ -2311,17 +2228,16 @@
      * @return Retorna o tipo da mensagem (normal, signature, cipher).
      */
-    function getMessageType($msg_number, $headers = false){
+    function getMessageType($msg_number, $headers = false , &$body = false){
             include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php");
             $contentType = "normal";
-            if (!$headers){
-                $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number));
-            }
-            
-            if (preg_match("/pkcs7-signature/i", $headers) == 1){
+          
+            if (!$headers)
+                $headers = imap_fetchheader($this->mbox, $msg_number, FT_UID);
+
+            if (preg_match("/pkcs7-signature/i", $headers) == 1)
                 $contentType = "signature";
-            } else if (preg_match("/pkcs7-mime/i", $headers) == 1){
-                $contentType = testa_p7m( imap_body($this->mbox, imap_msgno($this->mbox, $msg_number)) );
-            }
-
+             else if (preg_match("/pkcs7-mime/i", $headers) == 1)
+                $contentType = testa_p7m(  $body ? $body :  imap_body($this->mbox, $msg_number , FT_UID )) ;
+ 
             return $contentType;
     }
@@ -3360,5 +3276,5 @@
 			if ($offsetEnd >  $num_msgs) {$offsetEnd = $num_msgs;}
 			$slice_array = true;
-
+                 
 			for ($i=$num_msgs; $i>0; $i--)
 			{
@@ -4431,5 +4347,5 @@
 	function search_msg( $params = false )
 	{
-		$mbox_stream = "";
+	
 		
 		if(strpos($params['condition'],"#")===false)
@@ -4495,9 +4411,7 @@
 					$folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" );
 				
-				if(!is_resource($mbox_stream))
-					$mbox_stream = $this->open_mbox($name_box);
-				else
-					imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box);
-				
+	
+			        $this->open_mbox($name_box);
+
 				if (preg_match("/^.?\bALL\b/", $filter))
 				{ 
@@ -4509,5 +4423,5 @@
 						$_filter = $criteria_fixed . substr($filter,4);
 						
-						$search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
+						$search_criteria = imap_search($this->mbox, $_filter, SE_UID);
 						
 						if(is_array($search_criteria))
@@ -4515,5 +4429,6 @@
 							foreach($search_criteria as $new_search)
 							{
-								$elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 
+                                                                $elem = $this->get_info_head_msg($new_search);
+                                                                
 								$elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); 
 								$elem['uid'] = $new_search;
@@ -4526,10 +4441,10 @@
 				}
 				else{
-					$search_criteria = imap_search($mbox_stream, $filter, SE_UID);
+					$search_criteria = imap_search($this->mbox, $filter, SE_UID);
                                     if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag'])
                                     {
                                         if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false))
                                         {
-                                            $num_msgs = imap_num_msg($mbox_stream);
+                                            $num_msgs = imap_num_msg($this->mbox);
                                             $flagged_msgs = array();
                                             for ($i=$num_msgs; $i>0; $i--)
@@ -4561,6 +4476,6 @@
                                         foreach($search_criteria as $new_search)
                                         {
-                                            $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream);
-							$elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); 
+                                            $elem = $this->get_info_head_msg( $new_search );
+					    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); 
                                             $elem['uid'] = $new_search;
                                             /* compare dates in ordering */
@@ -4573,11 +4488,6 @@
 		}
 		
-		if($mbox_stream)
-		{
-			imap_close($mbox_stream);
-	    }
-	    
+            imap_close($this->mbox);
 	    $num_msgs = count($retorno);
-
 	    /* Comparison functions, descendent is ascendent with parms inverted */
 	    function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); }
@@ -4603,42 +4513,6 @@
 	    $arrayRetorno['currentTab'] =  $params['current_tab'];
 
-		if ($pageret)
-		{
-			return $arrayRetorno;
-		}
-		else
-		{
-			return 'none';
-		}
-	}
-
-	function get_msg_detail($uid_msg,$name_box, $mbox_stream )
-	{
-		$header = $this->get_header($uid_msg);
-		require_once("class.imap_attachment.inc.php");
-		$imap_attachment = new imap_attachment();
-		$attachments =  $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg);
-		$attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:"";
-		$flag = $header->Unseen
-			.$header->Recent
-			.$header->Flagged
-			.$header->Draft
-			.$header->Answered
-			.$header->Deleted
-			.$attachments;
-
-
-		$subject = $this->decode_string($header->fetchsubject);
-		$from = $header->from[0]->mailbox;
-		if($header->from[0]->personal != "")
-			$from = $header->from[0]->personal;
-		$ret_msg['from'] 	= $this->decode_string($from); 
-		$ret_msg['subject']	= $subject; 
-		$ret_msg['udate'] 	= gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); 
-		$ret_msg['size'] 	= $header->Size; 
-		$ret_msg['flag'] 	= $flag; 
-		return $ret_msg;
-	}
-
+            return ($pageret) ? $arrayRetorno : 'none';
+	}
 
 	function size_msg($size){
Index: trunk/expressoMail1_2/inc/class.attachment.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.attachment.inc.php	(revision 5316)
+++ trunk/expressoMail1_2/inc/class.attachment.inc.php	(revision 5359)
@@ -168,5 +168,5 @@
 		//TODO: Descartar código após atualização do módulo de segurança da SERPRO 
 		if($this->isSignedMenssage()) 
-			$this->convertSignedMenssage($rawMessageData);  
+			$this->convertSignedMenssage($rawMail);  
 		//////////////////////////////////////////////////////////////////////////
     }
@@ -379,5 +379,5 @@
 
                                 if (!$name)
-                                        $name = ($attach->structure->headers['subject']) ? $attach->structure->headers['subject'] : 'no title';
+                                        $name = (isset($attach->structure->headers['subject'])) ? $attach->structure->headers['subject'] : 'no title';
 
                                 if (!preg_match("/\.eml$/", $name))
@@ -464,6 +464,6 @@
                         $definition['name'] = addslashes($name);
                         $definition['type'] = $ctype;
-                        $definition['encoding'] = $part->headers['content-transfer-encoding'];
-                        $definition['cid'] = $part->headers['content-id'];
+                        $definition['encoding'] = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : 'base64';
+                        $definition['cid'] = isset($part->headers['content-id']) ? $part->headers['content-id'] : '';
                         array_push($images, $definition);
                     }
Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 5321)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 5359)
@@ -1296,19 +1296,8 @@
 
 		td_element2 = createTDElement(0,1,"td_msg");
-		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)
-			td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(headers_msgs.attachment.names) + "'>";
+		if (headers_msgs.attachment == 1)
+			td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' >";
 
 		td_element21 = createTDElement(0,2,"td_msg",null,"td_message_answered_"+headers_msgs.msg_number);
-
-		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {
-			attach_name = headers_msgs.attachment.names.split(", ");
-			for(var item in attach_name)
-			{
-				if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){
-					td_element21.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(attach_name[item]) + "'>";
-					break;
-				}
-			}
-		}
 
 		if ((headers_msgs.Forwarded == 'F')  || (headers_msgs.Draft == 'X' && headers_msgs.Answered == 'A')){
