Index: /trunk/prototype/modules/mail/js/foldertree.js
===================================================================
--- /trunk/prototype/modules/mail/js/foldertree.js	(revision 5813)
+++ /trunk/prototype/modules/mail/js/foldertree.js	(revision 5844)
@@ -11,12 +11,4 @@
 			element.children = new Array(); 
 			root[i].children.push(element);
-/* 			root[i]['children_unseen'] = (root[i]['children_unseen']? root[i]['children_unseen'] : 0)+ parseInt(element.messageCount.unseen);
-			console.log("=== INI ===");
-			console.log(root[i].id);
-			console.log(root[i].children.length);
-			console.log("=== END ===");
-			for(var k=0; k<root[i].children.length; k++){
-				root[i]['children_unseen'] += (root[i].children[k]['children_unseen'] ? root[i].children[k]['children_unseen'] : 0);
-			} */
 			return true;
 		} else if (ok = unorphanize(root[i].children, element)) {
@@ -419,16 +411,5 @@
 							}
 							$(".new_folder").parent().addClass("folders-loading");
-							$.ajax({
-								url : "controller.php?action=$this.imap_functions.create_mailbox",
-								type : "POST",
-								data : "newp="+($(this).val() != "" ? $(this).val() : get_lang("New Folder"))+"&base_path="+(selected_li.attr('id')? selected_li.attr('id') : "INBOX"),
-								success : function(data){
-									data = connector.unserialize(data);
-									if(data == "Mailbox already exists"){
-										write_msg(get_lang("Mailbox already exists"));
-									}
-									cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
-								}
-							});
+							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();
Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5816)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5844)
@@ -2389,4 +2389,5 @@
 	function get_folders_list($params = null)
 	{
+
 		///Define Variaveis
 		$prefixShared = 'user'; //Prefixo das pastas compartilhadas
@@ -2773,9 +2774,21 @@
                 //build shared folder path
                 $newfolder = "user" . $this->imap_delimiter . $fromaddress[3] . $this->imap_delimiter . $this->imap_sentfolder;
-                if ($this->folder_exists($newfolder))
+
+                if ($this->folder_exists($newfolder)){
+					$has_new_folder = false;
                     $folder = $newfolder;
-                else
-                    $folder = $params['folder'];
+				}
+                else{
+					$name_folder = $this->imap_sentfolder;
+					$base_path = "user" . $this->imap_delimiter . $fromaddress[3];
+					$arr_new_folder['newp'] = $name_folder;
+					$arr_new_folder['base_path'] = $base_path;
+
+					$this->create_mailbox($arr_new_folder);					
+					$has_new_folder = true;
+                    $folder = $newfolder;
+				}
             } else {
+				$has_new_folder = false;
                 $folder = $params['folder'];
             }
@@ -3088,5 +3101,6 @@
                        
                 
-                return array("success" => true);
+                //return array("success" => true, "folder" => $folder_list);
+				return array("success" => true, "load" => $has_new_folder);
                 
             }
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 5835)
+++ /trunk/expressoMail1_2/js/main.js	(revision 5844)
@@ -672,6 +672,5 @@
 }
 
-function delete_msgs(folder, msgs_number, border_ID, show_success_msg,archive){
-						
+function delete_msgs(folder, msgs_number, border_ID, show_success_msg,archive){	
 			if( preferences.use_local_messages == 1 && expresso_local_messages.isArchiving( msgs_number, folder ) ){
 			  alert( "Impossivel deletar mensagens que estão ainda estão sendo arquivadas." );
@@ -686,6 +685,15 @@
  		        if(folder.substr(0,4) == 'user') 
  		        { 
- 		          var arrayFolder = folder.split(cyrus_delimiter); 
- 		          userTrashFolder = 'user'+cyrus_delimiter+arrayFolder[1]+cyrus_delimiter+special_folders['Trash'];  
+					var arrayFolder = folder.split(cyrus_delimiter); 
+					userTrashFolder = 'user'+cyrus_delimiter+arrayFolder[1]+cyrus_delimiter+special_folders['Trash'];  
+					/** TODO Mudar quando melhorias forem implementadas na API de atualização do cache */
+					DataLayer.remove('folder', false);
+					DataLayer.get('folder');
+					
+					var has_folder = DataLayer.get('folder', userTrashFolder);
+					if(!has_folder){
+						create_new_folder(special_folders['Trash'], 'user'+cyrus_delimiter+arrayFolder[1]);
+					}
+					
  		        } 
 				else userTrashFolder = mount_url_folder(["INBOX",special_folders["Trash"]]); 
@@ -2001,4 +2009,8 @@
 
 function send_message_return(data, ID){
+	
+	if (typeof(data) == 'object' && data.load){
+		cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+	}
 	watch_changes_in_msg(ID);
 
@@ -3547,4 +3559,20 @@
 }
 
+function create_new_folder(name_folder, base_path){
+	$.ajax({
+		url : "controller.php?action=$this.imap_functions.create_mailbox",
+		type : "POST",
+		async : false,
+		data : "newp="+name_folder+"&base_path="+base_path,
+		success : function(data){
+			data = connector.unserialize(data);
+			if(data == "Mailbox already exists"){
+				write_msg(get_lang("Mailbox already exists"));
+			}
+			cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);
+		}
+	});
+}
+
 function searchEmail(emailString){
 		var arrayInvalidEmails = new  Array();
@@ -3599,6 +3627,16 @@
 				var prefix = 'INBOX';
 			}else{
-				var prefix = 'user/'+user_selected_name;
-			}
+				var prefix = 'user' + cyrus_delimiter+user_selected_name;
+				
+				/** TODO Mudar quando melhorias forem implementadas na API de atualização do cache */
+				DataLayer.remove('folder', false);
+				DataLayer.get('folder');
+				
+				var has_folder = DataLayer.get('folder', prefix + cyrus_delimiter + draftsfolder);
+				if(!has_folder){
+					create_new_folder(draftsfolder, prefix);
+				}
+			}
+			
             var folder_id = (openTab.imapBox[border_id] && openTab.type[border_id] < 6) ? openTab.imapBox[border_id]: prefix + cyrus_delimiter + draftsfolder;
             form.folder = folder_id;
