Index: sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js
===================================================================
--- sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7296)
+++ sandbox/2.5.0-expresso1/expressoMail1_2/js/main.js	(revision 7320)
@@ -608,5 +608,7 @@
 				
 		}
-		//Change msg class to read.
+		
+		//Marcosw inicio - Comentado código antigo gears
+		/*
 		if (!msg_is_read(ID))
 		{
@@ -617,4 +619,25 @@
 			}
 		}
+		*/
+		//Marcosw fim
+
+		//Marcosw inicio - Inserido código novo MailArchiver
+		//Change msg class to read.
+		if (!msg_is_read(ID))
+		{
+            //MAILARCHIVER-01 TAG MESSAGE AS SEEN
+            if (proxy_mensagens.is_local_folder(get_current_folder())){
+                expresso_mail_archive.drawdata = null //no draw action
+                var tl = expresso_mail_archive.pattern.tagConfig('unseen', ID, 1);
+                expresso_mail_archive.taglist = tl;
+                expresso_mail_archive.progressbar = window.setTimeout("expresso_mail_archive.tagMessage()",1);                            
+            }
+            set_msg_as_read(ID, true);
+			if (msg_info.cacheHit || (!proxy_mensagens.is_local_folder(get_current_folder()) && msg_info.original_ID))
+			{
+            	set_message_flag(ID, "seen"); // avoid caducous (lazy) data
+			}
+		}
+		//Marcosw fim
 	}
 	setTimeout('resizeWindow()',300);
Index: sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js
===================================================================
--- sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js	(revision 7296)
+++ sandbox/2.5.0-expresso1/expressoMail1_2/js/messages_controller.js	(revision 7320)
@@ -345,9 +345,14 @@
 	}
 	
-	messages_proxy.prototype.proxy_set_message_flag = function (msg_number,flag,func_after_flag_change){
-		var msg_number_folder = Element("new_input_folder_"+msg_number+"_r"); //Mensagens respondidas/encaminhadas
+    //Marcosw inicio - adicionado mais um parametro na função
+	messages_proxy.prototype.proxy_set_message_flag = function (msg_number,flag,func_after_flag_change,msgid){
+    //Marcosw fim
+        var msg_number_folder = Element("new_input_folder_"+msg_number+"_r"); //Mensagens respondidas/encaminhadas
 		if(!msg_number_folder)
 			var msg_number_folder = Element("input_folder_"+msg_number+"_r"); //Mensagens abertas
 		var folder = msg_number_folder ?  msg_number_folder.value : get_current_folder();
+
+        //Marcosw inicio - comentado código inconsistente do gears
+        /*
 		if(this.is_local_folder(folder)) {
 			expresso_local_messages.set_message_flag(msg_number,flag, func_after_flag_change);
@@ -356,4 +361,57 @@
 			set_message_flag(msg_number,flag, func_after_flag_change);
 		}
+        */
+        //Marcosw fim
+
+        //Marcosw inicio - Adicionado código novo do MailArchiver
+        //MAILARCHIVER
+        if(this.is_local_folder(folder)) {
+            if(!msgid)
+                msgid = msg_number;
+            var taglist = flag;
+            var operation;
+    
+            switch(flag.toLowerCase()){
+                case 'unseen':
+                    strtag = "unseen";
+                    operation = 0;
+                    set_msg_as_unread(msgid);
+                    break;
+                case 'seen':
+                    strtag = "unseen";
+                    operation = 1;
+                    set_msg_as_read(msgid);
+                    break;
+                case 'flagged':
+                    strtag = 'flagged, importance_high';
+                    operation = 0;
+                    set_msg_as_flagged(msgid);
+                    break;
+                case 'unflagged':
+                    strtag = "flagged, importance_high";
+                    operation = 1;
+                    set_msg_as_unflagged(msgid);
+                    break;
+                case 'forwarded':
+                    strtag = "forwarded";
+                    operation = 0;
+                    set_msg_as_flagged(msgid);
+                case 'answered':
+                    strtag = "answered";
+                    operation = 0;
+                    set_msg_as_flagged(msgid);                                  
+                    
+            }                
+            
+            expresso_mail_archive.drawdata = null;
+            var tl = expresso_mail_archive.pattern.tagConfig(strtag, msgid, operation);
+            expresso_mail_archive.currenttag = flag;
+            expresso_mail_archive.taglist = tl;
+            expresso_mail_archive.progressbar = window.setTimeout("expresso_mail_archive.tagMessage()",1);
+        }
+        else {
+            set_message_flag(msg_number,flag, func_after_flag_change);
+        }
+        //Marcosw fim
 	}
 	
Index: sandbox/2.5.0-expresso1/expressoMail1_2/js/draw_api.js
===================================================================
--- sandbox/2.5.0-expresso1/expressoMail1_2/js/draw_api.js	(revision 7227)
+++ sandbox/2.5.0-expresso1/expressoMail1_2/js/draw_api.js	(revision 7320)
@@ -2680,6 +2680,10 @@
 	var option_mark_as_unseen = document.createElement("SPAN");
 		option_mark_as_unseen.className = "reply_options";
-	option_mark_as_unseen.onclick = function () {changeLinkState(this,'seen');
-		proxy_mensagens.proxy_set_message_flag(folder_id,'unseen');
+	    option_mark_as_unseen.onclick = function () {changeLinkState(this,'seen');
+
+        //Marcosw inicio - mudança no parametro passado
+		proxy_mensagens.proxy_set_message_flag(folder_id,'unseen',null,ID.split("_r_")[0]);
+        //Marcosw fim
+
 		write_msg(get_lang('Message marked as ')+get_lang("Unseen"));
 	};
@@ -2696,17 +2700,21 @@
 		option_mark_important.onclick = function() {
 			var _this = this;
-			proxy_mensagens.proxy_set_message_flag(folder_id,'unflagged', function(success){
-				if (success) {
-					changeLinkState(_this, 'important');
-					write_msg(get_lang('Message marked as ') + get_lang("Normal"));
-				}
-			} );
+
+            //Marcosw inicio - removido função anonima para evitar inconsistência
+            changeLinkState(_this, 'important');
+			proxy_mensagens.proxy_set_message_flag(folder_id,'unflagged',null,ID.split("_r_")[0]);
+            write_msg(get_lang('Message marked as ')+get_lang("Normal"));
+            //Marcosw fim
 
 		};
-		option_mark_important.innerHTML = get_lang("Normal");
+        option_mark_important.innerHTML = get_lang("Normal");
 	}
 	else{
-		option_mark_important.onclick = function() {changeLinkState(this,'normal');
-			proxy_mensagens.proxy_set_message_flag(folder_id,'flagged');
+		option_mark_important.onclick = function() {changeLinkState(this,'normal',null,ID.substr(0, ID.length-2));
+
+            //Marcosw inicio - mudança no parametro passado
+			proxy_mensagens.proxy_set_message_flag(folder_id,'flagged',null,ID.split("_r_")[0]);
+            //Marcosw fim
+
 			write_msg(get_lang('Message marked as ')+get_lang("Important"));
 		};
