Index: /trunk/expressoMail1_2/js/mail_archiver.js
===================================================================
--- /trunk/expressoMail1_2/js/mail_archiver.js	(revision 7450)
+++ /trunk/expressoMail1_2/js/mail_archiver.js	(revision 7455)
@@ -172,4 +172,7 @@
     this.allmessagesbyfolder = new Array();
     this.isArchiveOperation = false; //Se estiver em andamento uma operaÃ§Ã£o de arquivamento/desarquivamento.
+    //Contadores da aba de listagem de mensagem
+    this.tot_msgs_tab = 0;
+    this.tot_unseen_msgs_tab = 0;
 }
 
@@ -1357,12 +1360,7 @@
                                       +'\n->ID ' + returnService.getReturn()[0].getId());
     */
-    var msg_unseen_count = 0;
     for(var i=0; i< returnService.getReturn().length; i++){
         var ExpSerialized = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]);
         var msgitem = connector.unserialize(ExpSerialized);
-        //counts unseen messages
-        if(msgitem.Unseen == 'U')
-            msg_unseen_count++;
-      
         // correÃ§Ã£o para por no padrao certo, se nao fizer isso buga a listagem
         msgitem_temp = msgitem.msg_sample;
@@ -1371,6 +1369,4 @@
         expresso_mail_archive.ServiceReturnObjectList.push(returnService.getReturn()[i]); //add each one service return data into this embeded object array
     }
-    var tab_counters = expresso_mail_archive.getFolderCounters();
-    
     //msglist["num_msgs"] = returnService.getReturn().length;
     //window.alert('service return length = ' + returnService.getReturn().length + '\nfolder.nummessages = ' + expresso_mail_archive.folder.nummessages);
@@ -1379,8 +1375,6 @@
 
     //msglist["num_msgs"] = expresso_mail_archive.folder.nummessages;
-    msglist["num_msgs"] = tab_counters[0];
     //window.alert('num msgs');
     //(expresso_mail_archive.folder.unseen) ? msglist["tot_unseen"] = expresso_mail_archive.folder.unseen : msglist["tot_unseen"] = 0;
-    (tab_counters[1] != 0) ? msglist["tot_unseen"] = tab_counters[1] : msglist["tot_unseen"] = 0;
 //    window.alert('num unseen');
     //window.alert('print_r\n\n' + print_r(msglist));
@@ -1389,8 +1383,8 @@
     expresso_mail_archive.messageslisted = msglist;
     expresso_mail_archive.drawdata = {messagesList:msglist};
-    //expresso_mail_archive.drawMessagesList();
+    expresso_mail_archive.drawMessagesList();
     //expresso_mail_archive.drawMessagesList(returnService.getReturn().length, msg_unseen_count);
     //expresso_mail_archive.drawMessagesList(msglist["num_msgs"], msg_unseen_count);
-    expresso_mail_archive.drawMessagesList(msglist["num_msgs"], msglist['tot_unseen']);
+    //expresso_mail_archive.drawMessagesList(expresso_mail_archive.tot_msgs_tab, expresso_mail_archive.tot_unseen_msgs_tab);
     connector.hideProgressBar();
 }
@@ -1402,7 +1396,12 @@
 
 //List all messages by folder given and set a array with all messages ids
-MailArchiver.prototype.listAllMessagesByFolder = function(folderid){
-    try{
-        var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date"}]}}';
+MailArchiver.prototype.listAllMessagesByFolder = function(folderid, searchType){
+    try{
+        //Marcosw
+        if(searchType == "ALL")
+            var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date"}]}}';
+        else
+            var query_messages = '{"query":{"folder":[{"@id":"'+folderid+'"}], "tags":[{"@contains":"'+searchType+'"}], "order":[{"@asc":"date"}]}}';
+        console.log(query_messages);
         ArchiveServices.listMessages(expresso_mail_archive.listAllMessagesByFolderOperationOK, expresso_mail_archive.listAllMessagesByFolderOperationFailure, expresso_mail_archive.session.id, query_messages);
     }
@@ -1417,5 +1416,12 @@
     for(var i=0; i< returnService.getReturn().length; i++){
         msglist.push(returnService.getReturn()[i]._id);
-    }
+        //Marcosw
+        if(returnService.getReturn()[i]._tags.indexOf("unseen") != -1){
+            expresso_mail_archive.tot_unseen_msgs_tab++;
+        }
+        expresso_mail_archive.tot_msgs_tab++;
+        //console.log(returnService.getReturn()[i]);
+    }
+    //console.log(msglist);
     expresso_mail_archive.allmessagesbyfolder = msglist;
 }
@@ -1436,5 +1442,5 @@
 }
 
-MailArchiver.prototype.drawMessagesList = function(msgtot, msgunseen){
+MailArchiver.prototype.drawMessagesList = function(){
     //window.alert('no drawMessagesList com folder = ' + expresso_mail_archive.currentfolder  + '\nudatecounters = ' + expresso_mail_archive.udatecounters);
     var data_to_draw = expresso_mail_archive.drawdata.messagesList;  
@@ -1467,12 +1473,7 @@
     //draw_paging(expresso_mail_archive.drawdata.messagesList.length);
     //draw_paging(preferences.max_email_per_page);
-    draw_paging(folder_num_msgs);    
-    if(((msgtot) && (msgunseen)) || ((parseInt(msgtot)==0)&&(parseInt(msgunseen)==0))){
-        Element('new_m').innerHTML = '<font color="RED">'+$(".tr_msg_unread").length+'</font>';
-    }
-    else{
-        Element("tot_m").innerHTML = folder_num_msgs;
-        Element('new_m').innerHTML = data_to_draw['tot_unseen'] ? '<font color="RED">'+data_to_draw['tot_unseen']+'</font>' : 0;
-    }
+    draw_paging(expresso_mail_archive.tot_msgs_tab);    
+    Element("tot_m").innerHTML = expresso_mail_archive.tot_msgs_tab; //folder_num_msgs;
+    Element('new_m').innerHTML = '<font color="RED">'+expresso_mail_archive.tot_unseen_msgs_tab+'</font>';
 }
 
Index: /trunk/expressoMail1_2/js/messages_controller.js
===================================================================
--- /trunk/expressoMail1_2/js/messages_controller.js	(revision 7426)
+++ /trunk/expressoMail1_2/js/messages_controller.js	(revision 7455)
@@ -34,4 +34,10 @@
                     var exp_dfs = new Array(baseFolder,msg_range_begin,emails_per_page,sort_box_type,search_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip);
                     expresso_mail_archive.queryconfig.setExpressoDefaults(exp_dfs);
+                    //Para recontagem de mensagens para aba e paginação.
+                    expresso_mail_archive.tot_msgs_tab = 0;
+                    expresso_mail_archive.tot_unseen_msgs_tab = 0;
+                    expresso_mail_archive.listAllMessagesByFolder(folder.replace("local_messages_",""), search_box_type);
+                    selectAllFolderMsgs(false);
+                    populateSelectedMsgs(expresso_mail_archive.allmessagesbyfolder);
                     expresso_mail_archive.listMessages();
                 }
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 7437)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 7455)
@@ -681,8 +681,4 @@
         if (/^local_messages/.test(current_folder)) {
             $(".folders-loading").removeClass("folders-loading"); //remove o icone de loading ao clicar nas pastas locais
-            selectAllFolderMsgs(false);
-            //Método chamado para retornar todos os ids de mensagens por folder
-            expresso_mail_archive.listAllMessagesByFolder(folder.replace("local_messages_",""));
-            populateSelectedMsgs(expresso_mail_archive.allmessagesbyfolder);
         }
         else { //se não, processamento normal da pasta
@@ -2310,6 +2306,6 @@
 	sort_box_type = sort;
 	search_box_type = search;
+
 	if (typeof(clean_selected) == "undefined"){	
-		
         $.ajax({			
 			url: "controller.php?" + $.param( {action: "$this.imap_functions.getMessagesIds", 
@@ -2338,6 +2334,6 @@
 			}
 		});
-        
 	}	
+
 	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);
 	current_page = 1;
@@ -5753,5 +5749,7 @@
    	answer+
    	'<span ' + change_font_color + ' id="span_flag_FLAGGED" class="'+(search_box_type == 'FLAGGED' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_important")+'" onclick="if(\'FLAGGED\' == \''+search_box_type+'\') return false;sort_box(\'FLAGGED\',\''+sort_box_type+'\')">'+get_lang("l_important")+'</span>&nbsp;&nbsp;';
-	draw_paging(num_msgs);
-	Element("tot_m").innerHTML = num_msgs;
-}
+    if(!proxy_mensagens.is_local_folder(current_folder)){
+        draw_paging(num_msgs);
+        Element("tot_m").innerHTML = num_msgs;
+    }
+}
