Index: /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3391)
+++ /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3392)
@@ -91,25 +91,61 @@
 		$sort_box_reverse = $params['sort_box_reverse'];
 		$search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false;
-		$sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end);
+
+		if(!$this->mbox || !is_resource($this->mbox))
+			$this->mbox = $this->open_mbox($folder);
 
 		$return = array();
-		$i = 0;
-		$num_msgs = imap_num_msg($this->mbox);
-		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);
-				if(!$temp)
+		
+		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."}".$folder,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)
 				{
-					return false;
-				}
-
-				$return[$i] = $temp;
-				$i++;
-			}
-		}
-		$return['num_msgs'] = $num_msgs;
-
+					$temp = $this->get_info_head_msg($msg_number);
+					if(!$temp)
+						return false;
+
+					$return[$i] = $temp;
+					$i++;
+				}
+			}
+			$return['num_msgs'] =  $num_msgs;
+		}
+		else {
+			$num_msgs = imap_num_msg($this->mbox);	
+			$sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$num_msgs);
+
+
+			$return['tot_unseen'] = 0;
+			$i = 0;		
+
+			if(is_array($sort_array_msg)){
+				foreach($sort_array_msg as $msg_number => $value)
+				{
+					$temp = $this->get_info_head_msg($msg_number);
+					if(!$temp)
+						return false;
+				
+					if($temp['Unseen'] == 'U' || $temp['Recent'] == 'N'){
+						$return['tot_unseen']++;
+					}
+				
+					if($i <= ($msg_range_end-$msg_range_begin))
+						$return[$i] = $temp;
+					$i++;
+				}
+			}
+			$return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1);
+
+		}
 		return $return;
 	}
Index: /branches/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- /branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3383)
+++ /branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3392)
@@ -540,13 +540,13 @@
 
 	if(total_pages == 1) {
-		if(span_paging = document.getElementById("span_paging")) {
+		if(span_paging = document.getElementById("span_paging0")) {
 			span_paging.parentNode.removeChild(span_paging);
 		}
 		return;
 	}
-  	span_paging = document.getElementById("span_paging");
+  	span_paging = document.getElementById("span_paging0");
 	if(!span_paging){
 		span_paging = document.createElement("DIV");
-		span_paging.id = "span_paging";
+		span_paging.id = "span_paging0";
 		span_paging.className = "boxHeaderText";
 		span_paging.align="right";
@@ -1099,12 +1099,9 @@
 	var handler_draw_box = function(data){
 		draw_box(data, current_folder,true);
-		draw_paging(Element('tot_m').innerHTML);
 		//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
-				var msgs_unseen = 0;
-				for(i in data){
-					if(data[i].Unseen == 'U')
-						msgs_unseen++;
-	}
-		Element("new_m").innerHTML = '<font style="color:'+(msgs_unseen == 0 ? '': 'red')+'">' + msgs_unseen + '</font>';
+        var msgs_unseen = 0;
+		draw_paging(data.num_msgs);
+		Element("new_m").innerHTML = '<font style="color:'+(data.tot_unseen == 0 ? '': 'red')+'">' + data.tot_unseen + '</font>';
+		Element("tot_m").innerHTML = data.num_msgs;
 	}
 
@@ -2000,9 +1997,6 @@
 			}
 			else{
-				var anchor_pattern = "http://"+location.host+location.pathname+"#"; 
-				
-				if ( ( links.item( i ).href.indexOf( 'javascript:' ) !== 0 ) && 
-					(links.item( i ).href.indexOf(anchor_pattern) !== 0) ) //se não for âncora
-						links.item( i ).setAttribute( 'target', '_blank' );
+				if ( links.item( i ).href.indexOf( 'javascript:' ) !== 0 )
+					links.item( i ).setAttribute( 'target', '_blank' );
 			}
 		}catch(e){
