Index: /sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js
===================================================================
--- /sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js	(revision 7543)
+++ /sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js	(revision 7831)
@@ -231,4 +231,27 @@
 var selectedFolder     = {};
 
+function mount_children_localfolders_list(folder){ 
+    folder.children = new Array();
+    folder.id_search = folder.id;
+    folder.id = 'local_messages_'+folder.id,
+    folder.commonName =  folder.name,
+    folder.parentId = folder.parentid,
+    folder.type = 'localFolder',
+    folder.name = folder.id,
+    folder.messageCount = {
+                             total: folder.messages,
+                             unseen: folder.unseen
+                          }
+
+    if(folder.haschild){
+        expresso_mail_archive.getFoldersList(folder.id_search);
+        folder.children = expresso_mail_archive.folders;
+
+        for(var i = 0; i < folder.children.length; i++){
+            mount_children_localfolders_list(folder.children[i]);
+        }
+
+    }
+}
 function adaptOffline( data )
 {
@@ -254,5 +277,29 @@
 	
     return( data );
-	
+}
+
+function archive_flag( flagObj ){
+
+    var flags = {};
+    var returns = '';
+
+    $.each( flagObj, function(i, flag){
+
+        flags[ flag['@value'] ] = true;
+
+    });
+
+/*0*/    returns += (flags['seen'] ? '0.' : '1.') ;
+/*1 2*/  returns += '0.';  
+/*3*/    returns += (flags['unflagged'] ? '0.' : '1.') ;
+/*4*/    returns += '0.';
+/*5*/    returns += '0';
+            
+
+//Answered: parseInt(cellvalue[1]) ? 'Answered' : (parseInt(cellvalue[2]) ? 'Forwarded' : ''),             
+//Recent: parseInt(cellvalue[4])  ? 'Recent' : '',            
+//Draft: parseInt(cellvalue[5]) ? 'Draft' : ''        
+    
+    return returns;
 }
 
@@ -271,4 +318,20 @@
 		var tree2 = new Array();
 		var tree3 = new Array();
+
+
+        if(expresso_mail_archive.folders && !expresso_offline && expresso_mail_archive.enabled == true) { //MailArchive
+            //pega pastas locais do mailarchiver e insere no array de pastas
+                expresso_mail_archive.getFoldersList("home");
+                treeFolders = expresso_mail_archive.folders;
+
+                for(var i=0; i<treeFolders.length; i++ ){
+                    mount_children_localfolders_list(treeFolders[i]);
+                }
+                
+                for(var i = 0; i < treeFolders.length; i++){
+                    data.push(treeFolders[i]);
+                }
+        }
+
 		for (var i=0; i<data.length; i++) {
 
@@ -286,8 +349,5 @@
 			}
 			else if (/^local_messages/.test(data[i].id)) {
-				if (!unorphanize(tree3, data[i])) {
-					data[i].children = new Array();
 					tree3.push(data[i]);
-				}
 			}
 			
@@ -299,4 +359,5 @@
 		.find("#foldertree").treeview()
 		.click(function(event){
+
 			//request new selected folder messages
 			var target = $(event.target);
@@ -325,14 +386,53 @@
 			var grid = $("#message_attacher_grid"), offlineCase = "";
 			
-			if( !targetId.indexOf( 'local_messages/' ) )
-			    offlineCase = ":offline";
-			
-
-			grid.jqGrid('setGridParam',{url:BASE_PATH + 'REST.php'+offlineCase+'?q=folder/'+targetId.replace(dashes, '.')+'/message'})
-			    .trigger("reloadGrid")
-			    .jqGrid('setCaption', '<span class="'+child.attr('class')+'">'+child.attr('title')+'</span>');
+            if(targetId.indexOf( 'local_messages' ) == 0){
+                 //Entrar caso: Clicar em uma pasta que seja do arquivamento local
+                targetId = targetId.split("_")[2];
+
+                expresso_mail_archive.getMessagesByFolder(targetId,"ALL");
+                 
+                msgAll = expresso_mail_archive.msgAll;                
+
+                var msgs = new Array();
+                var from = '';
+                var flag = '';
+                
+
+                $.each(msgAll, function(i, msg){
+                    from = $.parseJSON(msg['_from']);
+                    flag = $.parseJSON(msg['_tags']);
+                    id = msg['_id'];
+
+                    var message = {};
+                    
+                    message['msg_number'] = id;
+                    message['flags'] = archive_flag( flag );
+                    message['from.name'] = from['mailbox']['@name'];
+                    message['subject'] = msg['_subject'];
+                    message['timestamp'] = msg['_receivedDate'];
+                    message['size'] = msg['_size'];
+                    message['id'] = id;
+                    msgs.push( message );
+
+                });
+
+            grid.jqGrid("clearGridData", true);
+            grid.jqGrid('setGridParam',{datatype: "local",data: msgs})
+                    .trigger("reloadGrid")
+                    .jqGrid('setCaption', '<span class="'+child.attr('class')+'">'+child.attr('title')+'</span>');
+
+            } else {
+                if( !targetId.indexOf( 'local_messages/' ) )
+                    offlineCase = ":offline";
+
+                grid.jqGrid('setGridParam',{datatype: "json", url:BASE_PATH + 'REST.php'+offlineCase+'?q=folder/'+targetId.replace(dashes, '.')+'/message'})
+                    .trigger("reloadGrid")
+                    .jqGrid('setCaption', '<span class="'+child.attr('class')+'">'+child.attr('title')+'</span>');
+            }
+
+
 		})
 		.find('span:first-child');
-		$('span.folder.inbox').addClass('selected');
+		$('span.folder.inbox').parents(".ui-dialog").find("li#INBOX span").addClass('selected');
 		selectedFolder = {
 			id: firstFolder.parent().attr('id'), 
@@ -388,5 +488,5 @@
 				});
 				
-				// reconstrói a seleção das mensagens mesmo depois da mudança de pasta
+				// reconstrÃ³i a seleÃ§Ã£o das mensagens mesmo depois da mudanÃ§a de pasta
 				if (selectedMessages[selectedFolder.id]) {
 					for (var message in selectedMessages[selectedFolder.id]){
@@ -409,9 +509,9 @@
 					}
 				}
-				
 				var tabPanelTemplateId = 'mailpreview_tab_' + selectedFolder.id.replace(/[.\/]/g, '_') + '_' + message.msg_number;
 				var tabPanelTemplateId = tabPanelTemplateId.replace(/[\s\/]/g, '-'); 
 				
 				if (selected) {	
+
 					if (onceOpenedMessages[selectedFolder.id] && onceOpenedMessages[selectedFolder.id][message.msg_number]) {
 						if (!selectedMessages[selectedFolder.id])
@@ -433,5 +533,6 @@
 							.find('#' + tabPanelTemplateId + ', [href="#' + tabPanelTemplateId + '"]').removeClass('preview-message-unselected');
 						}
-						
+
+
 					} else {
 						jQuery('#mailpreview_container').block({  
@@ -460,4 +561,15 @@
 							selectedMessages[selectedFolder.id] = {};
 						selectedMessages[selectedFolder.id][message.msg_number] = true;
+
+
+                        if(selectedFolder['id'].indexOf("local_messages_") != -1 && false){
+                        // Arrumar isso!
+                            expresso_mail_archive.getMessageInfo(id);
+                            expresso_mail_archive.getMessageBodies([id]);
+
+                                var body = expresso_mail_archive.bodyPreview;
+                                var subject = expresso_mail_archive.subjectPreview;
+                        }
+
 						$.ajax({
 							accepts: 'text/html',
@@ -465,4 +577,5 @@
 							dataType: 'json',
 							success: function( mail_preview ){		
+
 								//selectedMessagesCount();
 								if (!onceOpenedMessages[selectedFolder.id])
Index: /sandbox/2.5.1-expresso1/expressoMail1_2/js/mail_archiver.js
===================================================================
--- /sandbox/2.5.1-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7685)
+++ /sandbox/2.5.1-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7831)
@@ -1398,4 +1398,47 @@
 }
 
+
+MailArchiver.prototype.getMessagesByFolder = function(folderid, searchType){
+    try{
+        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"}]}}';
+        ArchiveServices.listMessages(expresso_mail_archive.getMessagesByFolderOperationOK, expresso_mail_archive.getMessagesByFolderOperationFailure, expresso_mail_archive.session.id, query_messages);
+    }
+    catch (e){
+        expresso_mail_archive.getFaultInfo();
+    }
+}
+
+MailArchiver.prototype.getMessagesByFolderOperationOK = function(returnService){
+    var msglist = new Array();
+    var msglistcomplete = new Array();
+    var msgAll = new Array();
+    for(var i=0; i< returnService.getReturn().length; i++){
+        //Array montado apenas com ids para tratamento de seleÃ§Ã£o de mensagens independente de paginaÃ§Ã£o
+        msglist.push(returnService.getReturn()[i]._id);
+
+        msgAll.push(returnService.getReturn()[i]);
+
+        //Incremento de contadores para atualizaÃ§Ã£o da aba de listagem
+        if(returnService.getReturn()[i]._tags.indexOf("unseen") != -1){
+            expresso_mail_archive.tot_unseen_msgs_tab++;
+        }
+        expresso_mail_archive.tot_msgs_tab++;
+        //Array montado para operaÃ§Ã£o de desarquivamento
+        var ExpSerialized = expresso_mail_archive.pattern.toExpressoHeader(returnService.getReturn()[i]);
+        msglistcomplete.push(connector.unserialize(ExpSerialized));
+    }
+    expresso_mail_archive.allmessagesbyfolder = msglist;
+    expresso_mail_archive.allcompletemessagesbyfolder = msglistcomplete;
+    expresso_mail_archive.msgAll = msgAll;
+}
+
+MailArchiver.prototype.getMessagesByFolderOperationFailure = function(ServiceFault){
+    window.alert('listAllmessagesByFolder FALHOU!\n' + ServiceFault.getReturn());
+}
+
+
 //List all messages by folder given and set a array with all messages ids
 MailArchiver.prototype.listAllMessagesByFolder = function(folderid, searchType){
@@ -1515,4 +1558,5 @@
     if(msgfound){
         expresso_mail_archive.currentheaders = headerMsg;
+        expresso_mail_archive.subjectPreview = headerMsg.subject;
         return(headerMsg);
     }
@@ -1537,4 +1581,5 @@
             bodies.push(temp);
         }
+        expresso_mail_archive.bodyPreview = temp.getReturn();
         return bodies;
     }
@@ -1618,4 +1663,5 @@
         return;
     }    
+    expresso_mail_archive.te = returnService.getReturn();
     var msgBody = returnService.getReturn();
     //var msgHeaders = expresso_mail_archive.getMessageHeaders(expresso_mail_archive.currentmessage);
@@ -2092,4 +2138,5 @@
         expresso_mail_archive.messageslisted.push(msgitem2);    
         expresso_mail_archive.getMessageHeaders(serviceReturn.getReturn().getId());
+
     }
     else{
