Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 61)
+++ trunk/expressoMail1_2/js/main.js	(revision 63)
@@ -240,5 +240,15 @@
 
 function new_message(type, border_ID){
-	var new_border_ID = draw_new_message();
+	var new_border_ID = draw_new_message();	
+	// Salva a pasta da mensagem respondida ou encaminhada:
+	var folder_message = Element("input_folder_"+border_ID);
+	if(folder_message) {
+		var input_current_folder = document.createElement('input');	
+		input_current_folder.id = "new_input_folder_"+border_ID;
+		input_current_folder.name = "input_folder";
+		input_current_folder.type = "hidden";
+		input_current_folder.value = folder_message.value;
+		Element("content_id_" + new_border_ID).appendChild(input_current_folder);
+	}//Fim.
 	var title = '';
 	data = [];
@@ -393,5 +403,6 @@
 					tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
 					a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
-					divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+a_tmp.join(',')+"\"/>";
+					s_tmp = escape(connector.serialize(a_tmp));
+					divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
 					divFiles.appendChild(link_attachment);
 				}
@@ -585,21 +596,23 @@
 
 		for (var i=0; i<msgs_to_set.length; i++){
-			switch(data.flag){
-				case "unseen":
-					set_msg_class_to_unread(msgs_to_set[i]);
-					Element("check_box_message_" + msgs_to_set[i]).checked = false;
-					break;
-				case "seen":
-					set_msg_class_to_read(msgs_to_set[i], false);
-					Element("check_box_message_" + msgs_to_set[i]).checked = false;
-					break;
-				case "flagged":
-					set_msg_class_to_flagged(msgs_to_set[i]);
-					document.getElementById("check_box_message_" + msgs_to_set[i]).checked = false;
-					break;
-				case "unflagged":
-					set_msg_class_to_unflagged(msgs_to_set[i]);
-					Element("check_box_message_" + msgs_to_set[i]).checked = false;
-					break;
+			if(Element("check_box_message_" + msgs_to_set[i])){
+				switch(data.flag){
+					case "unseen":
+						set_msg_class_to_unread(msgs_to_set[i]);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "seen":
+						set_msg_class_to_read(msgs_to_set[i], false);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "flagged":
+						set_msg_class_to_flagged(msgs_to_set[i]);
+						document.getElementById("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "unflagged":
+						set_msg_class_to_unflagged(msgs_to_set[i]);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+				}
 			}
 		}
@@ -607,9 +620,12 @@
 	}
 	
+	var folder = get_current_folder();
 	if (msgs_to_set == 'get_selected_messages')
 		var msgs_to_set = this.get_selected_messages();
+	else
+		folder = Element("input_folder_"+msgs_to_set+"_r").value;
 	
 	if (msgs_to_set)
-		cExecute ("$this.imap_functions.set_messages_flag&folder="+get_current_folder()+"&msgs_to_set="+msgs_to_set+"&flag="+flag, handler_set_messages_flag);
+		cExecute ("$this.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, handler_set_messages_flag);
 	else
 		write_msg(get_lang('No selected message.'));		
@@ -618,8 +634,9 @@
 // By message number
 function set_message_flag(msg_number, flag){
+	var msg_number_folder = Element("new_input_folder_"+msg_number+"_r");
 	var handler_set_messages_flag = function (data){
 		if(!verify_session(data))
 			return;
-		if (data.status) {
+		if (data.status && Element("td_message_answered_"+msg_number)) {	
 			if(flag == 'answered')
 				Element("td_message_answered_"+msg_number).innerHTML = '<img src=templates/default/images/answered.gif title=Respondida>';
@@ -628,5 +645,5 @@
 		}
 	}
-	cExecute ("$this.imap_functions.set_messages_flag&folder="+get_current_folder()+"&msgs_to_set="+msg_number+"&flag="+flag, handler_set_messages_flag);
+	cExecute ("$this.imap_functions.set_messages_flag&folder="+( msg_number_folder ?  msg_number_folder.value : get_current_folder() )+"&msgs_to_set="+msg_number+"&flag="+flag, handler_set_messages_flag);
 }
 
