Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 8167)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 8186)
@@ -42,5 +42,5 @@
 	var $useCache = false;
 	var $expirationCache = false;
-
+    var $msgIds = array();// Usado para guardar o messagesIds
         
 	function imap_functions (){
@@ -271,33 +271,36 @@
                     }
                     $return['num_msgs'] =  $num_msgs;   
-		} else {
+		}
+        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);
+            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 $return; 
+            }
+
+            $return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1);
+        }
+
+        $return['messagesIds'] = $this->msgIds;
+        return $return;
     }
 	
@@ -3449,4 +3452,7 @@
 			$sort = array();
 		}
+
+        $this->msgIds = $sort;
+
 		if ($slice_array)
 			$sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true);
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 8167)
+++ /trunk/expressoMail1_2/js/main.js	(revision 8186)
@@ -171,34 +171,5 @@
     }
 
-    //cExecute ("$this.db_functions.get_dropdown_contacts", save_contacts); //Save contacts needs preferences.
-    $.ajax({
-        async: false,
-        url: "controller.php?" + $.param( {action: "$this.imap_functions.getMessagesIds",
-            folder: get_current_folder(),
-             msg_range_begin: "0",
-             msg_range_end: "0",
-            sort_box_type: "SORTARRIVAL",
-            search_box_type: search_box_type,
-            sort_box_reverse: "1"
-            }),
-        success: function(data){
-            data = connector.unserialize(data);
-            if(data){
-                var _data = {};
-                $.each(data,function(index,value){
-                    if (data[index]){
-                        _data[data[index]] = data[index];
-                    }
-                });
-                populateSelectedMsgs(_data);
-            }
-        },
-        beforeSend: function( jqXHR, settings ){
-            connector.showProgressBar();
-        },
-        complete: function( jqXHR, settings ){
-            connector.hideProgressBar();
-        }
-    });
+//  cExecute ("$this.db_functions.get_dropdown_contacts", save_contacts); //Save contacts needs preferences.
 
     cExecute ("$this.imap_functions.get_range_msgs2&folder=INBOX&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type=SORTARRIVAL&search_box_type=ALL&sort_box_reverse=1", handler_draw_box);
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 8182)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 8186)
@@ -658,4 +658,5 @@
 
 var handler_draw_box = function(data){
+    populateSelectedMsgs(data.messagesIds);
 	draw_box(data, 'INBOX', true);
 	//alternate_border(0);
@@ -670,5 +671,5 @@
 		var handler_draw_box = function(data)
 		{
-
+            populateSelectedMsgs(data.messagesIds);
 			if(!verify_session(data))
 				return;
@@ -686,39 +687,9 @@
 			return true;
 		}
+
 		//MAILARCHIVE
         //se for pasta local
         if (/^local_messages/.test(current_folder)) {
             $(".folders-loading").removeClass("folders-loading"); //remove o icone de loading ao clicar nas pastas locais
-        }
-        else { //se não, processamento normal da pasta
-    		$.ajax({
-                async: false,
-    			url: "controller.php?" + $.param( {action: "$this.imap_functions.getMessagesIds", 
-    				folder: folder,
-    				 msg_range_begin: "0",
-    				 msg_range_end: "0", 					
-    				sort_box_type: "SORTARRIVAL", 
-    				search_box_type: search_box_type,
-    				sort_box_reverse: "1"
-    				}),
-    			success: function(data){
-    				data = connector.unserialize(data);
-    				if(data){
-    					var _data = {};
-    					$.each(data,function(index,value){
-    						if (data[index]){
-    							_data[data[index]] = data[index];
-    						}
-    					});
-    					populateSelectedMsgs(_data);
-    				}
-    			},
-    			beforeSend: function( jqXHR, settings ){
-    				connector.showProgressBar();
-    			},
-    			complete: function( jqXHR, settings ){
-    				connector.hideProgressBar();
-    			}
-    		});
         }
 		proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
@@ -2355,5 +2326,9 @@
 	var message_header = Element("message_header_"+search);
 	var handler_draw_box = function(data){
-		draw_box(data, current_folder,true);
+
+        if (typeof(clean_selected) == "undefined")
+            populateSelectedMsgs(data.messagesIds);
+
+        draw_box(data, current_folder,true);
 		//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
         var msgs_unseen = 0;
@@ -2376,27 +2351,4 @@
 	sort_box_type = sort;
 	search_box_type = search;
-
-	if (typeof(clean_selected) == "undefined"){	
-        $.ajax({			
-			url: "controller.php?" + $.param( {action: "$this.imap_functions.getMessagesIds", 
-				folder: get_current_folder(),					
-				sort_box_type: "SORTARRIVAL", 
-				search_box_type: search_box_type,
-				sort_box_reverse: "1"
-				}),
-			success: function(data){
-				data = connector.unserialize(data);
-				if(data){
-					var _data = {};
-					$.each(data,function(index,value){
-						if (value){
-							_data[index] = value;
-						}
-					});
-					populateSelectedMsgs(_data);				
-				}
-			}
-		});
-	}	
 
 	proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
