Index: /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js
===================================================================
--- /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js	(revision 7154)
+++ /sandbox/2.5.0-expresso1/prototype/modules/mail/js/foldertree.js	(revision 7202)
@@ -4,543 +4,579 @@
 var cp_tree1;
 var cp_tree2;
-//Marcosw início
+//Marcosw inÃ­cio
 var cp_tree3;
 //Marcosw fim
 function unorphanize(root, element) {
-	var ok = false;
-	var f = 0;
-	for (var i=0; i<root.length; i++) {
-		if (root[i].id == element.parentFolder) {
-			element.children = new Array(); 
-			root[i].children.push(element);
-			return true;
-		} else if (ok = unorphanize(root[i].children, element)) {
-			break;
-		}
-	}
-	return ok;
+    var ok = false;
+    var f = 0;
+    for (var i=0; i<root.length; i++) {
+        if (root[i].id == element.parentFolder) {
+            element.children = new Array(); 
+            root[i].children.push(element);
+            return true;
+        } else if (ok = unorphanize(root[i].children, element)) {
+            break;
+        }
+    }
+    return ok;
 }
 
+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 count_unseen_children(folder){
-	if(folder.children.length){
-		for(var i=0; i< folder.children.length; i++){
-			if(folder.children[i].children.length)
-				folder.children[i]['children_unseen'] = (folder.children[i]['children_unseen'] ? folder.children[i]['children_unseen'] : 0) + count_unseen_children(folder.children[i]);
-			
-			folder['children_unseen'] = (folder['children_unseen'] ? folder['children_unseen'] : 0)+ (folder.children[i]['children_unseen'] ? folder.children[i]['children_unseen'] : 0) + parseInt(folder.children[i].messageCount.unseen);			
-		}
-		return folder['children_unseen'];
-	}else{
-		return parseInt(folder.messageCount.unseen);
-	}
+
+    if(folder.children.length){
+        for(var i=0; i< folder.children.length; i++){
+            
+                if(folder.children[i].children.length)
+                folder.children[i]['children_unseen'] = (folder.children[i]['children_unseen'] ? folder.children[i]['children_unseen'] : 0) + count_unseen_children(folder.children[i]);    
+           
+            folder['children_unseen'] = (folder['children_unseen'] ? folder['children_unseen'] : 0)+ (folder.children[i]['children_unseen'] ? folder.children[i]['children_unseen'] : 0) + parseInt(folder.children[i].messageCount.unseen);            
+        }
+        return folder['children_unseen'];
+    } else {
+        return parseInt(folder.messageCount.unseen);
+    }
 }
 
 function valid_tabs(children_of_this_folder, folder_to_move){
-	var borders_open = $("#border_tr").children();
-
-	var error = false;
-	for(var i = 1; i <= borders_open.length -2; i ++){
-		//VERIFICA A CADA FILHO DA PASTA SE ESTA eventNSAGEM E DESTA PASTA
-		$.each(children_of_this_folder, function(index, value){
-			if($(children_of_this_folder[index]).attr('id') == openTab.imapBox[$(borders_open[i]).find("input[type=hidden]").attr("name")]){
-				error = true;
-				write_msg(get_lang("One or more messages from any sub-folder are open"));
-				return error;
-				
-			}
-		});
-		if(error){
-			return error;
-		}
-		//VERIFICA SE EXISTE NA PASTA A SER MOVIDA
-		if(openTab.imapBox[$(borders_open[i]).find("input[type=hidden]").attr("name")] == folder_to_move){
-			error = true;
-			write_msg(get_lang("One or more messages from this folder are open"));
-			return error;
-		}
-	}
+    var borders_open = $("#border_tr").children();
+
+    var error = false;
+    for(var i = 1; i <= borders_open.length -2; i ++){
+        //VERIFICA A CADA FILHO DA PASTA SE ESTA eventNSAGEM E DESTA PASTA
+        $.each(children_of_this_folder, function(index, value){
+            if($(children_of_this_folder[index]).attr('id') == openTab.imapBox[$(borders_open[i]).find("input[type=hidden]").attr("name")]){
+                error = true;
+                write_msg(get_lang("One or more messages from any sub-folder are open"));
+                return error;
+                
+            }
+        });
+        if(error){
+            return error;
+        }
+        //VERIFICA SE EXISTE NA PASTA A SER MOVIDA
+        if(openTab.imapBox[$(borders_open[i]).find("input[type=hidden]").attr("name")] == folder_to_move){
+            error = true;
+            write_msg(get_lang("One or more messages from this folder are open"));
+            return error;
+        }
+    }
 }
 
 function draw_new_tree_folder(callback){
-	var folders = DataLayer.get("folder", true);	
-
-	if(expresso_mail_archive.folders){	//MailArchive
-	    //pega pastas locais do mailarchiver e insere no array de pastas
-	    var local_folders = new Array();
-	    for (var i=0; i<expresso_mail_archive.folders.length; i++) {
-	        var local_folder = {
-	            id: 'local_messages_'+expresso_mail_archive.folders[i].id,
-	            commonName: expresso_mail_archive.folders[i].name,
-	            messageCount: {
-	                total: expresso_mail_archive.folders[i].messages,
-	                unseen: expresso_mail_archive.folders[i].unseen
-	            }
-	        };
-	        folders.push(local_folder);
-	    }
-	}
-
-    //var local_folders = { id: 'local_messages', commonName: 'Pasta Local', messageCount: {total:200, unseen:20} };
-    //var local_folders = expresso_mail_archive.folders;
-
-    //folders.push(local_folders);
- //    folders[24] = new Array();
-	// folders[24].id = 'local_messages';
- //    folders[24].commonName = 'Pasta Local';
- //    //folders[20].parentFolder = 'root';
- //    folders[24].messageCount = { total: 200, unseen: 20};
-
- //    console.log(folders);
- //    console.log(folders.length);
-
-	if(!selected){
-		selected = "INBOX";
-	}
-	/*
-	if( folders )
-	{
-	    folders = $.map( folders, function( folder ){
-		  return {
-		    id: folder.folder_id,
-		    commonName: folder.folder_name,
-		    parentFolder: folder.folder_parent === "root" ? "" : folder.folder_parent,
-		    messageCount: { total : '', unseen : '0' }
-		  };
-	    });
-	}
-	else
-	    folders = DataLayer.get("folder", true);
-	*/
-	var tree1 = new Array();
-	var tree2 = new Array();
-	var tree3 = new Array();
-	for (var i=0; i<folders.length; i++) {
-		if (/^INBOX/.test(folders[i].id)) {
-			if (!unorphanize(tree1, folders[i])) {
-				folders[i].children = new Array();
-				tree1.push(folders[i]);
-			}
-		}
-		else if (/^user/.test(folders[i].id)) {
-			if (!unorphanize(tree2, folders[i])) {
-				folders[i].children = new Array();
-				tree2.push(folders[i]);
-			}
-		}
-		else if (/^local_messages/.test(folders[i].id)) {
-			if (!unorphanize(tree3, folders[i])) {
-				folders[i].children = new Array();
-				tree3.push(folders[i]);
-			}
-		}
-	}
-	
-	for(var i =0; i<tree1.length; i++){
-		count_unseen_children(tree1[i]);
-	}
-	for(var i =0; i<tree2.length; i++){
-		count_unseen_children(tree2[i]);
-	}
-	for(var i =0; i<tree3.length; i++){
-		count_unseen_children(tree3[i]);
-	}
-	cp_tree1 = tree1;
-	cp_tree2 = tree2;
-	//Marcosw inicio
-	cp_tree3 = tree3;
-	//Marcosw fim
-	var shared_acls = {};
-
-	$.each(cp_tree2, function(index, value){
-		shared_acls[value.id] = value.acl_share;
-	});
-
-	$("#content_folders").removeClass("menu-degrade").parent().removeClass("image-menu");
-	var html = DataLayer.render('../prototype/modules/mail/templates/detailedfoldertree.ejs', {folders: [tree1, tree2, tree3]});
-	var folders_html = $("#content_folders").html(html).find(".mainfoldertree").treeview({
-			persist: "cookie",
-			animated: "fast"
-	}).find(".folder").unbind("click").click(function(event){
-		
-		// MUDANÇA DE PASTAS!
-		var target = $(this);	
-		
-		if($(".folders-loading").length)
-			return;
-		
-		if($(event.target).parent().is(".float-menu"))
-			return;
-			
-		if( target.is('.collapsable-hitarea, .expandable-hitarea, .lastCollapsable-hitarea, .lastExpandable-hitarea, .treeview ,.folder_unseen,.ui-icon, .float-menu, .new_folder, .folders-loading, .head_folder, .shared-folders') )
-			return;
-		
-		if( target.parent().find(".new_folder").length)
-			return;
-			
-		if( !target.attr('id') )
-			target = target.parent();
-		if (target[0] == $(".mainfoldertree")[0]) return;
-		var uiId = target.attr('id');
-		var child = target.find('.folder');
-		  
-		if(!target.is('.mainfoldertree > .expandable-hitarea, .mainfoldertree > .collapsable-hitarea')){
-			$('.filetree span.folder.selected').removeClass('selected');
-			$(target).children('.folder').addClass('selected');
-		}
-		$(this).addClass("folders-loading");
-		selected = target.attr('id');
-		change_folder(target.attr('id'), child.attr('title'));	
-
-		$.ajax({
-			  url : "controller.php?"+ $.param( { action: "$this.imap_functions.get_folders_list", folder: target.attr('id') } ),
-			  success : function(data){
-				  data = connector.unserialize(data);
-
-				  if(data)
-				    build_quota(data);
-			  }
-		});
-
-	}).filter('.followup-messages').click(function(event, ui){
-		search_emails("UNDELETED KEYWORD \"$Followupflagged\"");
-	}).end().end();
-	
-	folders_html.find('[id="'+selected+'"]').children().addClass("selected");
-	$(".folder").not(".head_folder").not(".shared-folders").parent().find(".folder").not(".head_folder,.inbox,.drafts,.sent,.spam,.trash").draggable({
-		// DRAG DE PASTAS
-		start : function(){
-			$(this).css("color", "gray");
-		},
-		stop : function(){
-			$(this).css("color", "");
-		},
-		revert: "invalid",
-		helper: function(event){
-			if($.trim(($(this).text().split("["))[0]).length > 18)
-				return $(DataLayer.render('../prototype/modules/mail/templates/draggin_box.ejs', {texto : (($(this).text().split("["))[0]).substring(0,18) + "...", type: "folder"}));
-			return $(DataLayer.render('../prototype/modules/mail/templates/draggin_box.ejs', {texto : (($(this).text().split("["))[0]), type: "folder"}));
-		},
-		delay: 150,
-		refreshPositions: true,
-		zIndex : 2700,
-		//scroll: true, 
-		//scrollSensitivity: 100,
-		//scrollSpeed: 100,
-		containment: "#divAppbox" 
-	}).end().droppable({
-		//DROP DE PASTAS
-		over : function(a, b){
-			//INICIO : SE A PASTA CONTER FILHAS EXPANDE 
-			over = $(this);
-			$(this).addClass("folder-over");
-			if(($(this)[0] != $(this).parent().find(".head_folder")[0]))
-				if($(this).prev()[0])
-					if($(this).parent().find(".expandable-hitarea")[0] == $(this).prev()[0]){
-						setTimeout(function(){
-							if(over.hasClass("folder-over"))
-								over.prev().trigger("click");
-						}, 500);
-						
-					}
-			//FIM : SE A PASTA CONTER FILHAS EXPANDE
-			
-			//SETA BORDA EM VOLTA DA PASTA
-		},
-		out : function(){
-			//RETIRA BORDA EM VOLTA DA PASTA
-			$(this).removeClass("folder-over");
-		},
-		drop : function(event, ui){
-			$(this).removeClass("folder-over");
-			if($(this).parent().attr('id') == undefined){
-				var folder_to = 'INBOX';
-				var to_folder_title = get_lang("Inbox");
-			}else{
-				var folder_to = $(this).parent().attr('id');
-				var to_folder_title = $(this).attr('title');
-			}		
-			var folder_to_move = ui.draggable.parent().attr('id');
-			var border_id = ui.draggable.find("input[type=hidden]").attr("name");
-			// eventnsagens : SE O DROP VIER DA LISTA DE eventNSAGENS :
-			if(folder_to_move == "tbody_box"){
-				move_msgs2(get_current_folder(), 'selected', 0, folder_to, to_folder_title,true);
-				return refresh();
-			}
-			//SE FOR DE UMA PESQUISA RAPIDA
-			else if(ui.draggable.parents('[id^="content_id_"]')[0]){
-				move_search_msgs("content_id_"+border_id, folder_to, to_folder_title);
-				return refresh();
-			}
-			// eventnsagens : SE O DROP VIER DE UMA ABA ABERTA
-			else if(folder_to_move == "border_tr"){
-				var id_msg = border_id.split("_")[0];
-				folder = $("#input_folder_"+border_id+"_r")[0] ? $("#input_folder_"+border_id+"_r").val() : (openTab.imapBox[border_id] ? openTab.imapBox[border_id]:get_current_folder());
-				alternate_border(border_id);
-				move_msgs2(folder, id_msg, border_id, folder_to, to_folder_title,true);
-				return refresh();
-			}
-			// SE O DROP VIER DA LISTA DE PASTAS
-			else{
-				var folder_to_exist = folder_to_move.split(cyrus_delimiter);	
-				folder_to_exist = folder_to+cyrus_delimiter+folder_to_exist[folder_to_exist.length-1];
-				
-				//VERIFICA SE EXISTE UMA eventNSAGENS ABERTA NESTA PASTA E NAS SUAS FILHAS
-
-				if(valid_tabs(ui.draggable.parent().find("li"), folder_to_move)){
-					return;
-				}
-				//FIM : VERIFICA SE EXISTE UMA eventNSAGENS ABERTA NESTA PASTA E NAS SUAS FILHAS;
-				
-				// VALIDA SE O USUARIO ESTA TENTANDO MOVER A PASTA PARA O eventSMO LOCAL
-				if(folder_to_exist == folder_to_move){
-					return write_msg(get_lang("Thie folder is already in this place"));
-				}
-				
-				// VALIDA SE O USUARIO ESTA TENTANDO MOVER A PASTA ABERTA NO momentO
-				if(folder_to_move == get_current_folder()){
-					return write_msg(get_lang("It's not possible move this folder, because it is being used in the moment!"));
-				}
-				
-				// VALIDA SE O USUARIO ESTA TENTANDO MOVER UMA PASTA FILHA DA PASTA ABERTA NO momentO
-				if(ui.draggable.parent().find(".selected")[0]){
-					return write_msg(get_lang("It's not possible move this folder, because its subfolder is being used in the moment!"));
-				}
-				
-				// VALIDA SE O USUARIO ESTA TENTANDO MOVER UMA PASTA PAI PARA DENTRO DE UMA FILHA
-				if(ui.draggable.parent().find('[id="'+folder_to+'"]')[0]){
-					return write_msg(get_lang("It's not possible to move this folder to its subfolders!"));
-				}					
-				
-				if($('[id="'+folder_to_exist+'"]').length){
-					return write_msg(get_lang("Can not move this folder to this location, because the target has already a folder with this name"));
-				}
-				
-				$(this).addClass("folders-loading");
-				
-				$.ajax({
-					url : "controller.php?"+ $.param( { action: "$this.imap_functions.move_folder", folder_to_move: folder_to_move, folder_to: folder_to } ),
-					success : function(data){
-						cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-						data = connector.unserialize(data);
-						if(data == "Permission denied"){
-							write_msg(get_lang("Permission denied"));
-						}else if(data){
-							write_msg(get_lang("The folder was successfully moved"));
-						}
-						else{
-							write_msg(get_lang("ERROR moving your folder."));
-						}
-					}
-				});
-			}
-		}
-	});
-	$(".folder").not(".shared-folders").parent().find(".folder").hover(
-		function(){
-			//CASO A LI NÃO TENHA UM eventNU FLUTUANTE AINDA, O eventNU É ADICIONADO!
-			if(!$(this).children(":last").hasClass("float-menu") && !$(this).children(":last").hasClass("new_folder")){
-				var folder_ = $(this);
-				var folder_name;
-				var shared = {
-					head : false,
-					valid : false
-				};
-				if(folder_.parent().attr('id')){
-					folder_name = folder_.parent().attr('id').split(cyrus_delimiter);
-					folder_name = folder_name[folder_name.length -1];
-					shared.valid = folder_.parent().attr('id').search("user/") == 0 ? true : false;
-				}else
-					folder_name = "Root";
-				
-				if(shared.valid){
-					shared.head = folder_.parent().attr('id').split(cyrus_delimiter).length == 2 ?  true : false;
-					var folder_name_parts = folder_.parent().attr('id').split(cyrus_delimiter);
-					var acls = shared_acls[folder_name_parts[0]+cyrus_delimiter+folder_name_parts[1]];
-
-				}
-
-				html = DataLayer.render("../prototype/modules/mail/templates/float_folder_menu.ejs", {name_folder : folder_name, flag : shared, acl : acls});					
-					//FUNÇÃO DO eventNU FLUTUANTE EDITAR < BEGIN
-				var esc = false;
-				$(folder_).append(html).find(".float-menu-edit").click(function(){
-					var folder_id = $(this).parents(".closed:first").attr('id');
-					var name = $.trim($(this).parents(".closed:first").find("span:first").text().split("[")[0]);
-					if($(this).parents(".closed:first").find("span:first").hasClass("selected"))
-						return write_msg(get_lang("It's not possible rename this folder, because it is being used in the moment!"));
-					if($(this).parents(".closed:first").find(".selected").length)
-						return write_msg(get_lang("It's not possible rename this folder, because its subfolder is being used in the moment!")); 
-					if(valid_tabs($(this).parents("li:first").find("li"), folder_id))
-						return;
-					$(this).parents(".closed:first").find("span:first").empty().append("<input class='new_folder folder' type='text' maxlength='100'></input>");
-					$(".new_folder").focus().keydown(function(event){
-						event.stopPropagation();
-						if(event.keyCode == 13){
-							if($(this).val() != ""){
-								if($(this).val().match(/[\/\`\~\^\<\>\|\\\"\!\@\#\$\%\&\*\+\(\)\[\]\{\}\?;:]/gi)){
-									return write_msg(get_lang("cannot create folder. try other folder name"));
-								}
-								var new_name = folder_id.replace(/[a-zA-Z0-9á-úÁ-Ú^\s_-]+$/, $(this).val());
-								if($('[id="'+new_name+'"]').length){
-									$(".folders-loading").removeClass("folders-loading");
-									write_msg(get_lang("Mailbox already exists"));
-									return draw_new_tree_folder();
-								}
-								$(".new_folder").parent().addClass("folders-loading");
-								$.ajax({
-									url : "controller.php?action=$this.imap_functions.ren_mailbox",
-									type : "POST",
-									data : "current="+folder_id+"&rename="+new_name,
-									success : function(data){
-										data = connector.unserialize(data);
-										if(data == "Permission denied"){
-											$(".folders-loading").removeClass("folders-loading");
-											cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-											return write_msg(get_lang("Permission denied"));
-										}
-										write_msg(get_lang("The folder was successfully rename"));
-										cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-									}
-								});
-							}else{
-								$(".new_folder").focusout();
-							}
-						}else if( event.keyCode == 27){
-							draw_new_tree_folder();
-						}
-					}).focusout(function(){
-						draw_new_tree_folder();
-					}).val(name);
-				})
-				//FUNÇÃO DO eventNU FLUTUANTE EDITAR < END
-				//FUNÇÃO DO eventNU FLUTUANTE EXCLUIR < BEGIN
-				.end().find(".float-menu-remove").click(function(){
-					
-					var folder_id = $(this).parents(".closed:first").attr('id');
-					var folder_name = "<strong>"+$.trim($(this).parents(".closed:first").find(".folder").text().split("[")[0])+"</strong>";
-					
-					if(valid_tabs($(this).parents("li:first").find("li"), folder_id))
-						return;
-					$(this).parents(".closed:first").find(".folder").addClass("folders-loading"); 
-					
-					if($(this).parents(".closed:first").find("ul").length){
-						$(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
-						return write_msg(get_lang("Delete/move subfolders first"));
-					}
-					if($(this).parents(".closed:first").find(".selected").length){
-						$(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
-						return write_msg(get_lang("It's not possible delete this folder, because it is being used in the moment!")); 
-					}
-					var folder_span = $(this);
-					var confirm_text = get_lang("Do you wish to exclude the folder ");
-					$.Zebra_Dialog(confirm_text+folder_name, {
-						'type':     'question',
-						'overlay_opacity': '0.5',
-						'buttons':  [get_lang('Yes'), get_lang('No')],
-						'onClose':  function(caption) {
-							if(caption == get_lang('Yes')){
-								$.ajax({
-									url : "controller.php?action=$this.imap_functions.delete_mailbox",
-									type: "POST",
-									data : "del_past="+folder_id,
-									success : function(data){
-										data = connector.unserialize(data);
-										if(data == "Mailbox does not exist"){
-											$(".folders-loading").removeClass("folders-loading");
-											return write_msg(get_lang("Mailbox does not exist"));
-										}else if(data == "Permission denied"){
-											$(".folders-loading").removeClass("folders-loading");
-											cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-											return write_msg(get_lang("Permission denied"));
-										}
-										write_msg(get_lang("The folder %1 was successfully removed", folder_name));
-										cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-									}
-								});
-							}else{
-								folder_span.parents(".closed:first").find(".folder").removeClass("folders-loading");
-								return;
-							}
-						}
-					});
-					/* if(!confirm(confirm_text + folder_name)){
-						$(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
-						return;
-					} */
-				})
-				//FUNÇÃO DO eventNU FLUTUANTE EXCLUIR < END
-				//FUNÇÃO DO eventNU FLUTUANTE NOVA PASTA < BEGIN
-				.end().find(".float-menu-new").click(function(){
-					$(this).parents(".float-menu").hide();
-					var selected_li = $(this).parents(".closed:first");
-					if(selected_li.find("ul:first").length){
-						var new_folder = $("<li><input class='new_folder folder' type='text' maxlength='100'></input></li>").appendTo(selected_li.find("ul:first"));								
-						if(selected_li.find(".expandable-hitarea").length){
-							selected_li.find(".expandable-hitarea").trigger('click');
-						}
-						selected_li.find("ul:first").treeview({
-							add: new_folder
-						});
-					}else if(selected_li.length){
-						var new_folder = $("<ul><li><input class='new_folder folder' type='text' maxlength='100'></input></li></ul>").appendTo(selected_li);								
-						selected_li.treeview({
-							add: new_folder
-						});
-					}else{
-						selected_li = $(this).parents(".head_folder").parent();
-						if($(this).parents(".head_folder").parent().find(".expandable-hitarea").length){
-							$(this).parents(".head_folder").parent().find(".expandable-hitarea").trigger('click');
-						}
-						var new_folder = $("<ul><li><input class='new_folder folder' type='text' maxlength='100'></input></li></ul>").appendTo(selected_li);								
-						selected_li.treeview({
-							add: new_folder
-						});
-					}
-					
-					selected_li.find(".new_folder").Watermark("Nova Pasta").focus().keydown(function(event){
-						event.stopPropagation();
-						if(event.keyCode == 13){
-							if($(this).val().match(/[\`\~\^\<\>\|\\\"\!\@\#\$\%\&\*\+\(\)\[\]\{\}\?;:]/gi)){
-								return write_msg(get_lang("cannot create folder. try other folder name"));
-							}
-							if($('[id="'+ (selected_li.attr('id')? selected_li.attr('id') : "INBOX") + cyrus_delimiter + $(this).val()+'"]').length){
-								$(".folders-loading").removeClass("folders-loading");
-								write_msg(get_lang("Mailbox already exists"));
-								return draw_new_tree_folder();
-							}
-							$(".new_folder").parent().addClass("folders-loading");
-							create_new_folder(($(this).val() != "" ? $(this).val() : get_lang("New Folder")), (selected_li.attr('id')? selected_li.attr('id') : "INBOX"));
-						}else if( event.keyCode == 27){
-							draw_new_tree_folder();
-						}
-					}).focusout(function(){
-						draw_new_tree_folder();
-					});
-				}).end().find(".float-menu-export").click(function(){
-					//proxy_mensagens.export_all_messages($(this).parents("li:first").attr("id"))
-
-					var name_box = $(this).parents("li:first").attr("id");
-					var name_folder = name_box.split(cyrus_delimiter)[name_box.split(cyrus_delimiter).length-1];
-
-					var hand_export = function(data){
-						if(!data){
-							write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'))
-						}else if(data["empty_folder"]){
-							write_msg(get_lang("The selected folder is empty."));
-						}else
-						  download_attachments(null, null, data, null,null, name_folder +'.zip');
-					}
-					cExecute("$this.exporteml.export_all",hand_export,"folder="+name_box);	
-					write_msg(get_lang('You must wait while the messages will be exported...'));		
-				});
-				//FUNÇÃO DO eventNU FLUTUANTE NOVA PASTA < END
-			}
-			if(!$(".new_folder").length){
-				$(this).find(".float-menu:first").css("display", "");
-			}
-		},
-		function(){
-			$(this).find(".float-menu:first").hide();
-		}
-	);
-	$("#new_m").html($('.selected').find(".folder_unseen").html() ? $('.selected').find(".folder_unseen").html() : "0").css("color", "red");
+    var folders = DataLayer.get("folder", true);    
+
+
+    if(expresso_mail_archive.folders){  //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++){
+                folders.push(treeFolders[i]);
+            }
+ 
+    }
+
+    if(!selected){
+        selected = "INBOX";
+    }
+
+    var tree1 = new Array();
+    var tree2 = new Array();
+    var tree3 = new Array();
+    for (var i=0; i<folders.length; i++) {
+        if (/^INBOX/.test(folders[i].id)) {
+            if (!unorphanize(tree1, folders[i])) {
+                folders[i].children = new Array();
+
+                tree1.push(folders[i]);
+            }
+        }
+        else if (/^user/.test(folders[i].id)) {
+            if (!unorphanize(tree2, folders[i])) {
+                folders[i].children = new Array();
+                tree2.push(folders[i]);
+            }
+        }
+        else if (/^local_messages/.test(folders[i].id)) {
+           
+                tree3.push(folders[i]);
+            
+        }
+    }
+    
+    for(var i =0; i<tree1.length; i++){
+        count_unseen_children(tree1[i]);
+    }
+    for(var i =0; i<tree2.length; i++){
+        count_unseen_children(tree2[i]);
+    }
+    for(var i =0; i<tree3.length; i++){
+        count_unseen_children(tree3[i]);
+    }
+    cp_tree1 = tree1;
+    cp_tree2 = tree2;
+    //Marcosw inicio
+    cp_tree3 = tree3;
+    //Marcosw fim
+    var shared_acls = {};
+
+    $.each(cp_tree2, function(index, value){
+        shared_acls[value.id] = value.acl_share;
+    });
+
+    $("#content_folders").removeClass("menu-degrade").parent().removeClass("image-menu");
+    var html = DataLayer.render('../prototype/modules/mail/templates/detailedfoldertree.ejs', {folders: [tree1, tree2, tree3]});
+    var folders_html = $("#content_folders").html(html).find(".mainfoldertree").treeview({
+            persist: "cookie",
+            animated: "fast"
+    }).find(".folder").unbind("click").click(function(event){
+        
+        // MUDANÃA DE PASTAS!
+        var target = $(this);   
+        
+        if($(".folders-loading").length)
+            return;
+        
+        if($(event.target).parent().is(".float-menu"))
+            return;
+            
+        if( target.is('.collapsable-hitarea, .expandable-hitarea, .lastCollapsable-hitarea, .lastExpandable-hitarea, .treeview ,.folder_unseen,.ui-icon, .float-menu, .new_folder, .folders-loading, .head_folder, .shared-folders') )
+            return;
+        
+        if( target.parent().find(".new_folder").length)
+            return;
+            
+        if( !target.attr('id') )
+            target = target.parent();
+        if (target[0] == $(".mainfoldertree")[0]) return;
+        var uiId = target.attr('id');
+        var child = target.find('.folder');
+          
+        if(!target.is('.mainfoldertree > .expandable-hitarea, .mainfoldertree > .collapsable-hitarea')){
+            $('.filetree span.folder.selected').removeClass('selected');
+            $(target).children('.folder').addClass('selected');
+        }
+        $(this).addClass("folders-loading");
+        selected = target.attr('id');
+        change_folder(target.attr('id'), child.attr('title'));  
+
+        $.ajax({
+              url : "controller.php?"+ $.param( { action: "$this.imap_functions.get_folders_list", folder: target.attr('id') } ),
+              success : function(data){
+                  data = connector.unserialize(data);
+
+                  if(data)
+                    build_quota(data);
+              }
+        });
+
+    }).filter('.followup-messages').click(function(event, ui){
+        search_emails("UNDELETED KEYWORD \"$Followupflagged\"");
+    }).end().end();
+    
+    folders_html.find('[id="'+selected+'"]').children().addClass("selected");
+    $(".folder").not(".head_folder").not(".shared-folders").parent().find(".folder").not(".head_folder,.inbox,.drafts,.sent,.spam,.trash").draggable({
+        // DRAG DE PASTAS
+        start : function(){
+            $(this).css("color", "gray");
+        },
+        stop : function(){
+            $(this).css("color", "");
+        },
+        revert: "invalid",
+        helper: function(event){
+            if($.trim(($(this).text().split("["))[0]).length > 18)
+                return $(DataLayer.render('../prototype/modules/mail/templates/draggin_box.ejs', {texto : (($(this).text().split("["))[0]).substring(0,18) + "...", type: "folder"}));
+            return $(DataLayer.render('../prototype/modules/mail/templates/draggin_box.ejs', {texto : (($(this).text().split("["))[0]), type: "folder"}));
+        },
+        delay: 150,
+        refreshPositions: true,
+        zIndex : 2700,
+        //scroll: true, 
+        //scrollSensitivity: 100,
+        //scrollSpeed: 100,
+        containment: "#divAppbox" 
+    }).end().droppable({
+        //DROP DE PASTAS
+        over : function(a, b){
+            //INICIO : SE A PASTA CONTER FILHAS EXPANDE 
+            over = $(this);
+            $(this).addClass("folder-over");
+            if(($(this)[0] != $(this).parent().find(".head_folder")[0]))
+                if($(this).prev()[0])
+                    if($(this).parent().find(".expandable-hitarea")[0] == $(this).prev()[0]){
+                        setTimeout(function(){
+                            if(over.hasClass("folder-over"))
+                                over.prev().trigger("click");
+                        }, 500);
+                        
+                    }
+            //FIM : SE A PASTA CONTER FILHAS EXPANDE
+            
+            //SETA BORDA EM VOLTA DA PASTA
+        },
+        out : function(){
+            //RETIRA BORDA EM VOLTA DA PASTA
+            $(this).removeClass("folder-over");
+        },
+        drop : function(event, ui){
+            $(this).removeClass("folder-over");
+            if($(this).parent().attr('id') == undefined){
+                var folder_to = 'INBOX';
+                var to_folder_title = get_lang("Inbox");
+            }else{
+                var folder_to = $(this).parent().attr('id');
+                var to_folder_title = $(this).attr('title');
+            }       
+            var folder_to_move = ui.draggable.parent().attr('id');
+            var border_id = ui.draggable.find("input[type=hidden]").attr("name");
+            // eventnsagens : SE O DROP VIER DA LISTA DE eventNSAGENS :
+            if(folder_to_move == "tbody_box"){
+                move_msgs2(get_current_folder(), 'selected', 0, folder_to, to_folder_title,true);
+                return refresh();
+            }
+            //SE FOR DE UMA PESQUISA RAPIDA
+            else if(ui.draggable.parents('[id^="content_id_"]')[0]){
+                move_search_msgs("content_id_"+border_id, folder_to, to_folder_title);
+                return refresh();
+            }
+            // eventnsagens : SE O DROP VIER DE UMA ABA ABERTA
+            else if(folder_to_move == "border_tr"){
+                var id_msg = border_id.split("_")[0];
+                folder = $("#input_folder_"+border_id+"_r")[0] ? $("#input_folder_"+border_id+"_r").val() : (openTab.imapBox[border_id] ? openTab.imapBox[border_id]:get_current_folder());
+                alternate_border(border_id);
+                move_msgs2(folder, id_msg, border_id, folder_to, to_folder_title,true);
+                return refresh();
+            }
+            // SE O DROP VIER DA LISTA DE PASTAS
+            else{
+                var folder_to_exist = folder_to_move.split(cyrus_delimiter);    
+                folder_to_exist = folder_to+cyrus_delimiter+folder_to_exist[folder_to_exist.length-1];
+                
+                //VERIFICA SE EXISTE UMA eventNSAGENS ABERTA NESTA PASTA E NAS SUAS FILHAS
+
+                if(valid_tabs(ui.draggable.parent().find("li"), folder_to_move)){
+                    return;
+                }
+                //FIM : VERIFICA SE EXISTE UMA eventNSAGENS ABERTA NESTA PASTA E NAS SUAS FILHAS;
+                
+                // VALIDA SE O USUARIO ESTA TENTANDO MOVER A PASTA PARA O eventSMO LOCAL
+                if(folder_to_exist == folder_to_move){
+                    return write_msg(get_lang("Thie folder is already in this place"));
+                }
+                
+                // VALIDA SE O USUARIO ESTA TENTANDO MOVER A PASTA ABERTA NO momentO
+                if(folder_to_move == get_current_folder()){
+                    return write_msg(get_lang("It's not possible move this folder, because it is being used in the moment!"));
+                }
+                
+                // VALIDA SE O USUARIO ESTA TENTANDO MOVER UMA PASTA FILHA DA PASTA ABERTA NO momentO
+                if(ui.draggable.parent().find(".selected")[0]){
+                    return write_msg(get_lang("It's not possible move this folder, because its subfolder is being used in the moment!"));
+                }
+                
+                // VALIDA SE O USUARIO ESTA TENTANDO MOVER UMA PASTA PAI PARA DENTRO DE UMA FILHA
+                if(ui.draggable.parent().find('[id="'+folder_to+'"]')[0]){
+                    return write_msg(get_lang("It's not possible to move this folder to its subfolders!"));
+                }                   
+                
+                if($('[id="'+folder_to_exist+'"]').length){
+                    return write_msg(get_lang("Can not move this folder to this location, because the target has already a folder with this name"));
+                }
+                
+                $(this).addClass("folders-loading");
+
+                $.ajax({
+                    url : "controller.php?"+ $.param( { action: "$this.imap_functions.move_folder", folder_to_move: folder_to_move, folder_to: folder_to } ),
+                    success : function(data){
+                        cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                        data = connector.unserialize(data);
+                        if(data == "Permission denied"){
+                            write_msg(get_lang("Permission denied"));
+                        }else if(data){
+                            write_msg(get_lang("The folder was successfully moved"));
+                        } else {
+                            write_msg(get_lang("ERROR moving your folder."));
+                        }
+                    }
+                });
+            }
+        }
+    });
+    $(".folder").not(".shared-folders").parent().find(".folder").hover(
+        function(){
+            //CASO A LI NÃO TENHA UM eventNU FLUTUANTE AINDA, O eventNU Ã ADICIONADO!
+            if(!$(this).children(":last").hasClass("float-menu") && !$(this).children(":last").hasClass("new_folder")){
+                var folder_ = $(this);
+                var folder_name;
+                var shared = {
+                    head : false,
+                    valid : false
+                };
+                if(folder_.parent().attr('id')){
+                    folder_name = folder_.parent().attr('id').split(cyrus_delimiter);
+                    folder_name = folder_name[folder_name.length -1];
+                    shared.valid = folder_.parent().attr('id').search("user/") == 0 ? true : false;
+                }else
+                    folder_name = "Root";
+                
+                if(shared.valid){
+                    shared.head = folder_.parent().attr('id').split(cyrus_delimiter).length == 2 ?  true : false;
+                    var folder_name_parts = folder_.parent().attr('id').split(cyrus_delimiter);
+                    var acls = shared_acls[folder_name_parts[0]+cyrus_delimiter+folder_name_parts[1]];
+
+                }
+
+                html = DataLayer.render("../prototype/modules/mail/templates/float_folder_menu.ejs", {name_folder : folder_name, flag : shared, acl : acls});                   
+                    //FUNÃÃO DO eventNU FLUTUANTE EDITAR < BEGIN
+                var esc = false;
+                $(folder_).append(html).find(".float-menu-edit").click(function(){
+                    var folder_id = $(this).parents(".closed:first").attr('id');
+                    var name = $.trim($(this).parents(".closed:first").find("span:first").text().split("[")[0]);
+                    if($(this).parents(".closed:first").find("span:first").hasClass("selected"))
+                        return write_msg(get_lang("It's not possible rename this folder, because it is being used in the moment!"));
+                    if($(this).parents(".closed:first").find(".selected").length)
+                        return write_msg(get_lang("It's not possible rename this folder, because its subfolder is being used in the moment!")); 
+                    if(valid_tabs($(this).parents("li:first").find("li"), folder_id))
+                        return;
+                    $(this).parents(".closed:first").find("span:first").empty().append("<input class='new_folder folder' type='text' maxlength='100'></input>");
+                    $(".new_folder").focus().keydown(function(event){
+                        event.stopPropagation();
+                        
+                        if(event.keyCode == 13){
+                            if($(this).val() != ""){
+
+                                if($(this).val().match(/[\/\`\~\^\<\>\|\\\"\!\@\#\$\%\&\*\+\(\)\[\]\{\}\?;:]/gi)){
+                                    return write_msg(get_lang("cannot create folder. try other folder name"));
+                                }
+                                var new_name = folder_id.replace(/[a-zA-Z0-9Ã¡-ÃºÃ-Ã^\s_-]+$/, $(this).val());
+                                if($('[id="'+new_name+'"]').length){
+                                    $(".folders-loading").removeClass("folders-loading");
+                                    write_msg(get_lang("Mailbox already exists"));
+                                    return draw_new_tree_folder();
+                                }
+                                $(".new_folder").parent().addClass("folders-loading");
+
+                                if($(this).parent().parent().parent().find("input").val() == "localFolder"){
+                                    var idFolder = $(this).parent().parent().attr("id").split("_")[2];
+                                    expresso_mail_archive.renameFolder(idFolder, new_name);
+                                     cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                } else {
+
+                                $.ajax({
+                                    url : "controller.php?action=$this.imap_functions.ren_mailbox",
+                                    type : "POST",
+                                    data : "current="+folder_id+"&rename="+new_name,
+                                    success : function(data){
+                                        data = connector.unserialize(data);
+                                        if(data == "Permission denied"){
+                                            $(".folders-loading").removeClass("folders-loading");
+                                            cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                            return write_msg(get_lang("Permission denied"));
+                                        }
+                                        write_msg(get_lang("The folder was successfully rename"));
+                                        cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                    }
+                                });
+
+                                }
+                            }else{
+                                $(".new_folder").focusout();
+                            }
+                        }else if( event.keyCode == 27){
+                            draw_new_tree_folder();
+                        }
+                    }).focusout(function(){
+                        draw_new_tree_folder();
+                    }).val(name);
+                })
+                //FUNÃÃO DO eventNU FLUTUANTE EDITAR < END
+                //FUNÃÃO DO eventNU FLUTUANTE EXCLUIR < BEGIN
+                .end().find(".float-menu-remove").click(function(){
+                    
+                    var folder_id = $(this).parents(".closed:first").attr('id');
+                    var folder_name = "<strong>"+$.trim($(this).parents(".closed:first").find(".folder").text().split("[")[0])+"</strong>";
+                    
+                    if(valid_tabs($(this).parents("li:first").find("li"), folder_id))
+                        return;
+                    $(this).parents(".closed:first").find(".folder").addClass("folders-loading"); 
+                    
+                    if($(this).parents(".closed:first").find("ul").length){
+                        $(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
+                        return write_msg(get_lang("Delete/move subfolders first"));
+                    }
+                    if($(this).parents(".closed:first").find(".selected").length){
+                        $(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
+                        return write_msg(get_lang("It's not possible delete this folder, because it is being used in the moment!")); 
+                    }
+                    var folder_span = $(this);
+                    var confirm_text = get_lang("Do you wish to exclude the folder ");
+
+                    $.Zebra_Dialog(confirm_text+folder_name, {
+                        'type':     'question',
+                        'overlay_opacity': '0.5',
+                        'buttons':  [get_lang('Yes'), get_lang('No')],
+                        'onClose':  function(caption) {
+
+                            if(caption == get_lang('Yes')){
+                                if(folder_span.parent().parent().parent().find("input").val() == "localFolder"){
+                                    var idFolder = folder_span.parent().parent().parent("li").attr("id").split("_")[2];
+                                    expresso_mail_archive.deleteFolder(idFolder);
+                                     cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                } else {
+                                $.ajax({
+                                    url : "controller.php?action=$this.imap_functions.delete_mailbox",
+                                    type: "POST",
+                                    data : "del_past="+folder_id,
+                                    success : function(data){
+                                        data = connector.unserialize(data);
+                                        if(data == "Mailbox does not exist"){
+                                            $(".folders-loading").removeClass("folders-loading");
+                                            return write_msg(get_lang("Mailbox does not exist"));
+                                        }else if(data == "Permission denied"){
+                                            $(".folders-loading").removeClass("folders-loading");
+                                            cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                            return write_msg(get_lang("Permission denied"));
+                                        }
+                                        write_msg(get_lang("The folder %1 was successfully removed", folder_name));
+                                        cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                                    }
+                                });
+                                }
+                            }else{
+                                folder_span.parents(".closed:first").find(".folder").removeClass("folders-loading");
+                                return;
+                            }
+                        }
+                    });
+                    /* if(!confirm(confirm_text + folder_name)){
+                        $(this).parents(".closed:first").find(".folder").removeClass("folders-loading");
+                        return;
+                    } */
+                })
+                //FUNÃÃO DO eventNU FLUTUANTE EXCLUIR < END
+                //FUNÃÃO DO eventNU FLUTUANTE NOVA PASTA < BEGIN
+                .end().find(".float-menu-new").click(function(){
+                    $(this).parents(".float-menu").hide();
+                    var selected_li = $(this).parents(".closed:first");
+                    if(selected_li.find("ul:first").length){
+                        var new_folder = $("<li><input class='new_folder folder' type='text' maxlength='100'></input></li>").appendTo(selected_li.find("ul:first"));                                
+                        if(selected_li.find(".expandable-hitarea").length){
+                            selected_li.find(".expandable-hitarea").trigger('click');
+                        }
+                        selected_li.find("ul:first").treeview({
+                            add: new_folder
+                        });
+                    }else if(selected_li.length){
+                        var new_folder = $("<ul><li><input class='new_folder folder' type='text' maxlength='100'></input></li></ul>").appendTo(selected_li);                                
+                        selected_li.treeview({
+                            add: new_folder
+                        });
+                    }else{
+                        selected_li = $(this).parents(".head_folder").parent();
+                        if($(this).parents(".head_folder").parent().find(".expandable-hitarea").length){
+                            $(this).parents(".head_folder").parent().find(".expandable-hitarea").trigger('click');
+                        }
+                        var new_folder = $("<ul><li><input class='new_folder folder' type='text' maxlength='100'></input></li></ul>").appendTo(selected_li);                                
+                        selected_li.treeview({
+                            add: new_folder
+                        });
+                    }
+                    
+                    selected_li.find(".new_folder").Watermark("Nova Pasta").focus().keydown(function(event){
+                        event.stopPropagation();
+
+
+                        if(event.keyCode == 13){
+
+                            if($(this).parent().parent().parent().find("input[type=hidden]").val() == "localFolder"){
+
+                                 $(".new_folder").parent().addClass("folders-loading");
+
+                                 var folderName = $(this).val();
+                                 var folder = (folderName != "" ? folderName : get_lang("New Folder"));
+
+                                 create_new_local_folder((selected_li.attr('id') ? selected_li.attr('id') : "inbox") , folder);
+                                 cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+                            } else {
+
+                                if($(this).val().match(/[\`\~\^\<\>\|\\\"\!\@\#\$\%\&\*\+\(\)\[\]\{\}\?;:]/gi)){
+                                    return write_msg(get_lang("cannot create folder. try other folder name"));
+                                }
+                                if($('[id="'+ (selected_li.attr('id')? selected_li.attr('id') : "INBOX") + cyrus_delimiter + $(this).val()+'"]').length){
+                                    $(".folders-loading").removeClass("folders-loading");
+                                    write_msg(get_lang("Mailbox already exists"));
+                                    return draw_new_tree_folder();
+                                }
+                                $(".new_folder").parent().addClass("folders-loading");
+                                create_new_folder(($(this).val() != "" ? $(this).val() : get_lang("New Folder")), (selected_li.attr('id')? selected_li.attr('id') : "INBOX"));
+                            }
+
+                        }else if( event.keyCode == 27){
+                            draw_new_tree_folder();
+                        }
+
+
+
+                    }).focusout(function(){
+                        draw_new_tree_folder();
+                    });
+                }).end().find(".float-menu-export").click(function(){
+                    //proxy_mensagens.export_all_messages($(this).parents("li:first").attr("id"))
+
+                    var name_box = $(this).parents("li:first").attr("id");
+                    var name_folder = name_box.split(cyrus_delimiter)[name_box.split(cyrus_delimiter).length-1];
+
+                    var hand_export = function(data){
+                        if(!data){
+                            write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'))
+                        }else if(data["empty_folder"]){
+                            write_msg(get_lang("The selected folder is empty."));
+                        }else
+                          download_attachments(null, null, data, null,null, name_folder +'.zip');
+                    }
+                    cExecute("$this.exporteml.export_all",hand_export,"folder="+name_box);  
+                    write_msg(get_lang('You must wait while the messages will be exported...'));        
+                });
+                //FUNÃÃO DO eventNU FLUTUANTE NOVA PASTA < END
+            }
+            if(!$(".new_folder").length){
+                $(this).find(".float-menu:first").css("display", "");
+            }
+        },
+        function(){
+            $(this).find(".float-menu:first").hide();
+        }
+    );
+    $("#new_m").html($('.selected').find(".folder_unseen").html() ? $('.selected').find(".folder_unseen").html() : "0").css("color", "red");
 }
Index: /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/float_folder_menu.ejs
===================================================================
--- /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/float_folder_menu.ejs	(revision 7092)
+++ /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/float_folder_menu.ejs	(revision 7202)
@@ -1,3 +1,3 @@
-<%
+<% 
 	var specialFolders = {
 			INBOX: {name:'Caixa de Entrada'}, 
@@ -5,4 +5,10 @@
 			Root : {name:'root'}
 		};
+    specialFolders["local_messages_trash"] = {name:'Lixeira', classe:'trash'};
+    specialFolders["local_messages_drafts"] = {name:'Rascunhos', classe:'drafts'};
+    specialFolders["local_messages_spam"] = {name:'Spam', classe:'spam'};
+    specialFolders["local_messages_sent"] = {name:'Enviados', classe:'sent'};
+    specialFolders["local_messages_outbox"] = {name:'Enviados', classe:'sent'};
+
 	specialFolders[trashfolder] = {name:'Lixeira', classe:'trash'};
 	specialFolders[draftsfolder] = {name:'Rascunhos', classe:'drafts'};
@@ -12,16 +18,19 @@
 
 <span class="float-menu">
+    <% if(data.name_folder != "local_messages_inbox"){ %>
 	<%if(!data.flag.valid){ %>
+
 		<%if(data.name_folder != 'INBOX'){%>
 			<span class="ui-icon ui-icon-document float-menu-new floating-default" title="<%=get_lang("New Folder")%>"></span>  
 		<%}%>
-		<%if(!specialFolders[data.name_folder]){ %>
+		<%if(!specialFolders[data.name_folder] ){ %>
 			<span class="ui-icon ui-icon-pencil float-menu-edit floating-default" title="<%=get_lang("Edit folder")%>"></span>  
 			<span class="ui-icon ui-icon-close float-menu-remove floating-default" title="<%=get_lang("Delete folder")%>"></span>  
 		<%} 
-		else if(data.name_folder == trashfolder){%>
+		else if(data.name_folder == trashfolder || data.name_folder == "local_messages_trash"){%>
 			<span class="ui-icon ui-icon-trash float-menu-clean floating-default" onclick="empty_trash_imap();" title="<%=get_lang("Empty Trash")%>"></span>  
 		<%}
-		else if(data.name_folder == spamfolder){%>
+		else if(data.name_folder == spamfolder || data.name_folder == "local_messages_spam"){%>
+        
 			<span class="ui-icon ui-icon-trash float-menu-clean floating-default" onclick="empty_spam_imap();" title="<%=get_lang("Empty Spam")%>"></span>  
 			
@@ -45,4 +54,5 @@
 		<%}%>
 	<%}%>
+    <% } %>
 	<span class="ui-icon ui-icon-arrowthickstop-1-n float-menu-export floating-default" title="<%=get_lang("Export folder messages")%>"></span>  
  </span>
Index: /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/detailedfoldertree.ejs
===================================================================
--- /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/detailedfoldertree.ejs	(revision 6773)
+++ /sandbox/2.5.0-expresso1/prototype/modules/mail/templates/detailedfoldertree.ejs	(revision 7202)
@@ -30,4 +30,5 @@
 		  <% }	%>
 		  </span>
+		  <input type="hidden" value="<%= array_trees[i].type %>">
 		  <%
 		  if (array_trees[i].children.length>0)
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7195)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/mail_archiver.js	(revision 7202)
@@ -549,4 +549,31 @@
 
 /**
+ *move Folder
+ *
+ *@author Thiago Rossetto Afonso [thiago@prognus.com.br]
+ *
+ *@param folder_to_move Current folder that will be moved to another folder
+ *@param folder_to Folter that will receive the new folder
+ */
+MailArchiver.prototype.moveFolder = function(folter_to_move, folter_to){
+    try{
+        connector.showProgressBar();
+        ArchiveServices.moveFolder(expresso_mail_archive.getFoldersListOperationOK, expresso_mail_archive.getFoldersListOperationFailure, expresso_mail_archive.session.id, folter_to, folter_to_move);
+    }catch(e){
+        expresso_mail_archive.getFaultInfo();
+    }
+    
+}
+MailArchiver.prototype.getArchiveOperationOK = function(message){
+    document.write("Sucesso, sucesso, sucesso!!!");
+}
+MailArchiver.prototype.getArchiveOperationFailure = function(error_message){
+    alert("Error: " + error_message.getReturn());
+}
+
+
+
+
+/**
  *Unarchieve Message
  *
@@ -1015,4 +1042,5 @@
     //Internal variable used to map all XML data return from WS invokated
     var lfolders = new Array();
+
     
     //Mapping XML data to a handler data structure
@@ -1060,4 +1088,6 @@
             expresso_mail_archive.drawFolderTree();
         }
+    } else {
+        expresso_mail_archive.folders = 0;
     }
     connector.hideProgressBar();
@@ -1204,5 +1234,5 @@
     draw_tree_local_folders();
     expresso_mail_archive.drawdata.treeObject._drawn = true;
-    ttreeBox.update_folder();    
+    //ttreeBox.update_folder();    
 }
 
Index: /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js
===================================================================
--- /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7185)
+++ /sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7202)
@@ -1,4 +1,6 @@
 // Tempo do auto refresh (em milisegundos)
 var time_refresh = 300000;
+//local_messages_inbox
+expresso_mail_archive.createFolder(expresso_mail_archive.sessionid, "Inbox", "testando");
 
 //MAILARCHIVER-01
@@ -15,6 +17,5 @@
 var autosave_time = 40000;
 var results_search_messages = ""; 
-var cabecalho = '<h4>ExpressoLivre - ExpressoMail</h4>'; 
-
+var cabecalho = '<h4>ExpressoLivre - ExpressoMail</h4>';
 var auxNotificationCriteriaVetor = [];
 var auxNotification;
@@ -4673,4 +4674,16 @@
 }
 
+function create_new_local_folder(parentFolderId, name){
+
+    if(typeof(parentFolderId) == "string"){
+        parentFolderId = parentFolderId.split("_");
+        var parentName = parentFolderId[2];
+    }
+    
+
+    expresso_mail_archive.createFolder(parentName, name);
+
+}
+
 function create_new_folder(name_folder, base_path){
 	//Limit reached folders
