Index: /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js
===================================================================
--- /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js	(revision 7146)
+++ /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js	(revision 7149)
@@ -4,4 +4,7 @@
 var cp_tree1;
 var cp_tree2;
+//Marcosw início
+var cp_tree3;
+//Marcosw fim
 function unorphanize(root, element) {
 	var ok = false;
@@ -145,4 +148,7 @@
 	cp_tree1 = tree1;
 	cp_tree2 = tree2;
+	//Marcosw inicio
+	cp_tree3 = tree3;
+	//Marcosw fim
 	var shared_acls = {};
 
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7146)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7149)
@@ -889,8 +889,11 @@
 
 MailArchiver.prototype.moveMessagesHandler = function(){
-    
-    if((ttreeBox.name_folder != null) && (ttreeBox.name_folder != '') && (ttreeBox.name_folder.length >0)){
-        expresso_mail_archive.currentfolder = ttreeBox.name_folder.substr(6, ttreeBox.name_folder.length);
-    } 
+    //Marcosw inÃ­cio - código foi comentado pois causava inconsistencias.
+    // console.log("ttreBox.name_folder: "+ttreeBox.name_folder);
+    // console.log("Estranho este metodo");
+    // if((ttreeBox.name_folder != null) && (ttreeBox.name_folder != '') && (ttreeBox.name_folder.length >0)){
+    //     expresso_mail_archive.currentfolder = ttreeBox.name_folder.substr(6, ttreeBox.name_folder.length);
+    // } 
+    //Marcosw fim
 
     if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) {
@@ -948,11 +951,11 @@
         expresso_mail_archive.listMessages(expresso_mail_archive.currentfolder); 
               
-
-        if(expresso_mail_archive.currentfolder.substr(0,6) == 'local_'){
-            ttreeBox.name_folder = expresso_mail_archive.currentfolder;
-        }
-        else{
-            ttreeBox.name_folder = "local_" + expresso_mail_archive.currentfolder;
-        }
+        //Marcosw inÃ­cio - código foi comentado pois causava inconsistencias.
+        // if(expresso_mail_archive.currentfolder.substr(0,6) == 'local_'){
+        //     ttreeBox.name_folder = expresso_mail_archive.currentfolder;
+        // }
+        // else{
+        //     ttreeBox.name_folder = "local_" + expresso_mail_archive.currentfolder;
+        // }
         //ttreeBox.update_folder(true);
         expresso_mail_archive.resetObject();
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7146)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7149)
@@ -1378,58 +1378,112 @@
 	}
 	refresh();
-	if (parseInt(msgs_number) > 0 || msgs_number.length > 0){
-		// remove a flag $FilteredMessage da mensagem, depois move
-		var handler_removeFlag = function(){
-			$.ajax({
-				url: 'controller.php?' + $.param( {action: '$this.imap_functions.move_messages',
-								    folder: folder,
-								    msgs_number: ""+msgs_number,
-								    border_ID: border_ID,
-								    sort_box_type: sort_box_type,
-								    search_box_type: search_box_type,
-								    sort_box_reverse: sort_box_reverse,
-								    reuse_border: border_ID,
-								    new_folder: new_folder,
-								    new_folder_name: new_folder_name,
-								    get_previous_msg: ( !not_opem_previus ? preferences.delete_and_show_previous_message : false ),
-								    decoded: true } ),
-
-				success: function( data ){
-				    data = connector.unserialize( data );
-				    $.each(msgs_number, function(index, value){
-				    	delete selectedPagingMsgs[value];
+	
+	//*** MARCOSW INICIO ***
+	if (proxy_mensagens.is_local_folder(folder)){
+		expresso_mail_archive.update_counters = true;
+        //Folder de onde sai a mensagem Ã© local (armazenamento local)
+
+        if(msgs_number=='selected'){
+            msgs_number = get_selected_messages();
+        }
+
+        if (new_folder == 'local_root'){
+            alert(get_lang("Select a folder!"));
+        }
+                    
+        if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
+            if (proxy_mensagens.is_local_folder(new_folder)){
+                //esta tirando de um folder local para outro folder local
+                //expresso_mail_archive.moveMessages(new_folder.substr(6), msgs_number);
+                expresso_mail_archive.moveMessages(new_folder.replace('local_messages_', ''), msgs_number);
+            }
+            else{
+                //esta tirando de um folder local para um folder IMAP (desarquivamento)
+                if(!new_folder){
+                    new_folder = 'INBOX';
+                }
+                if(currentTab.toString().indexOf("_r") != -1){
+                    msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
+                }                      
+                expresso_mail_archive.unarchieve(folder, new_folder, msgs_number);
+            }
+        }
+        else{
+            write_msg(get_lang('No selected message.'));
+        }
+	}
+	else{
+        if (proxy_mensagens.is_local_folder(new_folder)){
+            //esta tirando de um folder nÃ£o local para um folder local (arquivamento)
+            if(msgs_number=='selected'){
+                archive_msgs(folder, new_folder);
+            }
+            else{
+                archive_msgs(folder, new_folder, msgs_number);
+            }
+        }
+        else{
+            //esta tirando de um folder nÃ£o local para outro folder nÃ£o local (move)
+        //*** MARCOSW FIM ***
+            //move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
+			if (parseInt(msgs_number) > 0 || msgs_number.length > 0){
+				// remove a flag $FilteredMessage da mensagem, depois move
+				var handler_removeFlag = function(){
+					$.ajax({
+						url: 'controller.php?' + $.param( {action: '$this.imap_functions.move_messages',
+										    folder: folder,
+										    msgs_number: ""+msgs_number,
+										    border_ID: border_ID,
+										    sort_box_type: sort_box_type,
+										    search_box_type: search_box_type,
+										    sort_box_reverse: sort_box_reverse,
+										    reuse_border: border_ID,
+										    new_folder: new_folder,
+										    new_folder_name: new_folder_name,
+										    get_previous_msg: ( !not_opem_previus ? preferences.delete_and_show_previous_message : false ),
+										    decoded: true } ),
+
+						success: function( data ){
+						    data = connector.unserialize( data );
+						    $.each(msgs_number, function(index, value){
+						    	delete selectedPagingMsgs[value];
+						    });
+						    totalFolderMsgs -= msgs_number.split(",").length;
+
+						    //TESTE
+						    selectAllFolderMsgs();
+			       			$('.select-link').unbind('click');
+
+						    if( data )
+							handler_move_msgs( data );
+						},
+						beforeSend: function( jqXHR, settings ){
+						  	connector.showProgressBar();
+					    },
+					    complete: function( jqXHR, settings ){
+						  	connector.hideProgressBar();
+					  }
+
 				    });
-				    totalFolderMsgs -= msgs_number.split(",").length;
-
-				    //TESTE
-				    selectAllFolderMsgs();
-           			$('.select-link').unbind('click');
-
-				    if( data )
-					handler_move_msgs( data );
-				},
-				beforeSend: function( jqXHR, settings ){
-				  	connector.showProgressBar();
-			    },
-			    complete: function( jqXHR, settings ){
-				  	connector.hideProgressBar();
-			  }
-
-		    });
-		}
-		var hasFolder = false;
-		$.each(fromRules, function(index, value) {
-			if(value == folder){
-				hasFolder = true;
-				cExecute ("$this.imap_functions.removeFlagMessagesFilter&folder="+folder+"&msg_number="+msgs_number, handler_removeFlag); 
-				return false;
-			}
-		});
-		if(!hasFolder){
-			handler_removeFlag();
-		}
-		
-	}else
-		write_msg(get_lang('No selected message.'));
+				}
+				var hasFolder = false;
+				$.each(fromRules, function(index, value) {
+					if(value == folder){
+						hasFolder = true;
+						cExecute ("$this.imap_functions.removeFlagMessagesFilter&folder="+folder+"&msg_number="+msgs_number, handler_removeFlag); 
+						return false;
+					}
+				});
+				if(!hasFolder){
+					handler_removeFlag();
+				}
+				
+			}else
+				write_msg(get_lang('No selected message.'));
+    //*** MARCOSW INICIO ***
+        }
+    }	
+    //Marcosw fim
+	
 }
 
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js	(revision 7146)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js	(revision 7149)
@@ -173,5 +173,110 @@
 		if (!this.is_local_folder(folder)){
 			delete_msgs(folder, msgs_number, border_ID);
-		}else {
+		}else {    
+            console.log("delete_msgs 2.3 messages_controller");               
+            //MAILARCHIVER-03
+            var msg_to_delete = Element(msgs_number);
+            //user has preference to show previous message on deleting one
+            if (isNaN(currentTab) && parseInt(preferences.delete_and_show_previous_message) && msg_to_delete) {
+                    if (msg_to_delete.previousSibling){ 
+                            var previous_msg = msg_to_delete.previousSibling.id;
+                            
+                            //user has preference to maintain default folder structure at local folders, so we have trash folder
+                            if(preferences.auto_create_local == 1){
+                                //user has preference to "save" delete messasge on trash folder, so move it to there
+                                if (((preferences.save_deleted_msg == true)) && (folder != expresso_mail_archive.specialfolders.trash)){
+                                    expresso_mail_archive.folder_destination = 'trash';
+                                    expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                                    expresso_mail_archive.getMessage(previous_msg);
+                                }
+                                //user does not want to save messages deleted on trash. purge them imediatly
+                                else{
+                                    expresso_mail_archive.deleteMessages(msgs_number);
+                                    expresso_mail_archive.getMessage(previous_msg)
+                                }                                                                                
+                            }
+                            //maybe, we do not have trash.
+                            else{
+                                //user has preference to "save" delete messasge on trash folder, so move it to there
+                                if (((preferences.save_deleted_msg == true)) && (folder != expresso_mail_archive.specialfolders.trash)){
+                                    expresso_mail_archive.createFolder("","Trash");
+                                    expresso_mail_archive.folder_destination = 'trash';
+                                    expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                                    expresso_mail_archive.getMessage(previous_msg);
+                                }
+                                //user does not want to save messages deleted on trash. purge them imediatly
+                                else{
+                                    expresso_mail_archive.deleteMessages(msgs_number);
+                                    expresso_mail_archive.getMessage(previous_msg)
+                                }                                          
+                            }
+                    } 
+                    //there is no previous message existing to show. Just delete de view context
+                    else{ 
+                           //user has preference to maintain default folder structure at local folders, so we have trash folder
+                           if(preferences.auto_create_local == 1){
+                                if (((preferences.save_deleted_msg == true)) && (folder != expresso_mail_archive.specialfolders.trash)){
+                                    expresso_mail_archive.folder_destination = 'trash';
+                                    expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                                    delete_border(currentTab,'false'); 
+                                }
+                                //user does not want to save messages deleted on trash. purge them imediatly
+                                else{
+                                    expresso_mail_archive.deleteMessages(msgs_number);
+                                    delete_border(currentTab,'false'); 
+                                }                                       
+                           }
+                            //maybe, we do not have trash. Purge message so.
+                            else{
+                                //user has preference to "save" delete messasge on trash folder, so move it to there
+                                if (((preferences.save_deleted_msg == true)) && (folder != expresso_mail_archive.specialfolders.trash)){
+                                    expresso_mail_archive.createFolder("","Trash");
+                                    expresso_mail_archive.folder_destination = 'trash';
+                                    expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                                    expresso_mail_archive.getMessage(previous_msg);
+                                }
+                                //user does not want to save messages deleted on trash. purge them imediatly
+                                else{
+                                    expresso_mail_archive.deleteMessages(msgs_number);
+                                }                                    
+                            }
+                    } 
+            } 
+            //user has no preferece to show previous message on deleting
+            else{ 
+                if(preferences.auto_create_local == 1){
+                    //user has preference to "save" delete messasge on trash folder, so move it to there
+					//Marcosw inicio - removido "messages_" da string folder para evitar inconsistência
+                    if (((preferences.save_deleted_msg == true)) && (folder.replace('messages_','') != expresso_mail_archive.specialfolders.trash)){
+                    //Marcosw fim
+                        expresso_mail_archive.folder_destination = 'trash';
+                        expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                        delete_border(currentTab,'false');
+                    }
+                    //user does not want to save messages deleted on trash (or is cleaning it). purge them imediatly
+                    else{
+                        expresso_mail_archive.deleteMessages(msgs_number);
+                        delete_border(currentTab,'false');
+                    }                            
+                }
+                //maybe, we do not have trash. Purge message so.
+                else{
+                    //user has preference to "save" delete messasge on trash folder, so move it to there
+                    if (((preferences.save_deleted_msg == true)) && (folder != expresso_mail_archive.specialfolders.trash)){
+                      expresso_mail_archive.createFolder("","Trash");
+                      expresso_mail_archive.folder_destination = 'trash';
+                      expresso_mail_archive.moveMessages(expresso_mail_archive.folder_destination, msgs_number);
+                    }
+                    //user does not want to save messages deleted on trash. purge them imediatly
+                    else{
+                      expresso_mail_archive.deleteMessages(msgs_number);
+                    }                                    
+                }
+            }
+		}
+
+
+
+		/*}else {
 			if((folder != 'local_Trash') && (expresso_local_messages.as_trash())){
 				expresso_local_messages.move_messages('Trash', msgs_number);
@@ -186,5 +291,5 @@
 				refresh();
 			}
-		}
+		}*/
 	}
 	
@@ -367,5 +472,60 @@
 		if (! folder || folder == 'null')
 			folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : (openTab.imapBox[currentTab] ? openTab.imapBox[currentTab]:get_current_folder());
-		if ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
+
+        //MAILARCHIVER-08
+        if (this.is_local_folder(folder)){
+            expresso_mail_archive.update_counters = true;
+            //Folder de onde sai a mensagem Ã© local (armazenamento local)
+            if (folder == new_folder){
+                write_msg(get_lang('The origin folder and the destination folder are the same.'));
+				return;
+            }                    
+
+            if(msgs_number=='selected'){
+                msgs_number = get_selected_messages();
+            }
+
+            if (new_folder == 'local_root'){
+                alert(get_lang("Select a folder!"));
+            }
+                        
+            if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
+                if (this.is_local_folder(new_folder)){
+                    //esta tirando de um folder local para outro folder local
+                    expresso_mail_archive.moveMessages(new_folder.substr(6), msgs_number);
+                }
+                else{
+                    //esta tirando de um folder local para um folder IMAP (desarquivamento)
+                    if(!new_folder){
+                        new_folder = 'INBOX';
+                    }
+                    if(currentTab.toString().indexOf("_r") != -1){
+                        msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
+                    }                      
+                    expresso_mail_archive.unarchieve(folder, new_folder, msgs_number);
+                }
+            }
+            else{
+                write_msg(get_lang('No selected message.'));
+            }
+        }else{
+            if (this.is_local_folder(new_folder)){
+                //esta tirando de um folder nÃ£o local para um folder local (arquivamento)
+                if(msgs_number=='selected'){
+                    archive_msgs(folder, new_folder);
+                }
+                else{
+                    archive_msgs(folder, new_folder, msgs_number);
+                }
+            }
+            else{
+                //esta tirando de um folder nÃ£o local para outro folder nÃ£o local (move)
+                move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
+            }
+        }	
+
+
+
+		/*if ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
 			if (folder == new_folder){
 				write_msg(get_lang('The origin folder and the destination folder are the same.'));
@@ -407,7 +567,5 @@
 				expresso_local_messages.unarchive_msgs(folder,new_folder,msgs_number);
                 //write_msg(get_lang("you can't move mails from local to server folders"));
-			}
-		
-		
+			}*/
 	}
 	
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/wfolders.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/wfolders.js	(revision 6910)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/wfolders.js	(revision 7149)
@@ -97,7 +97,10 @@
 		winSaveFile.next().css("background-color", "#E0EEEE");
 			
+		/*Insere a Ã¡rvore de diretÃ³rios*/
 		var foldersTree = jQuery("#foldertree-container-sendFileMessage")
 		.removeClass('empty-container')
-		.html(DataLayer.render(BASE_PATH + 'api/templates/foldertree.ejs', {folders: [cp_tree1, cp_tree2, [] ]}))
+		//Marcosw inÃ­cio - Adicionado parametro cp_tree3
+		.html(DataLayer.render(BASE_PATH + 'api/templates/foldertree.ejs', {folders: [cp_tree1, cp_tree2, cp_tree3 ]}))
+		//Marcosw fim
 		.find("#foldertree").treeview()
 		.click(function(event)
