Index: branches/1.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- branches/1.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 708)
+++ branches/1.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1342)
@@ -10,5 +10,4 @@
 		'get_range_msgs'				=> True,
 		'get_info_msg'					=> True,
-		'get_info_msgs'					=> True,
 		'get_folders_list'				=> True,
 		'import_msgs'					=> True
@@ -71,4 +70,6 @@
 	function get_range_msgs2($params)
 	{
+		include("class.imap_attachment.inc.php");
+		$imap_attachment = new imap_attachment();
 		$folder = $params['folder'];
 		$msg_range_begin = $params['msg_range_begin'];
@@ -84,88 +85,74 @@
 		if($num_msgs) { 
 			for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++)
-			{
-				$msg_number = $sort_array_msg[$msg_range_begin-1];
-				$temp = $this->get_info_head_msg($msg_number);
-				if(!$temp)
-					return false;
-	
-				$return[$i] = $temp;
-				$i++;
-			}
-		}
-		$return['num_msgs'] = $num_msgs;		
-		
-		return $return;
-	}
-	
-	function get_info_head_msg($msg_number) {
-		$head_array = array();
-		include_once("class.imap_attachment.inc.php");
-		$imap_attachment = new imap_attachment();
-		
-		/*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.
-		* Como as mensagens são renderizadas de X em X, não parece ter
-		* perda considerável de performance.
-		*/
-		$flag = preg_match('/importance *: *(.*)\r/i',
+		{
+			$msg_number = $sort_array_msg[$msg_range_begin-1];
+
+			/*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.
+			* Como as mensagens são renderizadas em um número pequeno por vez,
+			* não parece ter perda considerável de performance.
+			*/
+			$flag = preg_match('/importance *: *(.*)\r/i',
 					imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number))
 					,$importance);		
-		$head_array['Importance'] = $flag==0?"Normal":$importance[1];
-
-		
-		$header = $this->get_header($msg_number);
+			$return[$i]['Importance'] = $flag==0?"":$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;
-		//$return[$i]['msg_folder'] = $folder;
-		
-		$date_msg = gmdate("d/m/Y",$header->udate);
-		if (date("d/m/Y") == $date_msg)
-			$head_array['udate'] = gmdate("H:i",$header->udate);
-		else
-			$head_array['udate'] = $date_msg;
-		
-		$head_array['aux_date'] = $date_msg; //Auxiliar apenas para mensagens locais.
-		
-		$from = $header->from;
-		$head_array['from'] = array();
-		$tmp = imap_mime_header_decode($from[0]->personal);
-		$head_array['from']['name'] = $this->decode_string($tmp[0]->text);
-		$head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host;
-		if(!$head_array['from']['name'])
-			$head_array['from']['name'] = $head_array['from']['email'];
-		$to = $header->to;
-		$head_array['to'] = array();
-		$tmp = imap_mime_header_decode($to[0]->personal);
-		$head_array['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text));
-		$head_array['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host;
-		if(!$head_array['to']['name'])
-			$head_array['to']['name'] = $head_array['to']['email'];
-		$head_array['subject'] = $this->decode_string($header->fetchsubject);
-		
-		$head_array['Size'] = $header->Size;
-		
-		$head_array['attachment'] = array();
-		$head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);
-		
-		return $head_array;
+				return false;			
+			
+			$return[$i]['Recent'] = $header->Recent;
+			$return[$i]['Unseen'] = $header->Unseen;
+			if($header->Answered =='A' && $header->Draft == 'X'){
+				$return[$i]['Forwarded'] = 'F';
+			}
+			else {
+				$return[$i]['Answered']	= $header->Answered;
+				$return[$i]['Draft']	= $header->Draft;	
+			}
+			$return[$i]['Deleted'] = $header->Deleted;
+			$return[$i]['Flagged'] = $header->Flagged;
+			
+			$return[$i]['msg_number'] = $msg_number;
+			//$return[$i]['msg_folder'] = $folder;
+			
+			$date_msg = gmdate("d/m/Y",$header->udate);
+			if (gmdate("d/m/Y") == $date_msg)
+				$return[$i]['udate'] = gmdate("H:i",$header->udate);
+			else
+				$return[$i]['udate'] = $date_msg;
+			
+			$from = $header->from;
+			$return[$i]['from'] = array();
+			$tmp = imap_mime_header_decode($from[0]->personal);
+			$return[$i]['from']['name'] = $this->decode_string($tmp[0]->text);
+			$return[$i]['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host;
+			if(!$return[$i]['from']['name'])
+				$return[$i]['from']['name'] = $return[$i]['from']['email'];
+			$to = $header->to;
+			$return[$i]['to'] = array();
+			$tmp = imap_mime_header_decode($to[0]->personal);
+			$return[$i]['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text));
+			$return[$i]['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host;
+			if(!$return[$i]['to']['name'])
+				$return[$i]['to']['name'] = $return[$i]['to']['email'];
+			$return[$i]['subject'] = $this->decode_string($header->fetchsubject);
+
+			$return[$i]['Size'] = $header->Size;
+			
+			$return[$i]['attachment'] = array();
+			$return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number);			
+			$i++;
+		}
+		}
+		$return['num_msgs'] = $num_msgs;		
+		
+		return $return;
 	}
 	
@@ -310,40 +297,4 @@
 	}
 
-/**
-	 * 
-	 * @return 
-	 * @param $params Object
-	 */
-	function get_info_msgs($params) {
-		include_once("class.exporteml.inc.php");
-		$return = array();
-		$new_params = array();
-		$attach_params = array();
-		$new_params["msg_folder"]=$params["folder"];
-		$attach_params["folder"] = $params["folder"];
-		$msgs = explode(",",$params["msgs_number"]);
-		$exporteml = new ExportEml();
-		foreach($msgs as $msg_number) {
-			$new_params["msg_number"] = $msg_number;
-			//ini_set("display_errors","1");
-			$msg_info = $this->get_info_msg($new_params);
-
-			$this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro.
-			$msg_info['header'] = $this->get_info_head_msg($msg_number);
-
-			$attach_params["num_msg"] = $msg_number;
-			$msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params);
-			$msg_info['url_export_file'] = $exporteml->export_to_archive($msg_number,$params["folder"]);
-			imap_close($this->mbox);
-			$this->mbox=false;
-
-
-			array_push($return,serialize($msg_info));
-
-		}
-
-		return $return;
-	}
-
 	function get_info_msg($params)
 	{
@@ -366,5 +317,5 @@
 		//Substituição de links em email para abrir no próprio expresso
 		$body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']);
-		
+			
 		$return['body'] 		= $body;
 		$return['attachments'] 	= $return_get_body['attachments'];
@@ -598,11 +549,5 @@
 		$return['subject'] = $this->decode_string($header->fetchsubject);
 		$return['Size'] = $header->Size;
-		$return['reply_toaddress'] = $header->reply_toaddress;	
-	
-		//All this is to help in local messages
-		$return['timestamp'] = $header->udate;
-		$return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id'];
-		$return['reply_toaddress'] = $header->reply_toaddress;
-		
+		$return['reply_toaddress'] = $header->reply_toaddress;		
 		return $return;
 	}
@@ -1072,5 +1017,5 @@
 	function refresh($params)
 	{
-		include_once("class.imap_attachment.inc.php");
+		include("class.imap_attachment.inc.php");
 		$imap_attachment = new imap_attachment();		
 		$folder = $params['folder'];
@@ -1152,5 +1097,5 @@
 					imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number))
 					,$importance);		
-			$return[$i]['Importance'] = $flag==0?"Normal":$importance[1];
+			$return[$i]['Importance'] = $flag==0?"":$importance[1];
 			
 			$header = $this->get_header($msg_number);
@@ -1392,8 +1337,4 @@
 				return "The server denied your request to send a mail, you cannot use this mail address.";
 		}
-		
-		//new_message_to backs to mailto: pattern
-		$params['body'] = eregi_replace("<a href=\"javascript:new_message_to\('([^>]+)'\)\">[^>]+</a>","<a href='mailto:\\1'>\\1</a>",$params['body']);
-		
 		$toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to'])));
 		$ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc'])));
@@ -1407,5 +1348,4 @@
 		$attachments = $params['FILES'];
 		$forwarding_attachments = $params['forwarding_attachments'];
-		$local_attachments = $params['local_attachments'];
 		 
 		$folder =$params['folder'];
@@ -1491,5 +1431,5 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 		//	Build Uploading Attachments!!!
-		if ((count($attachments)) && ($params['is_local_forward']!="1")) //Caso seja forward normal...
+		if (count($attachments))
 		{
 			$total_uploaded_size = 0;
@@ -1503,20 +1443,4 @@
 				return $this->parse_error("message file too big");			
 		}			
-		else if(($params['is_local_forward']=="1") && (count($local_attachments))) { //Caso seja forward de mensagens locais
-			
-			$total_uploaded_size = 0;
-			$upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024;			
-			foreach($local_attachments as $local_attachment) {
-				$file_description = unserialize(rawurldecode($local_attachment));
-				$tmp = array_values($file_description);
-				foreach($file_description as $i => $descriptor){				
-					$tmp[$i]  = eregi_replace('\'*\'','',$descriptor);
-				}
-				$mail->AddAttachment($_FILES[$tmp[1]]['tmp_name'], $tmp[2], "base64", $this->get_file_type($tmp[2]));  // optional name
-				$total_uploaded_size = $total_uploaded_size + $_FILES[$tmp[1]]['size'];
-			}
-			if( $total_uploaded_size > $upload_max_filesize)
-				return 'false';	
-		}
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 		//	Build Forwarding Attachments!!!
@@ -1719,61 +1643,4 @@
 	}
 	
-	/**
-	 * Deprecated
-	 * 
-	 * Replaced for the method messages_sort
-	 */
-	function imap_sortfrom($sort_box_reverse, $search_box_type)
-	{
-		$sortfrom = array();
-		$sortfrom_uid = array();
-		
-		$num_msgs = imap_num_msg($this->mbox);
-		for ($i=1; $i<=$num_msgs; $i++)
-		{
-			$header = $this->get_header(imap_uid($this->mbox,$i));
-			// List UNSEEN messages.
-			if($search_box_type == "UNSEEN" &&  (!trim($header->Recent) && !trim($header->Unseen))){
-				continue;
-			}
-			// List SEEN messages.
-			elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){
-				continue;
-			}
-			// List ANSWERED messages.			
-			elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){
-				continue;				
-			}
-			// List FLAGGED messages.			
-			elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){
-				continue;
-			}
-						
-			if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email'])				
-				$from = $header->to;
-			else
-				$from = $header->from;
-			
-			$tmp = imap_mime_header_decode($from[0]->personal);			
-			
-			if ($tmp[0]->text != "")
-				$sortfrom[$i] = $tmp[0]->text;
-			else
-				$sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host;
-		}
-		
-		natcasesort($sortfrom);
-		
-		foreach($sortfrom as $index => $header_msg)
-		{	
-			$sortfrom_uid[] = imap_uid($this->mbox, $index);
-		}
-		
-		if ($sort_box_reverse)
-			$sortfrom_uid = array_reverse($sortfrom_uid);
-		
-		return $sortfrom_uid;
-	}
-
 	function move_search_messages($params){		
 		$params['selected_messages'] = urldecode($params['selected_messages']);	
@@ -2565,11 +2432,5 @@
 		$retorno = "";
 		$mbox_stream = "";
-		if(strpos($params['condition'],"#")===false) { //local messages
-			$search=false;
-		}
-		else {
-			$search = explode(",",$params['condition']);			
-		}
-
+		$search = explode(",",$params['condition']);
 		if($search){
 			$search_criteria = '';
@@ -2832,5 +2693,5 @@
 		$array_parts_attachments = array();		
 		$array_parts_attachments['names'] = '';
-		include_once("class.imap_attachment.inc.php");
+		include("class.imap_attachment.inc.php");
 		$imap_attachment = new imap_attachment();		
 		
