Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 603)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 605)
@@ -224,7 +224,7 @@
 			$return['fulldate'] = gmdate("d/m/Y H:i",$header->udate);
 			$return['smalldate'] = gmdate("H:i",$header->udate);
-			
+
 			$timestamp_now = strtotime("now");  			
-            $timestamp_msg_time = $header->udate;
+			$timestamp_msg_time = $header->udate;
 			// $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. 
 			// The variable $timestamp_diff is calculated without MailDate TZ.
@@ -414,7 +414,5 @@
 		$return['subject'] = $this->decode_string($header->fetchsubject);
 		$return['Size'] = $header->Size;
-		$return['reply_toaddress'] = $header->reply_toaddress;
-		$return['reuse_border'] = $params['reuse_border'];
-		
+		$return['reply_toaddress'] = $header->reply_toaddress;		
 		return $return;
 	}
Index: trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/common_functions.js	(revision 569)
+++ trunk/expressoMail1_2/js/common_functions.js	(revision 605)
@@ -113,4 +113,12 @@
 	purgeCache();
 	return true;
+}
+
+function msg_is_read(msg_number, selected){
+	tr_message = Element(msg_number);
+	if (tr_message.className == 'tr_msg_unread')
+		return false;
+	else
+		return true;
 }
 
Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 603)
+++ trunk/expressoMail1_2/js/main.js	(revision 605)
@@ -49,6 +49,6 @@
 		{
 			away=false;
-			var save_link = Element("save_message_options");
-			save_link.onclick = function onclick(event) { newMessageTab.toPreserve[border_id] = true; save_msg(border_id); } ;
+			var save_link = Element("save_message_options_"+border_id);
+			save_link.onclick = function onclick(event) { openTab.toPreserve[border_id] = true; save_msg(border_id); } ;
 			save_link.style.color = '#0000ff';
 		};
@@ -103,6 +103,6 @@
 		var id_msg_read = msg_info.msg_number +"_r";
 		// If needed, delete old border
-		if (msg_info.reuse_border)
-			delete_border(msg_info.reuse_border,'false');
+		if (openTab.type[currentTab] == 2 || openTab.type[currentTab] == 3)
+			delete_border(currentTab,'false');
 
 		
@@ -117,13 +117,33 @@
 		}
 
+		var domains = "";
+		if ((msg_info.DispositionNotificationTo) && (!msg_is_read(msg_info.msg_number) || (msg_info.Recent == 'N')))
+		{			
+			if (preferences.notification_domains != undefined && preferences.notification_domains != "")
+				domains = preferences.notification_domains.split(',');
+			else
+			{				
+				var confNotification = true;
+			 }
+			for (var i = 0; i < domains.length; i++)
+				if (msg_info.DispositionNotificationTo.match(domains[i]+">"))
+				{
+					var confNotification = true;
+					break;
+				}
+				if (confNotification == undefined)
+					var confNotification = confirm(get_lang("The sender:\n%1\nwaits your notification of reading. Do you want to confirm this?",msg_info.DispositionNotificationTo), "");
+
+			if (confNotification)
+				cExecute ("$this.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
+		}
 		//Change msg class to read.
-		if (msg_info.Unseen == 'U')
+		if (!msg_is_read(msg_info.msg_number))
+		{
 			set_msg_as_read(msg_info['msg_number'], true);
-		
-		if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
-		/*	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);
-		}
+			if (msg_info.cacheHit)
+				set_message_flag(msg_info.msg_number, "seen"); // avoid caducous (lazy) data
+		}
+
 	}
 }
@@ -316,5 +336,4 @@
 
 function move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name){
-
 	if (! folder || folder == 'null')
 		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : get_current_folder();
@@ -386,6 +405,8 @@
 			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
 		if (data.border_ID.indexOf('r') != -1){
-			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder())
+			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder()){
+				delete_border(data.border_ID,'false');
 				show_msg(data.previous_msg);
+				}
 			else
 				delete_border(data.border_ID,'false');
@@ -466,4 +487,6 @@
 	if (new_border_ID == false)
 		return false;	
+        openTab.type[new_border_ID] = tabTypes[type];
+
 	// Salva a pasta da mensagem respondida ou encaminhada:
 	var folder_message = Element("input_folder_"+border_ID);
@@ -744,7 +767,7 @@
 			break;
 		case "edit":
-			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("_")));
+			openTab.imapBox[new_border_ID] = folder_message.value;
+			openTab.toPreserve[new_border_ID] = true;
+			openTab.imapUid[new_border_ID] = parseInt(border_ID.substr(0,border_ID.indexOf("_")));
 			document.getElementById('font_border_id_'+new_border_ID).innerHTML = data.subject;
 			data.to = Element("to_values_" + border_ID).value;
@@ -797,5 +820,5 @@
     {
         var time_auto_save = false;
-        var save_link = document.getElementById("save_message_options");
+        var save_link = document.getElementById("save_message_options"+new_border_ID);
 
         function auto_sav()
@@ -882,6 +905,6 @@
 			}
 		}
-		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 });
+		if ((! openTab.toPreserve[ID]) && (openTab.imapUid[ID] != 0))
+			cExecute ("$this.imap_functions.delete_msgs&folder="+openTab.imapBox[ID]+"&msgs_number="+openTab.imapUid[ID],function(data){ return });
 	}
 	else{			
@@ -896,5 +919,5 @@
 
 function send_message(ID, folder, folder_name){
-	var save_link = Element("save_message_options");
+	var save_link = Element("save_message_options_"+ID);
 	save_link.onclick = '';
 	save_link.style.color = '#999';
@@ -920,5 +943,5 @@
 	msg_id.style.display='none';
 	msg_id.name = "msg_id";
-	msg_id.value = newMessageTab.imapUid[ID];
+	msg_id.value = openTab.imapUid[ID];
 	
 	if (is_ie){
@@ -970,6 +993,6 @@
 	{
 		RichTextEditor.saveFlag = 1;
-		newMessageTab.imapUid[border_id] = data.msg_no;
-		newMessageTab.imapBox[border_id] = data.folder_id;
+		openTab.imapUid[border_id] = data.msg_no;
+		openTab.imapBox[border_id] = data.folder_id;
 		
 		var newTitle = document.getElementById('subject_'+border_id).value;
@@ -988,5 +1011,5 @@
 		{
 			for (var i=0; i<body_images.length; i++){
-				content_body = 	content_body.replace(body_images[i],"msg_num="+newMessageTab.imapUid[border_id]);
+				content_body = 	content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]);
 			}
 			var allImgs = new Array (images_part.length);
@@ -1027,5 +1050,5 @@
 		var attach_files = connector.unserialize(data.files);
 		if (attach_files != null) {
-			newMessageTab.countFile[border_id] = attach_files.length;
+			openTab.countFile[border_id] = attach_files.length;
 		for (att_index = 0; att_index < attach_files.length; att_index++){
 	
@@ -1056,7 +1079,7 @@
 	}
 		if (message_id)
-			cExecute ("$this.imap_functions.delete_msgs&folder="+newMessageTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
-		
-		var save_link = Element("save_message_options");
+			cExecute ("$this.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
+		
+		var save_link = Element("save_message_options_"+border_id);
 		save_link.onclick = '';
 		save_link.style.color = '#999';
@@ -1070,6 +1093,6 @@
 	Element("send_button_"+border_id).style.visibility="hidden";
 
-	if (newMessageTab.imapBox[border_id]) //Gets the imap folder
-		var folder_id = newMessageTab.imapBox[border_id];
+	if (openTab.imapBox[border_id]) //Gets the imap folder
+		var folder_id = openTab.imapBox[border_id];
 	else
 		var	folder_id = "INBOX/"+draftsfolder;
@@ -1084,5 +1107,5 @@
 	tmp_folder_name=folder_name;
 	tmp_folder_id=folder_id;
-	message_id = newMessageTab.imapUid[border_id];
+	message_id = openTab.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); }
 
Index: trunk/expressoMail1_2/js/connector.js
===================================================================
--- trunk/expressoMail1_2/js/connector.js	(revision 584)
+++ trunk/expressoMail1_2/js/connector.js	(revision 605)
@@ -479,6 +479,4 @@
 		'result' : []
 	};
-	var acertos = 0;
-	var naoacertos = 0;
 	var expurgatedCache = new Array(); // Data to purge from cache
 
@@ -501,5 +499,5 @@
 	}
 	function addToCache(id,data){
-		if (typeof(preferences) =='undefined' || preferences.use_cache != 'True')
+		if (typeof(preferences) == "undefined" || preferences.use_cache != 'True')
 			return false;
 		var func = id.substr(id.lastIndexOf('.')+1);
@@ -508,4 +506,6 @@
 		switch (func){
 			// functions that enters in cache
+                        case 'get_info_msg':
+				data.cacheHit = true;
 			case 'get_preferences':
 			case 'getSharedUsersFrom':
@@ -515,5 +515,4 @@
 			case 'get_cc_contacts':
 			case 'get_cc_groups':
-			case 'get_info_msg':
 			case 'getUsersByEmail':
 			case 'br':
@@ -526,5 +525,5 @@
 			case 'get_range_msgs2':
 			case 'get_folders_list':
-			case 'search_msg':
+//			case 'search_msg':
 				connectorCache.valid[id] = true;
                                 connectorCache.result[id] = data;
@@ -534,6 +533,8 @@
 			//functions that expires the cache
 			case 'move_messages':
+			case 'delete_msgs':
 			case 'getReturnExecuteForm':
 			case 'set_messages_flag':
+			case 'empty_trash':
 				purgeCache();
 			default: // no cache
