Index: /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3831)
+++ /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3843)
@@ -101,5 +101,5 @@
 	{
 		// Free others requests 
-                session_write_close(); 
+		session_write_close(); 
 		$folder = $params['folder'];
 		$msg_range_begin = $params['msg_range_begin'];
@@ -109,10 +109,10 @@
 		$search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false;
 
-                if(!$this->mbox || !is_resource($this->mbox))
+		if(!$this->mbox || !is_resource($this->mbox))
 			$this->mbox = $this->open_mbox($folder);
-
+		
 		$return = array();
-                // Para enviar o offset entre o timezone definido pelo usuário e GMT
-                $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
+		//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") {
@@ -397,5 +397,5 @@
 			}
 			else
-				return ("The import was executed successfully.");
+				return $this->functions->getLang("The import was executed successfully.");
 		}
 	}
@@ -3394,116 +3394,125 @@
         }
 
-	function search_msg($params = ''){
-            $mbox_stream = "";
-            if(strpos($params['condition'],"#")===false) { //local messages? It shouldn't be necessary, should it? FIXME
-                    $search=false;
-            }
-            else {
-                    $search = explode(",",$params['condition']);
+	function search_msg( $params = false )
+	{
+		$mbox_stream = "";
+		
+		if(strpos($params['condition'],"#")===false)
+		{ //local messages
+			$search=false;
+		}
+		else
+		{
+			$search = explode(",",$params['condition']);
+		}
+		
+		$params['page'] = $params['page'] * 1;
+
+	    if( is_array($search) )
+	    {
+			$search = array_unique($search); // Remove duplicated folders
+			$search_criteria = '';
+			$search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'];
+			foreach($search as $tmp)
+			{
+				$tmp1 = explode("##",$tmp);
+				$sum = 0;
+				$name_box = $tmp1[0];
+				unset($filter);
+				foreach($tmp1 as $index => $criteria)
+				{
+					if ($index != 0 && strlen($criteria) != 0)
+					{
+						$filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria)));
+						$filter .= " ".$filter_array[0];
+						if (strlen($filter_array[1]) != 0)
+						{
+							if ( trim($filter_array[0]) != 'BEFORE' &&
+								 trim($filter_array[0]) != 'SINCE' &&
+								 trim($filter_array[0]) != 'ON')
+							{
+							    $filter .= '"'.$filter_array[1].'"';
+							}
+							else
+							{
+								$filter .= '"'.$this->make_search_date($filter_array[1]).'"';
+							}
+						}
+					}
+				}
+				
+				$name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
+				$filter = $this->remove_accents($filter);
+
+				//Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name
+				if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user')
+				{
+					$folder_name = explode($this->imap_delimiter,$name_box);
+					$this->ldap = new ldap_functions();
+					
+					if ($cn = $this->ldap->uid2cn($folder_name[1]))
+					{
+						$folder_name[1] = $cn;
+					}
+					$folder_name = implode($this->imap_delimiter,$folder_name);
+				}
+				else
+					$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);
+				
+				if (preg_match("/^.?\bALL\b/", $filter))
+				{ 
+					// Quick Search, note: this ALL isn't the same ALL from imap_search
+					$all_criterias = array ("TO","SUBJECT","FROM","CC");
+					    
+					foreach($all_criterias as $criteria_fixed)
+					{
+						$_filter = $criteria_fixed . substr($filter,4);
+						
+						$search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
+						
+						if(is_array($search_criteria))
+						{
+							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['uid'] = $new_search; 
+								$retorno[] = $elem; 
+							}
+						}
+					}
+				}
+				else
+				{
+					$search_criteria = imap_search($mbox_stream, $filter, SE_UID);
+					
+					if( is_array( $search_criteria) )
+					{
+						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['uid'] = $new_search; 
+							$retorno[] = $elem;
+						}
+					}
+				}
+			}
+		}
+		
+		if($mbox_stream)
+		{
+			imap_close($mbox_stream);
 	    }
-	    $params['page'] = $params['page']*1;
-
-	    if(is_array($search)){
-		$search = array_unique($search); // Remove duplicated folders
-                $search_criteria = '';
-                $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'];
-                foreach($search as $tmp)
-                {
-                    $tmp1 = explode("##",$tmp);
-                    $sum = 0;
-                    $name_box = $tmp1[0];
-                    unset($filter);
-                    foreach($tmp1 as $index => $criteria)
-                    {
-                        if ($index != 0 && strlen($criteria) != 0)
-                        {
-                            $filter_array = explode("<=>",rawurldecode($criteria));
-                            $filter .= " ".$filter_array[0];
-                            if (strlen($filter_array[1]) != 0){
-                                if (trim($filter_array[0]) != 'BEFORE' &&
-                                    trim($filter_array[0]) != 'SINCE' &&
-                                    trim($filter_array[0]) != 'ON')
-                                {
-                                    $filter .= '"'.$filter_array[1].'"';
-                                }
-                                else
-                                    {
-                                        $filter .= '"'.$this->make_search_date($filter_array[1]).'"';
-                                    }
-                            }
-                        }
-                    }
-                    $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
-                    $filter = $this->remove_accents($filter);
-                    //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name
-                    if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user')
-                    {
-                        $folder_name = explode($this->imap_delimiter,$name_box);
-                        $this->ldap = new ldap_functions();
-                        if ($cn = $this->ldap->uid2cn($folder_name[1]))
-                        {
-                            $folder_name[1] = $cn;
-                        }
-                        $folder_name = implode($this->imap_delimiter,$folder_name);
-                    }
-                    else
-                    {
-                        $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);
-                        }
-
-                    if (preg_match("/^.?\bALL\b/", $filter))
-                    { // Quick Search, note: this ALL isn't the same ALL from imap_search
-
-                        $all_criterias = array ("TO","SUBJECT","FROM","CC");
-                        foreach($all_criterias as $criteria_fixed)
-                        {
-                            $_filter = $criteria_fixed . substr($filter,4);
-
-                            $search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
-
-                            if(is_array($search_criteria))
-                            {
-                                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['uid'] = $new_search; 
-				    $retorno[] = $elem; 
-				}
-			    }
-                        }
-                    }
-                    else {
-                        $search_criteria = imap_search($mbox_stream, $filter, SE_UID);
-                        if( is_array( $search_criteria) )
-                        {
-                            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['uid'] = $new_search; 
-				    $retorno[] = $elem;
-                            }
-                        }
-		    }
-                }
-            }
-            if($mbox_stream)
-            {
-                imap_close($mbox_stream);
-	    }
+	    
 	    $num_msgs = count($retorno);
 
 	    /* Comparison functions, descendent is ascendent with parms inverted */
-	    function SORTDATE($a, $b) { return ($a['udate'] < $b['udate']); }
+	    function SORTDATE($a, $b){ return ($a['udate'] < $b['udate']); }
 	    function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); }
 
@@ -3520,17 +3529,20 @@
 	    function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); }
 
-	    usort($retorno, $params['sort_type']);
-	    $pageret = array_slice($retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']);
-	    $arrayRetorno['num_msgs'] =  $num_msgs;
-	    $arrayRetorno['data'] =  $pageret;
-
-            if ($pageret)
-            {
-                return $arrayRetorno;
-            }
-            else
-            {
-                return 'none';
-            }
+	    usort( $retorno, $params['sort_type']);
+	    $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']);
+	    
+	    $arrayRetorno['num_msgs']	=  $num_msgs;
+	    $arrayRetorno['data']		=  $pageret;
+
+		error_log( '\nNumero de mensagens :'.$arrayRetorno['num_msgs'], 3, "/tmp/log" );
+
+		if ($pageret)
+		{
+			return $arrayRetorno;
+		}
+		else
+		{
+			return 'none';
+		}
 	}
 
@@ -3555,9 +3567,9 @@
 		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; 
+		$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;
 	}
@@ -3938,10 +3950,15 @@
         $sources = explode("#@#@#@",$params['source']);
         $timestamps = explode("#@#@#@",$params['timestamp']);
-        foreach($sources as $index=>$src) {
-                        if($src!=""){
-                                $source = $this->treat_base64_from_post($src);
-                                $insert = $this->insert_email($source,$dest_folder,$timestamps[$index]);
-                        }
-                }
+        foreach($sources as $index=>$src)
+        {
+            if($src!="")
+            {
+				$source = $this->treat_base64_from_post($src);
+				$insert = $this->insert_email($source,$dest_folder,$timestamps[$index]);
+            }
+		}
+        
+        error_log( print_r($insert, true), 3, "/tmp/log" );
+        
         return $insert;
     }
