Index: /trunk/expressoMail1_2/setup/setup.inc.php
===================================================================
--- /trunk/expressoMail1_2/setup/setup.inc.php	(revision 271)
+++ /trunk/expressoMail1_2/setup/setup.inc.php	(revision 320)
@@ -12,5 +12,5 @@
 	$setup_info['expressoMail1_2']['name']      	= 'expressoMail1_2';
 	$setup_info['expressoMail1_2']['title']     	= 'ExpressoMail 1.2';
-	$setup_info['expressoMail1_2']['version']   	= '1.2211';
+	$setup_info['expressoMail1_2']['version']   	= '1.222';
 	$setup_info['expressoMail1_2']['app_order'] 	= 2;
 //	$setup_info['expressoMail1_2']['tables'][]    	= 'phpgw_expressoMail1_2';
Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 278)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 320)
@@ -275,5 +275,8 @@
 					$return['toaddress2'] .= " ";
 					$return['toaddress2'] .= "&lt;";
-					$return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host;
+					if ($tmp->host != 'unspecified-domain')
+						$return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host;
+					else
+						$return['toaddress2'] .= $tmp->mailbox;
 					$return['toaddress2'] .= "&gt;";
 					$return['toaddress2'] .= ", ";
@@ -281,5 +284,8 @@
 				else
 				{
-					$return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host;
+					if ($tmp->host != 'unspecified-domain')
+						$return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host;
+					else
+						$return['toaddress2'] .= $tmp->mailbox;
 					$return['toaddress2'] .= ", ";
 				}
@@ -351,4 +357,5 @@
 		$return['Size'] = $header->Size;
 		$return['reply_toaddress'] = $header->reply_toaddress;
+		
 		return $return;
 	}
@@ -1471,4 +1478,5 @@
 		$ccaddress = $params['input_cc'];
 		$subject = $params['input_subject'];
+		$msg_uid = $params['msg_id'];
 		$body = $params['body'];
 		$body = str_replace("%nbsp;","&nbsp;",$params['body']);
@@ -1507,4 +1515,54 @@
 		$mail->Body = $body;
 		
+		//	Build CID for embedded Images!!!
+		$pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&amp;msg_num=(.+)?&amp;msg_part=(.+)?)"/isU';
+		$cid_imgs = '';
+		$name_cid_files = array();
+		preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);
+		$cid_array = array();
+		foreach($cid_imgs[4] as $j => $val){
+				if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) )
+      			{
+                $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36);
+		        }
+		        $cid = $cid_array[$cid_imgs[3][$j].$val]; 
+        		$mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);
+        		
+				if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail?
+				{
+					$fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64');
+					$fileName = "image_".($j).".jpg";
+					$fileCode = "base64";
+					$fileType = "image/jpg";
+				}
+				else
+				{
+					$attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2];
+					$file_description = unserialize(rawurldecode($attach_img));
+					foreach($file_description as $i => $descriptor){				
+						$file_description[$i]  = eregi_replace('\'*\'','',$descriptor);
+					}
+					$fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64');
+					$fileName = $file_description[2];
+					$fileCode = $file_description[4];
+					$fileType = $this->get_file_type($file_description[2]);
+					unset($forwarding_attachments[$cid_imgs[4][$j]-2]);
+					if (!empty($file_description))
+					{
+						$file_description[5] = strlen($fileContent); //Size of file
+						$return_forward[] = $file_description;
+					}
+				}
+				$tempDir = ini_get("session.save_path");
+				$file = "cid_image_".base_convert(microtime(), 10, 36).".dat";					
+				$f = fopen($tempDir.'/'.$file,"w");
+				fputs($f,$fileContent);
+				fclose($f);
+				if ($fileContent)
+					$mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);
+				//else
+				//	return "Error loading image attachment content";						
+
+		}
 	
 	//	Build Forwarding Attachments!!!		
@@ -1757,12 +1815,18 @@
 		$search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false;
 		$sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);				
-		$i = 0;
-		
-		while($sort_array_msg[$i] != $msg_number)
-		{
-			$i++;
-		}
-
-		if ($i == (count($sort_array_msg)-1))
+		
+		$success = false;
+		if (is_array($sort_array_msg))
+		{
+			foreach ($sort_array_msg as $i => $value){
+				if ($value == $msg_number)
+				{
+					$success = true;
+					break;
+				}
+			}
+		}
+
+		if (! $success || $i >= sizeof($sort_array_msg)-1)
 		{
 			$params['status'] = 'false';
@@ -1789,12 +1853,18 @@
 		$search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false;
 		$sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse);
-		$i = 0;
-		
-		while($sort_array_msg[$i] != $msg_number)
-		{
-			$i++;
-		}
-		
-		if ($i == 0){
+		
+		$success = false;
+		if (is_array($sort_array_msg))
+		{
+			foreach ($sort_array_msg as $i => $value){
+				if ($value == $msg_number)
+				{
+					$success = true;
+					break;
+				}
+			}
+		}
+		if (! $success || $i == 0)
+		{
 			$params['status'] = 'false';
 			$params['command_to_exec'] = "delete_border('". $reuse_border ."');";
Index: /trunk/expressoMail1_2/inc/class.ScriptS.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.ScriptS.inc.php	(revision 122)
+++ /trunk/expressoMail1_2/inc/class.ScriptS.inc.php	(revision 320)
@@ -96,5 +96,5 @@
 		
 		$narray  = explode("_end_",$var_decode);
-		
+
 		foreach($narray as $key=>$tmp){
 			if($tmp != ""){
@@ -196,10 +196,11 @@
 	          $special_char = false;
 		  for ( $i = 0; $i < strlen($input); $i++ )
-		      if ( preg_match('/[ÁáÉéÍíÓóÚúÀàÈèÌìÒòÙùÇçÃãÕõÂâÊêÔô]/', $input[$i]) )
+		      if ( preg_match('/[ÁáÉéÍíÓóÚúÀàÈèÌìÒòÙùÇçÃãÕõÂâÊêÔô®©§ªºÐ¹²³°¢¿Æ£µøæß«»Ø÷±¬]/', $input[$i]) )
 		      {
 		          $special_char = true;
 		          $input = preg_replace('/'.$input[$i].'/', '=' . bin2hex($input[$i]), $input);
 		      }
-                   if ( $special_char )
+		      
+           if ( $special_char )
 		   {
 		   /*  When using arrays with pattern and replacement, the keys are processed in the order they appear in the array. See preg_replace in php.net/preg_replace */
@@ -210,5 +211,8 @@
 		   $input = preg_replace($patterns, $replacements, $input);
 		   }
-                   return($input);
+		   if (($input{0}) && (!eregi('^[a-zA-Z0-9=-]+$',$input)))
+				return false;	
+			else
+           		return($input);
         }
 
@@ -233,7 +237,7 @@
           $rule['from'] 	     = $this->convert_specialchar($tmp1[3]);
           $rule['to']            = $this->convert_specialchar($tmp1[4]);
-	  $rule['subject'] = $this->convert_specialchar($tmp1[5]);
+	 	  $rule['subject'] = $this->convert_specialchar($tmp1[5]);
           $rule['action'] 	     = $tmp1[6];
-	  $rule['action_arg']    = utf8_encode(preg_replace("/\\r\\n/","\r\n",$tmp1[7]));
+		  $rule['action_arg']    = utf8_encode(preg_replace("/\\r\\n/","\r\n",$tmp1[7]));
           $rule['flg'] 		     = $tmp1[8];   
           $rule['field'] 		 = $tmp1[9];
Index: /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 271)
+++ /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 320)
@@ -554,5 +554,5 @@
 					);
 
-				$_SESSION['phpgw_info']['expressomail']['contact_photo'] = ldap_get_values_len($ds, $entry, "jpegphoto");
+				$_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto");
 				ldap_close($ds);
 				return $obj;
Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 271)
+++ /trunk/expressoMail1_2/js/search.js	(revision 320)
@@ -9,5 +9,4 @@
 		this.fields = new Array("_ass","_de","_body","_para","_cc","_cco");
 	}
-	var search_tabs = 0; // Count the number of seach tabs
 	
 	//Monta os forms dentro da janela;
@@ -261,8 +260,8 @@
 			}
 		}
-		search_tabs += 1;
-		var border_id = create_border(get_lang("Search Results"), "search_" + search_tabs);
+		numBox++;
+		var border_id = create_border(get_lang("Search Results"), "search_" + numBox);
 		var table = document.createElement("TABLE");
-		table.id    = "table_resultsearch_" + search_tabs;
+		table.id    = "table_resultsearch_" + numBox;
 		table.width = "100%";
 		table.borderColorDark = "#bbbbbb";
@@ -273,5 +272,5 @@
 
 		var tbody = document.createElement("TBODY");
-		tbody.id    = "tbody_resultsearch_" + search_tabs;
+		tbody.id    = "tbody_resultsearch_" + numBox;
 		if(nw_array.length > 0){
 			write_msg(nw_array.length + " "+ get_lang('results found'));			
@@ -309,5 +308,5 @@
 						td.style.width = "1%";					
 						var subject_encode = url_encode(aux[2]);
-						var td1 = '<input type="checkbox" id="check_box_search_message_'+tr.id+'"></input>';
+						var td1 = '<input type="checkbox" id="check_box_message_'+tr.id.substr(tr.id.indexOf(';')+1)+'"></input>';
 					}
 					if( j == 1){
@@ -355,11 +354,10 @@
 		subject = tr.firstChild;
 		subject = subject.nextSibling.nextSibling.nextSibling.firstChild.firstChild.innerHTML;
-//		_dragArea.makeDragged(tr, msg_number, subject, true);
-		_dragArea.makeDragged(tr, tr.firstChild.firstChild.id.substr(tr.firstChild.firstChild.id.indexOf(';')+1), subject, true);
+		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
 		tbody.appendChild(tr);
 		}
 		table.appendChild(tbody);
 		
-	var content_search =  Element('content_id_' + "search_" + search_tabs);	
+	var content_search =  Element('content_id_search_' + numBox);	
 	// BEGIN MAKE THE SCROLL HEIGHT		
 	var defaultWidth = document.body.offsetWidth - 31;	
@@ -372,5 +370,5 @@
 		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;		
 	var div_scroll_result = document.createElement("DIV");
-	div_scroll_result.id = "div_result_scroll_"+search_tabs;
+	div_scroll_result.id = "divScrollMain_"+numBox;
 	div_scroll_result.style.background = 'WHITE';
 	div_scroll_result.style.height = document.body.clientHeight - offset - 120;
Index: /trunk/expressoMail1_2/js/drag_area.js
===================================================================
--- /trunk/expressoMail1_2/js/drag_area.js	(revision 2)
+++ /trunk/expressoMail1_2/js/drag_area.js	(revision 320)
@@ -3,4 +3,5 @@
 	this.msg_number = false;
 	this.subject	= false;
+	this.folder		= '';
 	this.color_dd	= 'red';
 	this.from_list	= false;
@@ -27,5 +28,30 @@
 }
 
-DragArea.prototype.makeDragged = function(element, msg_number, subject, from_list){
+DragArea.prototype.makeMenuBox = function(element){
+
+	element.oncontextmenu = function(e)
+	{
+		return false;
+	}
+	
+	var _this = this;
+	
+	element.onmousedown = function (e)
+	{
+		var _button = is_ie ? window.event.button : e.which;
+
+		if(_button == 2 || _button == 3)
+		{
+			var boxFolder = element.id.substr(1,element.id.indexOf('tree_folders')-1);
+			var boxName = element.firstChild.nextSibling.innerHTML;
+			ConstructBoxMenu(is_ie ? window.event : e,boxName,boxFolder);
+		}
+				
+		return true;
+	};	
+	
+}
+
+DragArea.prototype.makeDragged = function(element, msg_number, subject, from_list, folder){
 	element.oncontextmenu = function(e) {
 		return false;
@@ -62,4 +88,5 @@
 			_this.div_dd.style.width = "auto";
 			_this.div_dd.style.height = "auto";			
+			_this.folder = folder;
 		}
 		return true;
@@ -69,6 +96,7 @@
 
 	var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
-	if(_dragArea.from_list) {	
-		if(! Element("check_box_message_"+msg_number).checked) {
+	if(_dragArea.from_list) {
+
+		if((Element("check_box_message_"+msg_number)) && (! Element("check_box_message_"+msg_number).checked)) {
 			if (is_ie)
 				changeBgColor(window.event,msg_number);
@@ -148,5 +176,6 @@
 	if(_button != 2 && _button != 3) {		
 
-		if(Element("div_rightbutton") && Element("div_rightbutton").style.display != 'none') {
+		if(Element("div_rightbutton") && Element("div_rightbutton").style.display != 'none')
+		{
 						
 			if(!_target.id.match(/link_rightbutton_(.*)$/)){
@@ -168,4 +197,10 @@
 		if(is_ie)
 			_dragArea.onSelectStart(true);
+	
+		if (Element("div_rightbutton_folder") && Element("div_rightbutton_folder").style.display != 'none')
+		{	
+		Element('div_rightbutton_folder').style.display = 'none';
+		}
+	
 	}	
 
@@ -183,8 +218,8 @@
 				
 			if(_dragArea.from_list)
-				move_msgs('null', 'selected', 'null', new_folder, new_folder_name);
-			else {
+				move_msgs(_dragArea.folder, 'selected', numBox, new_folder, new_folder_name);
+			else{
 				var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
-				move_msgs('null', msg_number, msg_number+"_r", new_folder, new_folder_name);
+				move_msgs(_dragArea.folder, msg_number, msg_number+"_r", new_folder, new_folder_name);
 			}
 		}
Index: /trunk/expressoMail1_2/js/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/abas.js	(revision 271)
+++ /trunk/expressoMail1_2/js/abas.js	(revision 320)
@@ -11,4 +11,6 @@
 function alternate_border(ID)
 {
+	if (! Element('border_id_'+ID))
+		return false; // Not possible to alternate
 	Element("footer_menu").style.display = (ID != "0" ? 'none' : '');
 	var len = BordersArray.length;
@@ -16,5 +18,5 @@
 	{
 		m = document.getElementById(BordersArray[i].border_id);
-		if (m.className == 'menu-sel')
+		if ((m)&&(m.className == 'menu-sel'))
 		{
 			m.className = 'menu';
@@ -43,9 +45,11 @@
 
 	m = Element("border_id_"+ID);
-	m.className = 'menu-sel';
+	if (m)
+		m.className = 'menu-sel';
 	if(Element("font_border_id_" + ID))
 		Element("font_border_id_" + ID).className = 'font-menu-sel';
 	var c = Element("content_id_"+ID)
-	c.style.display = '';
+	if (c)
+		c.style.display = '';
 
 	body = document.getElementById('body_'+ ID);
@@ -68,5 +72,10 @@
 		window_DropDownContacts.style.visibility = 'hidden';
 	}
-	
+
+	if (typeof(ID) == 'number')
+	{
+	 	current_folder = openBox.tab_folder[ID];
+	 	numBox=ID;
+ 	}
 	return ID;
 }
@@ -89,5 +98,5 @@
 	else{
 		var ID = id_value;
-		if (document.getElementById("border_id_"+id_value+"_r")) // Edit message? if yes treat like new
+		if (document.getElementById("border_id_"+id_value+"_r")) // Edit message? if yes treat like new in dragdrop case
 					var id_value = null;
 	}
@@ -123,5 +132,5 @@
 	parent_bb.insertBefore(td, bb);
 	
-	if(id_value && id_value.match(/_r$/))	
+	if((typeof(id_value) == 'string') && id_value.match(/_r$/))	
 		_dragArea.makeDragged(td, id_value,td.value);
 
@@ -139,5 +148,5 @@
 		
 	div.style.height = document.body.clientHeight - offset - (is_ie ? 76 : 86);
-	div.style.overflow = "auto";
+	div.style.overflow = "hidden";
 
 	if(!is_ie) {
@@ -187,4 +196,6 @@
 	if(!ID)
 		return false;
+
+	Element("border_id_" + ID).onclick = null;
 	
 	if (msg_sent == 'false')
@@ -205,6 +216,8 @@
 					else
 					{
-						if (! newMessageTab.toPreserve[ID])
-							cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[ID]+"&msgs_number="+newMessageTab.imapUid[ID],function(data){ return });
+						if (newMessageTab.imapBox[ID] && ! newMessageTab.toPreserve[ID]){
+							delete_msgs(newMessageTab.imapBox[ID], newMessageTab.imapUid[ID].toString(), 0)
+							}
+							//cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[ID]+"&msgs_number="+newMessageTab.imapUid[ID],function(data){ return });
 						Element('to_'+ID).focus();
 					}
@@ -224,5 +237,5 @@
 	{
 		m = document.getElementById(BordersArray[i].border_id);
-		if (m.className == 'menu-sel')
+		if ((m) && (m.className == 'menu-sel'))
 			border_selected = BordersArray[i].border_id;
 	}
@@ -237,8 +250,8 @@
 
 	// Remove TD, title
-	border = document.getElementById('border_id_' + ID);
+	border = Element('border_id_' + ID);
 	border.parentNode.removeChild(border);
 	// Remove Div Content
-	content = document.getElementById('content_id_' + ID);
+	content = Element('content_id_' + ID);
 	content.parentNode.removeChild(content);
 	
@@ -247,5 +260,5 @@
 	for (i=0;i<BordersArray.length;i++)
 	{
-		if (document.getElementById(BordersArray[i].border_id) != null){
+		if (Element(BordersArray[i].border_id) != null){
 			new_BordersArray[j] = BordersArray[i];
 			j++;	
@@ -255,3 +268,4 @@
 		Element("footer_menu").style.display = '';
 	BordersArray = new_BordersArray;
-}
+	return true;
+}
Index: /trunk/expressoMail1_2/js/InfoContact.js
===================================================================
--- /trunk/expressoMail1_2/js/InfoContact.js	(revision 72)
+++ /trunk/expressoMail1_2/js/InfoContact.js	(revision 320)
@@ -48,5 +48,5 @@
 	}
 	div_label.innerHTML = text;
-	div_label.style.top = findPosY(this.td) + 20 - Element("divScrollMain").scrollTop;
+	div_label.style.top = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
 	div_label.style.left = findPosX(this.td) + 20;
 	div_label.style.display = '';
@@ -73,5 +73,5 @@
 	 {
 		card.style.left = findPosX(this.td) + 20;
-		var y = findPosY(this.td) + 20 - Element("divScrollMain").scrollTop;
+		var y = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
 		var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
 		if(y + 160 > w_height)
Index: /trunk/expressoMail1_2/js/shortcut.js
===================================================================
--- /trunk/expressoMail1_2/js/shortcut.js	(revision 163)
+++ /trunk/expressoMail1_2/js/shortcut.js	(revision 320)
@@ -250,4 +250,5 @@
 		var selected_shortcut_msgs = '';
 		var current_folder = get_current_folder();
+		var tbody_box = Element('tbody_box');
 		all_messages = Element('tbody_box').childNodes;
 		
Index: /trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- /trunk/expressoMail1_2/js/common_functions.js	(revision 271)
+++ /trunk/expressoMail1_2/js/common_functions.js	(revision 320)
@@ -16,4 +16,18 @@
 
 window.onresize = resizeWindow;
+
+function config_events(pObj, pEvent, pHandler)
+{
+    if( typeof pObj == 'object')
+    {
+        if( pEvent.substring(0, 2) == 'on')
+            pEvent = pEvent.substring(2, pEvent.length);
+
+        if ( pObj.addEventListener )
+            pObj.addEventListener(pEvent, pHandler, false);
+        else if( pObj.attachEvent )
+            pObj.attachEvent('on' + pEvent, pHandler );
+    }
+}
 
 function resizeWindow(){
@@ -38,21 +52,18 @@
 	}
 	Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
-	if(Element("divScrollMain"))
-		Element("divScrollMain").style.height 	= defaultHeight - (is_ie ? 111 : 110);	
+	if(Element("divScrollMain_"+numBox))
+		Element("divScrollMain_"+numBox).style.height 	= defaultHeight - (is_ie ? 111 : 110);	
 }
 // END: FUNCTION RESIZE WINDOW
 
 // onUnload edit message
-if(!is_ie)
+
+var _beforeunload_ = window.onbeforeunload;
+
+window.onbeforeunload = function()
 {
-	var beforeunload = window.onbeforeunload;
-	window.onbeforeunload = function()
-	{
-		if ( typeof beforeunload == 'function' )
-			beforeunload();
-
-		return unloadMess();
-	};
-}
+	return unloadMess();
+}
+
 function unloadMess(){
 	var mess = get_lang("Your message has not been sent and will be discarted.");
@@ -64,4 +75,5 @@
 	}
 }
+
 // Translate words and phrases using user language from eGroupware.
 function get_lang(_key,_arg1,_arg2,_arg3,_arg4) {
@@ -143,4 +155,6 @@
 	if (box != null)
 		box.parentNode.removeChild(box);
+	else
+		return false;
 }
 
@@ -189,4 +203,6 @@
 function addFile(id_border){
 	divFiles = document.getElementById("divFiles_"+id_border);
+	if (! divFiles)
+		return false;
 	
 	if (divFiles.lastChild)
@@ -216,5 +232,5 @@
 	linkFile.id = "linkFile_"+id_border+"_"+countDivFiles;
 	linkFile.href='javascript:void(0)';
-	linkFile.onclick=function () {removeFile(this.id.replace("link","div"));};
+	linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
 	linkFile.innerHTML=get_lang("Remove");	
 	//divFile.innerHTML += "&nbsp;&nbsp;";
@@ -231,12 +247,19 @@
 
 function validateFileExtension(fileName, id, id_border){
+	
 	var error_flag  = false;
-	if (fileName[0] != '/'){ // file name is windows format?
-		var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
-		if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
-			error_flag = true;	
-	}
-	else // is nix
-		var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);						
+
+	if ( fileName.indexOf('/') != -1 )
+	{
+		if (fileName[0] != '/'){ // file name is windows format?
+			var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
+			if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
+				error_flag = true;	
+		}
+		else // is Unix
+			var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);						
+	}
+	else  // is Firefox 3
+		var file = fileName;
 
 	var fileExtension = file.split(".");
@@ -252,5 +275,6 @@
 	}
 
-	if (error_flag == true){
+	if ( error_flag == true )
+	{
 		alert(get_lang('File extension forbidden or invalid file') + '.');
 		removeFile(id);
@@ -259,5 +283,4 @@
 	}
 	return true;
-	
 }
 
@@ -635,5 +658,6 @@
 function remove_className(obj, className){
 	var re = new RegExp("\\s*"+className);
-	obj.className = obj.className.replace(re, '');
+	if (obj)
+		obj.className = obj.className.replace(re, '');
 }
 
Index: /trunk/expressoMail1_2/js/TreeS.js
===================================================================
--- /trunk/expressoMail1_2/js/TreeS.js	(revision 197)
+++ /trunk/expressoMail1_2/js/TreeS.js	(revision 320)
@@ -128,4 +128,5 @@
 		
 		folders_tree = new dFTree({name: name_tree});
+
 		if(click_root != ""){
 			var n_root = new dNode({id:'root', caption:get_lang("My Folders"), onClick:click_root});
@@ -134,5 +135,5 @@
 		}
 		folders_tree.add(n_root,'root'); //Places the root; second argument can be anything.
-		
+
 		if(data.length == 0){
 			alert("sem dados");
@@ -161,20 +162,4 @@
 		}
 		
-/* 		if(folders_tree._folderPr.length > 0 && destination == "div_tree"){
-			var nw_rt = new dNode({id:'proble', caption:'<font style=color:red><b>' + get_lang('Problems') + '</b></font>', plusSign:true});		
-			folders_tree.add(nw_rt,'root');
-
-			for(var i=0; i < folders_tree._folderPr.length; i++){
-				var nm_fl = folders_tree._folderPr[i].split(cyrus_delimiter);
-				if( nm_fl[0] == "INBOX")
-					var nm = folders_tree._folderPr[i].substr(6,folders_tree._folderPr[i].length);
-				else
-					var nm = folders_tree._folderPr[i].substr(5,folders_tree._folderPr[i].length);
-				var nw_rm = new dNode({id:folders_tree._folderPr[i], caption:nm, plusSign:false});
-				folders_tree.add(nw_rm,'proble');
-			}
-			folders_tree._folderPr.splice(0,folders_tree._folderPr.length);
-		} 
-		*/
 		folders_tree.draw(Element(destination));
 		n_root.changeState();
Index: /trunk/expressoMail1_2/js/globals.js
===================================================================
--- /trunk/expressoMail1_2/js/globals.js	(revision 248)
+++ /trunk/expressoMail1_2/js/globals.js	(revision 320)
@@ -4,5 +4,5 @@
 var hold_session = false;
 var current_page = 1;
-var current_folder = 'INBOX';
+var current_folder = '';
 var id_menu_folders = '';
 var preferences = '';
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 271)
+++ /trunk/expressoMail1_2/js/main.js	(revision 320)
@@ -1,5 +1,7 @@
 // Tempo do auto refresh (em milisegundos)
 var time_refresh = 300000;
-var autosave_time = 60000;
+// tempo do auto save (em milisegundos)
+// 20000 = 20 segundos
+var autosave_time = 20000;
 
 function init(){
@@ -35,46 +37,7 @@
 	cyrus_delimiter = Element('cyrus_delimiter').value;
 	
-	alternate_border(0);
 	cExecute ("$this.db_functions.get_dropdown_contacts", save_contacts);
 	cExecute ("$this.functions.get_preferences", save_preferences);
 	setTimeout('auto_refresh()', time_refresh);
-}
-
-var away = false;
-var away_timer;
-function setAway ()
-{
-	away_timer = setTimeout("setAway()", 5000);
-	away=true;
-}
-
-function auto_save_msg(border_id)
-{
-	if (document.getElementById('border_id_'+border_id))
-	{	
-		var	 keypress_handler = function stop_counting ()
-		{
-			clearTimeout(away_timer);
-			away=false;
-			away_timer = setTimeout('setAway()',5000);
-		};
-		
-		var obj = document.getElementById('body_'+border_id).contentWindow.document;
-		if ( obj.addEventListener )
-				obj.addEventListener('keypress', keypress_handler, false);
-		else if ( obj.attachEvent )
-			obj.attachEvent('onkeypress', keypress_handler);
-
-		if (away)
-			{
-				var save_link = Element("save_message_options");
-				if (save_link.onclick !=  '')
-					save_msg(border_id);
-				else
-					setTimeout('auto_save_msg('+border_id+')',autosave_time);
-			}
-			else
-				setTimeout('auto_save_msg('+border_id+')',3000);
-	}
 }
 
@@ -158,5 +121,7 @@
 		
 		if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
-			cExecute ("$this.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
+		/*	var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), "");
+			if (confNotification)*/
+				cExecute ("$this.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
 		}
 	}
@@ -285,5 +250,5 @@
 	var main_list = Element("tbody_resultsearch_"+border_id.substr(18)).childNodes;	
 	for (j = 0; j < main_list.length; j++)	{
-		var check_box = Element("check_box_search_message_"+main_list[j].id);
+		var check_box = Element("check_box_message_"+main_list[j].id);
 		if(check_box && check_box.checked) {
 			selected_messages += main_list[j].id + ',';
@@ -334,19 +299,37 @@
 function move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name){
 
-	if (folder == 'null')
-		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : get_current_folder();			
-
+	if (! folder || folder == 'null')
+		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : get_current_folder();
+	
 	var handler_move_msgs = function(data){
-
-		if(typeof(data) == 'string' && data.match(/^(.*)TRYCREATE(.*)$/)){
-			var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : "Lixeira";
-			alert(get_lang('Its %1 folder is not created. It is necessary to create so that it functions correctly.', move_to_folder));
-			return false;
-		}
+		if(typeof(data) == 'string')
+			if (data.match(/^(.*)TRYCREATE(.*)$/)){
+				connector.loadScript('TreeS');
+				var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : trashfolder;
+				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.', move_to_folder));
+				connector.loadScript('TreeShow');
+				ttree.FOLDER = 'root';
+				ttreeBox.new_past(move_to_folder);
+				return false;
+			}else{
+				alert(data);
+				return false;
+			}
+
 
 		Element('chk_box_select_all_messages').checked = false;
 		mail_msg = Element("tbody_box");
+		//mail_msg = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
 		data.msgs_number = data.msgs_number.split(",");
-		
+
+		var msg_to_delete;		
+		all_search_msg = msgs_number.split(',');
+		for (var i=0; i <= all_search_msg.length; i++)
+		{
+			msg_to_delete = Element(folder+';'+all_search_msg[i]); 
+			if (msg_to_delete)
+				msg_to_delete.parentNode.removeChild(msg_to_delete);
+		}
+
 		if ( preferences.use_shortcuts == '1') {
 			var all_messages = Element('tbody_box').childNodes;
@@ -363,5 +346,4 @@
 		}
 
-		var msg_to_delete;		
 		for (var i=0; i<data.msgs_number.length; i++)
 		{
@@ -370,4 +352,5 @@
 				mail_msg.removeChild(msg_to_delete);
 		}
+		
 
 		if (data.msgs_number.length == 1)
@@ -375,6 +358,5 @@
 		else
 			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-
-		if (data.border_ID != '' && data.border_ID != 'null'){
+		if (data.border_ID.indexOf('r') != -1){
 			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder())
 				show_msg(data.previous_msg);
@@ -399,12 +381,14 @@
 	else
 		write_msg(get_lang('No selected message.'));		
+		
 }
 
 function get_selected_messages(){
 	main = Element("tbody_box");
-	
+//	main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
+
 	// Get all TR (messages) in tBody.
 	main_list = main.childNodes;
-	
+
 	var selected_messages = '';
 	var selected_messages_by_shortcuts = '';
@@ -412,9 +396,16 @@
 	for (j; j<(main_list.length); j++)
 	{
+	if (main_list[j].id.indexOf(';') == -1)
+	{
 		check_box = Element("check_box_message_"+main_list[j].id);
 		if ( (check_box) && (check_box.checked) )
-		{
 			selected_messages += main_list[j].id + ',';
-		}
+	}
+	else
+	{ // Message from search tab
+		check_box = Element("check_box_message_"+main_list[j].id.substr(main_list[j].id.indexOf(';')+1));
+		if ( (check_box) && (check_box.checked) )
+			selected_messages += main_list[j].id.substr(main_list[j].id.indexOf(';')+1) + ',';
+	}
 		
 		if (preferences.use_shortcuts == '1')
@@ -450,6 +441,4 @@
 
 	var new_border_ID = draw_new_message(parseInt(border_ID));
-	if (preferences.auto_save_draft == 1)
-		setTimeout('auto_save_msg('+new_border_ID+')', autosave_time);		
 	
 	// Salva a pasta da mensagem respondida ou encaminhada:
@@ -466,29 +455,25 @@
 	data = [];
 	if (Element("from_" + border_ID)){
-		if (document.getElementById("reply_to_" + border_ID)){
-			data.to = document.getElementById("reply_to_values_" + border_ID).value;
-			data.to = data.to.replace(/&lt;/gi,"<");
-			data.to = data.to.replace(/&gt;/gi,">");
+			if (document.getElementById("reply_to_" + border_ID)){
+				data.to = document.getElementById("reply_to_values_" + border_ID).value;
+				data.to = data.to.replace(/&lt;/gi,"<");
+				data.to = data.to.replace(/&gt;/gi,">");
 		}
 		else {
-			data.to = document.getElementById("from_values_" + border_ID).value;
-			data.to = data.to.replace(/&lt;/gi,"<");
-			data.to = data.to.replace(/&gt;/gi,">");
+			if (document.getElementById("from_values_" + border_ID))
+			{
+				data.to = document.getElementById("from_values_" + border_ID).value;
+				data.to = data.to.replace(/&lt;/gi,"<");
+				data.to = data.to.replace(/&gt;/gi,">");
+			}
 		}	
 		
-		data.to_all = document.getElementById("to_values_" + border_ID).value;
-		data.to_all = data.to_all.replace(/\n/gi," ");		
-		data.to_all = data.to_all.replace(/&lt;/gi,"<");
-		data.to_all = data.to_all.replace(/&gt;/gi,">");
-		// delete user email from to_all array.
-		var _array_to_all = data.to_all.split(",");
-		data.to_all = new Array();
-		var j = 0;
-		for(i = 0; i < _array_to_all.length; i++) {			
-			if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
-				data.to_all[j++] = _array_to_all[i];
-			}
-		}
-		data.to_all = data.to_all.join(",");
+		if (document.getElementById("to_values_" + border_ID)){
+			data.to_all = document.getElementById("to_values_" + border_ID).value;
+			data.to_all = data.to_all.replace(/\n/gi," ");		
+			data.to_all = data.to_all.replace(/&lt;/gi,"<");
+			data.to_all = data.to_all.replace(/&gt;/gi,">");
+			var _array_to_all = data.to_all.split(",");
+		}	
 	}
 	
@@ -561,4 +546,14 @@
 			break;
 		case "reply_to_all_without_history":
+			// delete user email from to_all array.
+			data.to_all = new Array();
+			var j = 0;
+			for(i = 0; i < _array_to_all.length; i++) {			
+				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
+					data.to_all[j++] = _array_to_all[i];
+				}
+			}
+			data.to_all = data.to_all.join(",");
+
 			title = "Re: " + data.subject;
 			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
@@ -590,4 +585,13 @@
 			break;
 		case "reply_to_all_with_history":
+			// delete user email from to_all array.
+			data.to_all = new Array();
+			var j = 0;
+				for(i = 0; i < _array_to_all.length; i++) {			
+				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
+					data.to_all[j++] = _array_to_all[i];
+				}
+			}
+			data.to_all = data.to_all.join(",");
 			title = "Re: " + data.subject;
 			Element("to_" + new_border_ID).value = data.to;
@@ -680,5 +684,6 @@
 			break;
 		case "edit":
-			newMessageTab.imapBox[new_border_ID] = folder_message.value
+			newMessageTab.imapBox[new_border_ID] = folder_message.value;
+			newMessageTab.toPreserve[new_border_ID] = true;
 			newMessageTab.imapUid[new_border_ID] = parseInt(border_ID.substr(0,border_ID.indexOf("_")));
 			document.getElementById('font_border_id_'+new_border_ID).innerHTML = data.subject;
@@ -728,5 +733,20 @@
 		default:
 	}
-	
+
+	if (preferences.auto_save_draft == 1)
+    {
+        var time_auto_save = false;
+        var save_link = document.getElementById("save_message_options");
+
+        function auto_sav()
+        {
+            if ( time_auto_save )
+                clearTimeout(time_auto_save);
+
+            time_auto_save = setTimeout("save_msg("+new_border_ID+")", autosave_time);
+        }
+        config_events(body.contentWindow.document,'keypress', auto_sav);
+    }
+
 	//BEGIN Tab event
 	if (preferences.use_shortcuts == '1')
@@ -792,4 +812,6 @@
 			write_msg(get_lang('Your message was sent.'));		
 		}
+		if ((! newMessageTab.toPreserve[ID]) && (newMessageTab.imapUid[ID] != 0))
+			cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[ID]+"&msgs_number="+newMessageTab.imapUid[ID],function(data){ return });
 	}
 	else{			
@@ -801,6 +823,4 @@
 			write_msg(data);
 	}
-	if ((! newMessageTab.toPreserve[ID]) && (newMessageTab.imapUid[ID] != 0))
-		cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[ID]+"&msgs_number="+newMessageTab.imapUid[ID],function(data){ return });
 }
 
@@ -856,10 +876,28 @@
 {
 	var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg); };
-	RichTextEditor.saveFlag = 1;
-
-	if (! data)
-		write_msg('ERROR saving your message.');
-	else
+
+	if (data.append != true || !data)
 	{
+		RichTextEditor.saveFlag = -1;
+		if (! data.append)
+			write_msg('ERROR saving your message.');
+		else
+		{
+			if (data.append.match(/^(.*)TRYCREATE(.*)$/))
+			{
+				connector.loadScript('TreeS');
+				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.',draftsfolder));
+				connector.loadScript('TreeShow');
+				ttree.FOLDER = 'root';
+				ttreeBox.new_past(draftsfolder);
+				setTimeout('save_msg('+border_id+')',3000);
+			}
+			else
+				write_msg(data.append);
+		}
+	}
+	else
+	{
+		RichTextEditor.saveFlag = 1;
 		newMessageTab.imapUid[border_id] = data.msg_no;
 		newMessageTab.imapBox[border_id] = data.folder_id;
@@ -876,4 +914,5 @@
 		var content_body =  mainField.document.getElementsByTagName('body').item(0).innerHTML;
 		var body_images = content_body.match(/msg_num=\d*/g);
+		var images_part = content_body.match(/msg_part=\d*/g);
 		if (body_images)
 		{
@@ -881,7 +920,29 @@
 				content_body = 	content_body.replace(body_images[i],"msg_num="+newMessageTab.imapUid[border_id]);
 			}
+			var allImgs = new Array (images_part.length);
+				var j=-1;
+				for (var i in images_part){
+				
+					if (is_ie)
+						if (i == 0)
+							var image_number = parseInt(images_part[i].substr(9));
+						else
+							image_number = "null";
+					else
+						var image_number = parseInt(images_part[i].substr(9));
+					
+				if (! isNaN(image_number))
+					{
+						if (! allImgs[image_number])
+						{
+							allImgs[image_number] = true;
+							j--;					
+						}
+					content_body = content_body.replace(images_part[i],'msg_part='+j);
+					}
+				}
+			content_body = content_body.replace(/msg_part=-/g,'msg_part=');
+			
 			mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body;
-			// This is not just stupid, it refresh screen to avoid broken images
-			mainField.document.getElementsByTagName('body').item(0).innerHTML = mainField.document.getElementsByTagName('body').item(0).innerHTML;	
 		}	
 				
@@ -927,7 +988,4 @@
 			cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
 		
-		if (preferences.auto_save_draft == 1)
-				setTimeout('auto_save_msg('+border_id+')', autosave_time);		
-
 		var save_link = Element("save_message_options");
 		save_link.onclick = '';
@@ -940,4 +998,5 @@
 
 function save_msg(border_id){
+
 	if (newMessageTab.imapBox[border_id]) //Gets the imap folder
 		var folder_id = newMessageTab.imapBox[border_id];
@@ -956,9 +1015,11 @@
 	message_id = newMessageTab.imapUid[border_id];
 	var handler_save_msg = function(data){ return_save(data,this.tmp_border_id,this.tmp_folder_name,this.tmp_folder_id,this.message_id); }
-	
+
 	var textArea = document.createElement("TEXTAREA");
 	textArea.style.display='none';
 	textArea.name = "body";
 	body = document.getElementById("body_"+border_id);
+	if (! body)
+		return;
 	textArea.value += '<body>\r\n';
 	textArea.value += body.contentWindow.document.body.innerHTML;
@@ -968,4 +1029,8 @@
 	input_folder.name = "folder";
 	input_folder.value = folder_id;
+	var input_msgid = document.createElement("INPUT");
+	input_msgid.style.display='none';
+	input_msgid.name = "msg_id";
+	input_msgid.value = message_id;
 	
 	if (is_ie){
@@ -978,4 +1043,5 @@
 	form.appendChild(textArea);
 	form.appendChild(input_folder);
+	form.appendChild(input_msgid);
 
 	cExecuteForm ("$this.imap_functions.save_msg", form, handler_save_msg,border_id);	
@@ -1091,5 +1157,5 @@
 function print_all(){
 	var folder= Element('border_id_0').innerHTML;
-	var body = Element('divScrollMain').innerHTML;
+	var body = Element('divScrollMain_'+numBox).innerHTML;
 	var print_width = screen.width - 200;
 	var x = ((screen.width - print_width) / 2);
@@ -1243,60 +1309,4 @@
 }
 
-/*function select_all_messages(select){
-	var main = Element("tbody_box");
-	var main_list = main.childNodes;
-	var len_main_list = main_list.length;
-	
-	var j = 0;
-	if (select){
-		for (j; j<len_main_list; j++){
-			var check_box = Element("check_box_message_"+main_list[j].id);
-			if (check_box){
-				check_box.checked = true;
-				var tr = Element(main_list[j].id);
-				switch(tr.className){
-					case "tr_msg_read":
-						tr.className = 'selected_seen_msg_bg';
-						break;
-					case "tr_msg_unread":
-						tr.className = 'selected_unseen_msg_bg';
-						break;
-					case "important_msg_read":
-						tr.className = 'selected_important_msg_read';
-						break;
-					case "important_msg_unread":
-						tr.className = 'selected_important_msg_unread';
-						break;
-				}
-			}
-		}
-	}
-	else{
-		for (j; j<len_main_list; j++){
-			var check_box = Element("check_box_message_"+main_list[j].id);
-			if (check_box){
-				check_box.checked = false;
-
-				var tr = Element(main_list[j].id);
-				switch(tr.className){
-					case "selected_seen_msg_bg":
-						tr.className = 'tr_msg_read';
-						break;
-					case "selected_unseen_msg_bg":
-						tr.className = 'tr_msg_unread';
-						break;
-					case "selected_important_msg_read":
-						tr.className = 'important_msg_read';
-						break;
-					case "selected_important_msg_unread":
-						tr.className = 'important_msg_unread';
-						break;
-				}
-			}
-		}
-	}
-}*/
-
-
 function verify_session(data){
 	if(data && data.imap_error) {
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 271)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 320)
@@ -1,2 +1,8 @@
+var openBox = {
+	'content_id' : [],
+	'tab_folder' : []
+ };
+var numBox = 0; // Open Mailboxes at context
+
 function draw_tree_folders(folders){
 	// Check if the tree folders alredy exist.
@@ -24,7 +30,7 @@
 				if(data[i].folder_id == get_current_folder()){					
 					var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
-					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
-						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
-					}
+//					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
+//						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
+//					}
 					Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
 					draw_paging(Element('tot_m').innerHTML);
@@ -43,6 +49,10 @@
 		for (var i=0; i<folders.length; i++){
 			if (folders[i].folder_unseen > 0)
+			{
 				var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
-
+				
+				if( folders[i].folder_name.toLowerCase() == 'inbox' )
+					Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
+			}
 			else
 				var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
@@ -62,4 +72,10 @@
 		tree_folders.getNodeById('INBOX')._select();		
 		draw_paging(Element('tot_m').innerHTML);
+		// Draw right menu folders.
+		/*
+		var treeroot = document.getElementById('chroottree_folders'); 
+		for (var linkBox = treeroot.firstChild; linkBox != null; linkBox = linkBox.nextSibling)
+			_dragArea.makeMenuBox(linkBox);
+		*/
 	}
 	
@@ -93,6 +109,4 @@
 		}
 	}
-
-
 }
 
@@ -105,5 +119,8 @@
 				Element('new_m').innerHTML = '<font face="Verdana" size="1" color="RED">'+f_unseen.innerHTML+'</font>';
 			else
-				Element('new_m').innerHTML = 0;			
+			{
+				if( parseInt(Element('new_m').innerHTML) == 0 )
+					Element('new_m').innerHTML = 0;			
+			}
 			folders = data;
 			cExecute ("$this.imap_functions.get_range_msgs2&folder=INBOX&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type=SORTARRIVAL&sort_box_reverse=1", handler_draw_box);
@@ -112,9 +129,31 @@
 
 var handler_draw_box = function(data){
-	draw_box(data, 'INBOX');
+	draw_box(data, 'INBOX', true);
+	//alternate_border(0);
 }
 
 // Action on change folders.
 function change_folder(folder, folder_name){
+	if (openBox.tab_folder[0] != folder)
+	{
+		current_folder = folder;
+		var handler_draw_box = function(data)
+		{
+			if(!verify_session(data))
+				return;
+			alternate_border(0);
+			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+			draw_box(data, folder, true);
+			draw_paging(data.num_msgs);
+			Element("tot_m").innerHTML = data.num_msgs;
+			update_menu();
+			return true;
+		}
+		cExecute ("$this.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
+	} else
+		alternate_border(0);
+}
+
+function open_folder(folder, folder_name){
 	if (get_current_folder()!= folder)
 	{
@@ -123,16 +162,16 @@
 		{
 			if(!verify_session(data))
-				return;
-			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
-			draw_box(data, current_folder);
-			draw_paging(data.num_msgs);
-			Element("tot_m").innerHTML = data.num_msgs;
-			update_menu();
-			alternate_border(0);
+				return false;
+			numBox++;
+			create_border(folder_name,numBox.toString());
+			draw_box(data, current_folder, false);
+			alternate_border(numBox);
+			return true;
 		}
 		cExecute ("$this.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
 	}
 	else
-		alternate_border(0);
+		alternate_border(numBox);
+	return true;
 }
 
@@ -246,17 +285,19 @@
 
 // Draw the inbox and another folders
-function draw_box(headers_msgs, msg_folder){
-	kill_current_box();
+function draw_box(headers_msgs, msg_folder, alternate){
+	if (alternate)
+		kill_current_box();
 	
 	if(is_ie)
 		document.getElementById("border_table").width = "99.5%";
 
-	var content_id_0 = document.getElementById("content_id_0");
-	
-	table_message_header_box = document.getElementById("table_message_header_box");
+	openBox.content_id[numBox] = document.getElementById("content_id_"+numBox);	
+	openBox.tab_folder[numBox] = msg_folder;
+	
+	table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
 	if (table_message_header_box == null){
 		var table_element = document.createElement("TABLE");
 		var tbody_element = document.createElement("TBODY");
-		table_element.setAttribute("id", "table_message_header_box");
+		table_element.setAttribute("id", "table_message_header_box_"+numBox);
 		table_element.className = "table_message_header_box";
 		
@@ -292,5 +333,5 @@
 		td_element3.setAttribute("width", "31%");
 		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
-		td_element3.id = "message_header_SORTFROM";
+		td_element3.id = "message_header_SORTFROM_"+numBox;
 		td_element3.align = "left";
 		td_element3.innerHTML = get_lang("Who");
@@ -299,5 +340,5 @@
 		td_element4.setAttribute("width", "41%");
 		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
-		td_element4.id = "message_header_SORTSUBJECT";
+		td_element4.id = "message_header_SORTSUBJECT_"+numBox;
 		td_element4.align = "left";
 		td_element4.innerHTML = get_lang("Subject");
@@ -306,5 +347,5 @@
 		td_element5.setAttribute("width", "14%");
 		td_element5.onclick = function () {sort_box(search_box_type,'SORTARRIVAL');};
-		td_element5.id = "message_header_SORTARRIVAL";
+		td_element5.id = "message_header_SORTARRIVAL_"+numBox;
 		td_element5.align = "center";
 		td_element5.innerHTML = get_lang("Date");
@@ -312,5 +353,5 @@
 		td_element6.setAttribute("width", "14%");
 		td_element6.onclick = function () {sort_box(search_box_type,'SORTSIZE');}
-		td_element6.id = "message_header_SORTSIZE";
+		td_element6.id = "message_header_SORTSIZE_"+numBox;
 		td_element6.align = "left";
 		td_element6.innerHTML = get_lang("Size");
@@ -324,5 +365,5 @@
 		tbody_element.appendChild(tr_element);
 		table_element.appendChild(tbody_element);
-		content_id_0.appendChild(table_element);
+		openBox.content_id[numBox].appendChild(table_element);
 	}
 	draw_header_box();
@@ -362,5 +403,6 @@
 	table_element.appendChild(tbody_element);
 
-	var _divScroll = Element("divScrollMain");
+	var _divScroll = document.getElementById("divScrollMain_"+numBox);
+
 	var bar = document.getElementById("toolbar");
 	var offset = 0;
@@ -368,5 +410,5 @@
 	if(!_divScroll){		
 		_divScroll = document.createElement("DIV");
-		_divScroll.id = "divScrollMain";
+		_divScroll.id = "divScrollMain_"+numBox;
 	}
 	
@@ -391,5 +433,5 @@
 	// Fim: Redimensiona DIV SCROLL
 	_divScroll.appendChild(table_element);
-	content_id_0.appendChild(_divScroll);
+	openBox.content_id[numBox].appendChild(_divScroll);
 	
 	var f_unseen = 0;
@@ -415,9 +457,9 @@
 
 	if ((preferences.use_shortcuts == '1') && (headers_msgs[0]))
-		select_msg(headers_msgs[0].msg_number, 'null');
+		select_msg(headers_msgs[0].msg_number, 'null', true);
 
 	var tdFolders  =  Element("folderscol");
 	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
-	alternate_border(0);
+	alternate_border(numBox);
 	draw_footer_box(headers_msgs.num_msgs);	
 	Element('main_table').style.display = '';
@@ -458,5 +500,5 @@
 
 function make_tr_message(headers_msgs, msg_folder){
-		var tr_element = document.createElement("TR");
+		var tr_element = document.createElement('tr');
 		tr_element.style.height = preferences.line_height;
 		var _fontSize = preferences.font_size ? preferences.font_size : "11";
@@ -625,5 +667,5 @@
 	var message_header = Element("message_header_"+search);
 	var handler_draw_box = function(data){
-		draw_box(data, get_current_folder());
+		draw_box(data, get_current_folder(),true);
 		draw_paging(Element('tot_m').innerHTML);
 	}
@@ -665,9 +707,9 @@
 			break;
 	}
-	Element("message_header_SORTFROM").innerHTML 	= get_lang("Who");
-	Element("message_header_SORTSUBJECT").innerHTML = get_lang("Subject");
-	Element("message_header_SORTARRIVAL").innerHTML = get_lang("Date");
-	Element("message_header_SORTSIZE").innerHTML	= get_lang("Size");	
-	Element("message_header_"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL") ).innerHTML = "<B>"+type_name+"</B><img src ='templates/default/images/arrow_"+(sort_box_reverse == 1 ? 'desc' : 'asc')+"endant.gif'>";
+	document.getElementById("message_header_SORTFROM_"+numBox).innerHTML 	= get_lang("Who");
+	document.getElementById("message_header_SORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
+	document.getElementById("message_header_SORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
+	document.getElementById("message_header_SORTSIZE_"+numBox).innerHTML	= get_lang("Size");	
+	document.getElementById("message_header_"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox ).innerHTML = "<B>"+type_name+"</B><img src ='templates/default/images/arrow_"+(sort_box_reverse == 1 ? 'desc' : 'asc')+"endant.gif'>";
 }
 function draw_message(info_msg, ID){
@@ -743,4 +785,9 @@
 	}
 	
+	if (info_msg.DispositionNotificationTo)
+	{
+		td.innerHTML += '&nbsp;<img style="cursor:pointer" alt="'+ get_lang('Message with read notification') + '" title="'+ get_lang('Message with read notification') + '" src="templates/default/images/notification.gif">';
+	}
+	
 	// NORMAL MSG
 	if(info_msg.Draft != 'X')
@@ -852,4 +899,5 @@
 			div_other_options.innerHTML += ' | <span class="message_options" onclick="spam(\''+info_msg.msg_folder+'\', '+info_msg.msg_number+',\'null\')";>'+get_lang("Mark as Spam")+'</span>';	
 	}
+		
 	td_other_options.appendChild(div_other_options);
 	//td_other_options.innerHTML = option_print + option_reply_to_all + option_source_msg;
@@ -1321,25 +1369,25 @@
 		input_to.rows = 2;
 		input_to.onkeypress = function (e)
-		{
-			if ((e.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_to.value, 'to', ID);
-			}
-			else
-			{ 
-				if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-				{
-					e.preventDefault();
-					search_contacts(e.keyCode,this.id);
-				}
-			}
-		}
-		input_to.onkeyup = function (e)
-		{
-			if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-			{
-				search_contacts(e.keyCode,this.id);
-			}
-		}
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_to.value, 'to', ID);
+            }
+            else
+            {
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_to.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
 	}
 	else
@@ -1347,14 +1395,14 @@
 		input_to.rows = 3;
 		input_to.onkeyup = function (e)
-		{
-			if ((window.event.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_to.value, 'to', ID);
-			}
-			else 
-			{ 
-				search_contacts(window.event.keyCode,this.id);
-			}	
-		}
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_to.value, 'to', ID);
+            }
+            else 
+            { 
+                search_contacts(window.event.keyCode,this.id);
+            }   
+        }
 	}
 	td_to.appendChild(input_to);
@@ -1400,45 +1448,46 @@
 	input_cc.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
 	input_cc.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
-	if (!is_ie)
-	{
-		input_cc.rows = 2;
-		input_cc.onkeypress = function (e)
-		{
-			if ((e.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_cc.value, 'cc', ID);
-			}
-			else 
-			{ 
-				if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-				{
-					e.preventDefault();
-					search_contacts(e.keyCode,this.id);
-				}
-			}
-		}
-		input_cc.onkeyup = function (e)
-		{
-			if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-			{
-				search_contacts(e.keyCode,this.id);
-			}
-		}
-	}
-	else if (is_ie)
-	{
-		input_cc.rows = 3;
-		input_cc.onkeyup = function (e)
-		{
-			if ((window.event.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_cc.value, 'cc', ID);
-			}
-			else 
-			{ 
-				search_contacts(window.event.keyCode,this.id);
-			}	
-		}
-	}
+    if (!is_ie)
+    {
+        input_cc.rows = 2;
+        input_cc.onkeypress = function (e)
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cc.value, 'cc', ID);
+            }
+            else
+            {
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_cc.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
+    }
+    else if (is_ie)
+    {
+        input_cc.rows = 3;
+        input_cc.onkeyup = function (e)
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cc.value, 'cc', ID);
+            }
+            else
+            {
+                search_contacts(window.event.keyCode,this.id);
+            }
+        }
+    }
+	
 	td_cc.appendChild(input_cc);
 	var img_search = document.createElement("IMG");
@@ -1481,45 +1530,47 @@
 	input_cco.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
 	input_cco.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
+	
 	if (!is_ie)
-	{
-		input_cco.rows = 2;
-		input_cco.onkeypress = function (e)
-		{
-			if ((e.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_cco.value, 'cco', ID);
-			}
-			else 
-			{ 
-				if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-				{
-					e.preventDefault();
-					search_contacts(e.keyCode,this.id);
-				}
-			}
-		}
-		input_cco.onkeyup = function (e)
-		{
-			if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-			{
-				search_contacts(e.keyCode,this.id);
-			}
-		}
-	}
-	else if (is_ie)
-	{
-		input_cco.rows = 3;
-		input_cco.onkeyup = function (e)
-		{
-			if ((window.event.keyCode) == 120) //F9
-			{
-				emQuickSearch(input_cco.value, 'cco', ID);
-			}
-			else 
-			{ 
-				search_contacts(window.event.keyCode,this.id);
-			}	
-		}
-	}
+    {
+        input_cco.rows = 2;
+        input_cco.onkeypress = function (e)
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cco.value, 'cco', ID);
+            }
+            else 
+            { 
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_cco.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
+    }
+    else if (is_ie)
+    {
+        input_cco.rows = 3;
+        input_cco.onkeyup = function (e)
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cco.value, 'cco', ID);
+            }
+            else 
+            { 
+                search_contacts(window.event.keyCode,this.id);
+            }   
+        }
+    }
+	
 	td_cco.appendChild(input_cco);
 	var img_search = document.createElement("IMG");
@@ -1553,5 +1604,5 @@
 	a_cc_link.setAttribute("href","javascript:void(0)");
 	a_cc_link.setAttribute("tabIndex","-1");
-	a_cc_link.onclick = function () {this.style.display='none';document.getElementById('tr_cc_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cc.focus();}
+	a_cc_link.onclick = function () {this.style.display='none';document.getElementById('tr_cc_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cc.focus(); return false;}
 	td2_link.appendChild(a_cc_link);	
 	var space = document.createElement("span");
@@ -1564,5 +1615,5 @@
 	a_cco_link.setAttribute("href","javascript:void(0)");
 	a_cco_link.setAttribute("tabIndex","-1");
-	a_cco_link.onclick = function () {this.style.display='none';document.getElementById('tr_cco_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cco.focus();}
+	a_cco_link.onclick = function () {this.style.display='none';document.getElementById('tr_cco_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cco.focus(); return false;}
 	td2_link.appendChild(a_cco_link);	
 	tr_link.appendChild(td1_link);
@@ -1605,5 +1656,5 @@
 	var add_files = document.createElement("A");
 	add_files.setAttribute("href", "javascript:void(0)");
-	add_files.onclick = function () {addFile(ID);};
+	add_files.onclick = function () { addFile(ID); return false;};
 	add_files.innerHTML =  get_lang("Attachments: add+");
 	add_files.setAttribute("tabIndex","-1");
@@ -1650,4 +1701,5 @@
 	_div.style.height = document.body.clientHeight - _offset - 105;
 	content.style.height = document.body.clientHeight - _offset - 80;
+	
 	_div.style.overflow = "auto";
 	_div.style.width = defaultWidth;
Index: /trunk/expressoMail1_2/js/doiMenuData.js
===================================================================
--- /trunk/expressoMail1_2/js/doiMenuData.js	(revision 214)
+++ /trunk/expressoMail1_2/js/doiMenuData.js	(revision 320)
@@ -206,2 +206,71 @@
 	div.style.display ='';
 } 
+
+function ConstructBoxMenu(_event,boxName,boxFolder){
+
+	var div = Element("div_rightbutton_folder");
+		if (div)
+			div.parentNode.removeChild(div);
+	
+		div = document.createElement("DIV");
+		div.style.position = 'absolute';
+		div.style.zIndex = '15';
+
+		div.style.border = '1px outset BLACK';
+		div.style.background = "#EEEEE6";
+		div.id = 'div_rightbutton_folder';
+		div.style.padding = "1px";
+		div.style.fontSize = is_ie || is_gecko1_5 || is_win ? "9pt" : "11pt";
+		div.style.width = "190px";
+		div.style.height = is_win && !is_ie ? "35px" : "33px";
+		div.style.display ='none';		
+		document.body.appendChild(div);
+		var _tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+		var _sep = "<hr>";
+		var optionsMenu = new Array( 
+			_tab + get_lang("Open in new tab")+'|'+"open_folder('"+boxFolder+"', '"+boxName+"')",
+			_tab + get_lang("Edit folders")+'|'+"folderbox()"
+		);
+
+		for(i = 0; i < optionsMenu.length; i++){
+			optionsMenu_l = optionsMenu[i].split('|');
+			var div_l = document.createElement("DIV");
+			div_l.style.padding = "1px";
+			div_l.style.width = "188px";
+			div_l.style.cursor = 'pointer';			
+			div_l.innerHTML = optionsMenu_l[0];
+			div_l.style.valign = 'top';
+			if(optionsMenu_l[0] != _sep) {
+				var attr = document.createAttribute('javascript');
+				attr.value = optionsMenu_l[1]+";Element('div_rightbutton_folder').style.display = 'none';";
+				div_l.setAttributeNode(attr);
+				div_l.oncontextmenu = function(e) {	return false;};
+				div_l.onclick = function () {this.onmouseout();eval(this.getAttribute('javascript'));};
+				div_l.onmouseover = function () {this.style.color = 'WHITE';this.style.background = "#4a79cd";};
+				div_l.onmouseout = function ()  {this.style.color = 'BLACK';this.style.background = "#EEEEE6";};
+			}
+			else
+				div_l.style.height = "11px";
+				
+			div_l.id="link_rightbutton_folder"+i;
+			div.appendChild(div_l);
+		}
+
+	var x = _event.clientX + document.body.scrollLeft +  2;
+	var y =  _event.clientY + document.body.scrollTop +  2;
+
+	var w_width  = is_ie ? document.body.clientWidth : window.innerWidth;
+	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
+
+	if(x + 218 > w_width)
+		div.style.left = w_width - (is_ie ? 198 : 218);	
+	else
+		div.style.left = x;
+	
+	if(y + 131 > w_height)
+		div.style.top =  w_height - (is_ie ? 125 : 131);	
+	else
+		div.style.top = y;	
+
+	div.style.display ='';
+} 
Index: /trunk/expressoMail1_2/js/DropDownContacts.js
===================================================================
--- /trunk/expressoMail1_2/js/DropDownContacts.js	(revision 2)
+++ /trunk/expressoMail1_2/js/DropDownContacts.js	(revision 320)
@@ -89,7 +89,12 @@
 	// treat especials keys
 	// key ENTER
-	if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility)){
-		makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id);
-		hideTip();
+	if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility))
+	{
+		//Bug, sometimes the actualSelectedContact do not exist.
+		try{
+			makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id);
+			hideTip();
+		}
+		catch(e){}
 		return;
 	}
Index: /trunk/expressoMail1_2/js/color_palette.js
===================================================================
--- /trunk/expressoMail1_2/js/color_palette.js	(revision 51)
+++ /trunk/expressoMail1_2/js/color_palette.js	(revision 320)
Index: /trunk/expressoMail1_2/js/rich_text_editor.js
===================================================================
--- /trunk/expressoMail1_2/js/rich_text_editor.js	(revision 279)
+++ /trunk/expressoMail1_2/js/rich_text_editor.js	(revision 320)
@@ -8,7 +8,7 @@
 function cRichTextEditor(){
 	this.emwindow   = new Array;
-	this.editor;
-	this.table;
-	this.id;
+	this.editor = "body_1";
+	this.table = "";
+	this.id = "1";
 	this.buildEditor();
 	this.saveFlag = 0;
@@ -16,21 +16,38 @@
 
 cRichTextEditor.prototype.loadEditor = function(ID) {
-	this.id = ID;
+	var _this = this;
+	_this.id = ID;
 	parentDiv = document.getElementById("body_position_"+this.id);
 	this.editor = "body_"+this.id;
+
+	if(this.table.parentNode)
+		this.table.parentNode.removeChild(this.table);
 	
-	if(this.table.parentNode)
-		this.table.parentNode.removeChild(this.table);	
-
-	if(parentDiv.firstChild){
-		parentDiv.insertBefore(this.table,parentDiv.firstChild);
+	if( parentDiv.firstChild )
+	{
+		if (!parentDiv.firstChild.hasChildNodes()) 
+			parentDiv.insertBefore(this.table,parentDiv.firstChild);
 	}
 	else
 		parentDiv.appendChild(this.table);
 
-	if(!Element(this.editor)){
+	if(!Element(this.editor))
+	{
+		this.createElementEditor(this.editor);
+	}
+	else
+	{
+		Element("viewsource_rt_checkbox").checked=false;
+	}
+
+	document.getElementById('fontname').selectedIndex = 1;
+	document.getElementById('fontsize').selectedIndex = 1;
+}
+
+cRichTextEditor.prototype.createElementEditor = function(pObj)
+{
 		iframe = document.createElement("IFRAME");
-		iframe.id = this.editor;
-		iframe.name = this.editor;
+		iframe.id = pObj;
+		iframe.name = pObj;
 		iframe.width = "99%";
 		iframe.height = 300;
@@ -46,11 +63,4 @@
 		parentDiv.appendChild(checkbox);
 		parentDiv.appendChild(text);
-	}
-	else{
-		Element("viewsource_rt_checkbox").checked=false;
-	}
-
-	document.getElementById('fontname').selectedIndex = 1;
-	document.getElementById('fontsize').selectedIndex = 1;
 }
 
@@ -231,5 +241,5 @@
 			mainField.document.execCommand(command, false, option);
 		//mainField.focus();
-    } catch (e) { alert(e.description); }
+    } catch (e) {/* alert(e);*/ }
 }
 
@@ -258,9 +268,26 @@
 cRichTextEditor.prototype.addInputFile = function()
 {
+	//Begin: Verify if the image extension is allowed.
+	var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx");
+	var inputFile = document.getElementById('inputFile_img');	
+	if(!inputFile.value) return false;
+	var fileExtension = inputFile.value.split(".");
+	fileExtension = fileExtension[(fileExtension.length-1)];
+	var deniedExtension = true;
+	for(var i=0; i<imgExtensions.length; i++) {
+		if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) {
+			deniedExtension = false;
+			break;
+		}
+	}
+	if(deniedExtension) {
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		return false;
+	}
+	// End: Verify image extension.
 	var id = this.editor.substr(5); // border_id
 	divFiles = document.getElementById("divFiles_"+id);
 	var countDivFiles = divFiles.childNodes.length + 1;
 
-	var inputFile = document.getElementById('inputFile_img');
 	var divFiles = document.getElementById('divFiles_'+id);
 	inputFile.id = 'inputFile_'+id +"_"+countDivFiles;
@@ -273,9 +300,8 @@
 	form_upload.parentNode.removeChild(form_upload);
 	win.close();
-	
-	if (! validateFileExtension(inputFile.value, inputFile.id , id))
-	return false;
 
 	RichTextEditor.saveFlag = 0; // See if save function finished
+	var save_link = document.getElementById("save_message_options");
+	//save_link.onclick = function () {};
 	save_msg(id);
 	setTimeout("RichTextEditor.insertImgHtml("+id+")",1000);
@@ -286,4 +312,5 @@
 		setTimeout("RichTextEditor.insertImgHtml("+id+")",500);
 	else
+		if (RichTextEditor.saveFlag == 1)
 			this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=INBOX/'+draftsfolder+'&msg_num='+newMessageTab.imapUid[id]+'&msg_part='+(newMessageTab.countFile[id]+1));
 			// this.editorCommand('Image', '.inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params'));
Index: /trunk/expressoMail1_2/js/TreeShow.js
===================================================================
--- /trunk/expressoMail1_2/js/TreeShow.js	(revision 197)
+++ /trunk/expressoMail1_2/js/TreeShow.js	(revision 320)
@@ -26,5 +26,6 @@
 			}
 			ttree.FOLDER = ttreeBox.name_folder;
-			tree_folders.getNodeById(get_current_folder())._select();
+			if (tree_folders.getNodeById(get_current_folder()))
+				tree_folders.getNodeById(get_current_folder())._select();
 		}
 		cExecute ("$this.imap_functions.get_folders_list", handler_update_folders);		
Index: /trunk/expressoMail1_2/index.php
===================================================================
--- /trunk/expressoMail1_2/index.php	(revision 271)
+++ /trunk/expressoMail1_2/index.php	(revision 320)
@@ -28,5 +28,5 @@
 		'nonavbar' => False,
 		'currentapp' => 'expressoMail1_2',
-		'update_version'	=> '1.2211',
+		'update_version'	=> '1.222',
 		'enable_nextmatchs_class' => True
 	);
Index: /trunk/expressoMail1_2/templates/default/preferences.tpl
===================================================================
--- /trunk/expressoMail1_2/templates/default/preferences.tpl	(revision 271)
+++ /trunk/expressoMail1_2/templates/default/preferences.tpl	(revision 320)
@@ -108,4 +108,13 @@
     </tr>
 
+    <tr bgcolor="{tr_color1}">
+        <td>
+			{lang_auto_save_draft}
+		</td>
+		<td align="center">
+			<input type="checkbox" name="auto_save_draft" value=1 {checked_auto_save_draft}>
+		</td>
+    </tr>
+
     <tr bgcolor="{tr_color2}">
         <td colspan='2'>
Index: /trunk/expressoMail1_2/templates/default/index.tpl
===================================================================
--- /trunk/expressoMail1_2/templates/default/index.tpl	(revision 139)
+++ /trunk/expressoMail1_2/templates/default/index.tpl	(revision 320)
@@ -29,5 +29,5 @@
 				<div style="height:4px"></div>
 				<div align="center">
-					<input type="text" id="em_message_search" size="18" maxlength="22"/>
+					<input type="text" id="em_message_search" size="16" maxlength="22" onfocus="javascript:onFocusQuickSearchEmail(this); return false;"/>
 					<a class='' onMouseOut="window.status='';return true;" title='{lang_Open_Search_Window}' onMouseOver="window.status='{lang_Open_Search_Window}';return true;" href="javascript:void(0);"  onClick="javascript:search_emails(Element('em_message_search').value)">
 						<img valign="center" align="center" src="templates/default/images/search.gif">
@@ -37,6 +37,32 @@
 					</a>
 				</div>
+				<script type="text/javascript">
+					
+					var element_input = document.getElementById('em_message_search');
 				
-			</td>			
+					function keyPressQuickSearchEmail(e)
+					{
+						if( e.keyCode == 13 )
+							search_emails(element_input.value);
+					}
+
+					if ( element_input.addEventListener )
+						element_input.addEventListener('keypress', keyPressQuickSearchEmail, false);
+					else if ( element_input.attachEvent )
+						element_input.attachEvent('onkeypress', keyPressQuickSearchEmail);
+
+					function onFocusQuickSearchEmail(pInput)
+					{
+						if ( pInput.createTextRange )
+						{
+							var FieldRange = pInput.createTextRange();
+								FieldRange.moveStart('character', pInput.value.length);
+								FieldRange.collapse();
+								FieldRange.select();
+						}
+					}
+				
+				</script>
+			</td>
 			<td width="2px">&nbsp;</td>			
 			<td width="*" valign="top" align="left">
