Index: /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3250)
+++ /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3265)
@@ -1467,6 +1467,5 @@
 	function refresh($params)
 	{
-		include_once("class.imap_attachment.inc.php");
-		$imap_attachment = new imap_attachment();
+
 		$folder = $params['folder'];
 		$msg_range_begin = $params['msg_range_begin'];
@@ -1489,32 +1488,11 @@
 
 		$msgs_to_exec = array();
-		if ((count($msg_to_insert)) && ($msgs_existent))
-		{
-			foreach($msg_to_insert as $index => $msg_number)
-			{
-				if ($msgs_in_the_server[$index+1])
-				{
-					//$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' antes da ' . $msgs_in_the_server[$index+1];
-					$msgs_to_exec[$msg_number] = 'box.insertBefore(new_msg, Element("'.$msgs_in_the_server[$index+1].'"));';
-				}
-				else
-				{
-					//$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' no final (append)';
-					$msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);';
-				}
-			}
-			ksort($msgs_to_exec);
-		}
-		elseif(!$msgs_existent)
-		{
-			foreach($msgs_in_the_server as $index => $msg_number)
-			{
-				$msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);';
-			}
-		}
+		foreach($msg_to_insert as $msg_number)
+			$msgs_to_exec[] = $msg_number;
+		sort($msgs_to_exec);
 
 		$return = array();
 		$i = 0;
-		foreach($msgs_to_exec as $msg_number => $command)
+		foreach($msgs_to_exec as $msg_number)
 		{
 			/*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns
@@ -1525,8 +1503,6 @@
 			* duas vezes e de duas formas diferentes, mas em contrapartida, eu
 			* não preciso reimplementar o método utilizando o fetchheader.
-			* Como na atualização são poucas as mensagens que devem ser renderizadas,
-			* a perda em performance é insignificante.
 			*/
-            $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number));
+	                $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];
@@ -1540,9 +1516,8 @@
 
 			$return[$i]['msg_number']	= $msg_number;
-			$return[$i]['command']		= $command;
 
 			$return[$i]['msg_folder']	= $folder;
-            // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type
-            $return[$i]['ContentType']  = $this->getMessageType($msg_number, $tempHeader);
+        		// 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;
@@ -1580,7 +1555,14 @@
 
 			$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['quota'] = $this->get_quota(array('folder_id' => $folder));
+		$return['sort_box_type'] = $params['sort_box_type'];
 		$return['new_msgs'] = imap_num_recent($this->mbox);
 		$return['msgs_to_delete'] = $msg_to_delete;
Index: /branches/2.2/expressoMail1_2/js/main.js
===================================================================
--- /branches/2.2/expressoMail1_2/js/main.js	(revision 3231)
+++ /branches/2.2/expressoMail1_2/js/main.js	(revision 3265)
@@ -406,12 +406,21 @@
 		if (data.length > 0){
 			var msg_info = document.getElementById('msg_info');
-			try{
+			if (msg_info != null)
+			{
 				var msg_tr = msg_info.parentNode;
 				msg_tr.removeChild(msg_info);
-			}catch(e){}
+			}
 
 			table_element = Element("table_box");
 			var box = Element("tbody_box");
 			table_element.appendChild(box);
+
+			if (data.msgs_to_delete.length > 0)
+				for (var i=0; i<data.msgs_to_delete.length; i++){
+					if (data.msgs_to_delete[i] != undefined){
+						removeAll(data.msgs_to_delete[i]);
+					}
+				}
+
 			if (data[0].msg_folder != current_folder) // Bad request
 				return false;
@@ -423,22 +432,15 @@
 					var new_msg = this.make_tr_message(data[i], current_folder);
 					_dragArea.makeDragged(new_msg, data[i].msg_number, data[i].subject, true);
-					eval(data[i].command);
-				}
-			}
-			if (! typeof(data.msgs_to_delete) == 'undefined')
-				for (var i=0; i<data.msgs_to_delete.length; i++){
-					var remove_msg = document.getElementById(data.msgs_to_delete[i]);
-					if (remove_msg)
-						remove_msg.parentNode.removeChild(remove_msg);
-				}
+					if (data[i].Recent == 'N')
+						box.insertBefore(new_msg,box.firstChild);
+					else
+						box.appendChild(new_msg);
+
+				}
+			}
 
 			if(parseInt(alert_new_msg) && data.new_msgs > 0)
 				alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!");
-			if(data.new_msgs > 0){
-				Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + parseInt(data.new_msgs); //refresh tab title
-				update_quota(get_current_folder());
-			}
-			 //if(data.new_msgs > 0 || data.msgs_to_delete.length > 0)
-			//	purgeCache();
+			build_quota(data['quota']);
 		}
 		// Update Box BgColor
