Index: /trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- /trunk/expressoMail1_2/js/common_functions.js	(revision 4749)
+++ /trunk/expressoMail1_2/js/common_functions.js	(revision 4820)
@@ -224,5 +224,5 @@
 	div_attachment = document.getElementById("id_div_attachment");
 	var params = '';
-	
+
 	if (div_attachment == null){
 		var div_attachment = document.createElement("DIV");
@@ -343,37 +343,32 @@
 
 	divFile = document.createElement('div');
-	var inputFile = document.createElement("input");
-	inputFile.id        = "inputFile_"+id_border+"_"+countDivFiles; 
-	
-	inputFile.name      = "file_"+countDivFiles; 
-	inputFile.type      = "file"; 
-	inputFile.size      = 50;
-	inputFile.maxlength = 255;
-	
-	inputFile.onchange  = function () {
-		validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));
-		
-		openTab.autosave_timer[id_border] = setTimeout("save_msg("+id_border+")", autosave_time);
-	}; 
-		
-		
-	inputFile.onfocus = function () { 	
-		if (openTab.autosave_timer[id_border])
-			clearTimeout(openTab.autosave_timer[id_border]);
-	};	
-		
-	divFile.appendChild(inputFile); 	
-	var linkFile = document.createElement("a");	
-	linkFile.id        = "linkFile_"+id_border+"_"+countDivFiles;
-	linkFile.href      = 'javascript:void(0)';
-	linkFile.onclick   = function () {
-		removeFile("divFile_"+id_border+"_"+countDivFiles); return false;
-	};
-		
-	linkFile.innerHTML = get_lang("Remove");	
-		
-	divFile.appendChild(linkFile);
-	divFile.id = "divFile_"+id_border+"_"+countDivFiles;
-	divFiles.appendChild(divFile);
+
+ 	var inputFile = document.createElement("input");
+ 	inputFile.id        = "inputFile_"+id_border+"_"+countDivFiles;
+ 	inputFile.name      = "file_"+countDivFiles;
+ 	inputFile.type      = "file";
+ 	inputFile.size      = 50;
+ 	inputFile.maxlength = 255;
+ 	inputFile.onchange  = function () {
+            validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));
+            openTab.autosave_timer[id_border] = setTimeout("save_msg("+id_border+")", autosave_time);
+ 	};
+
+ 	inputFile.onfocus = function () {
+            if (openTab.autosave_timer[id_border])
+                clearTimeout(openTab.autosave_timer[id_border]);
+            };
+
+ 	divFile.appendChild(inputFile);
+
+ 	var linkFile = document.createElement("a");
+ 	linkFile.id        = "linkFile_"+id_border+"_"+countDivFiles;
+ 	linkFile.href      = 'javascript:void(0)';
+ 	linkFile.onclick   = function () {removeFile("divFile_"+id_border+"_"+countDivFiles); return false;};
+ 	linkFile.innerHTML = get_lang("Remove");
+
+        divFile.appendChild(linkFile);
+        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
+        divFiles.appendChild(divFile);
 
 	return inputFile;
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 4818)
+++ /trunk/expressoMail1_2/js/main.js	(revision 4820)
@@ -1786,12 +1786,9 @@
 	var handler_delete_msg = function(data){refresh(preferences.alert_new_msg);};
 
-	if (data.append != true || !data)
+ 	if (data == null || data.append != true )
 	{
-		RichTextEditor.saveFlag = 0;
+		RichTextEditor.saveFlag = -1;
 		if (! data.append)
-			if(data == 'Post-Content-Length')
-				write_msg(get_lang('The size of this message has exceeded  the limit (%1B).', preferences.max_attachment_size ? preferences.max_attachment_size : Element('upload_max_filesize').value));
-			else
-				write_msg(get_lang('ERROR saving your message.'));
+			write_msg('ERROR saving your message.');
 		else
 		{
@@ -1815,114 +1812,88 @@
 
 		var newTitle = document.getElementById('subject_'+border_id).value;
-		if (newTitle == '')
-			newTitle = get_lang("No subject");
-		set_border_caption('border_id_'+border_id, newTitle);
+		if (newTitle.length > 18)
+                    newTitle = newTitle.substr(18) + '...';
+                else if (newTitle == '')
+                    newTitle = get_lang("No subject");
+		document.getElementById('font_border_id_'+border_id).innerHTML = newTitle; 
 
 		// Replace the embedded images for new uids
-		var mainField = document.getElementById('body_'+border_id).contentWindow;
-		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)
+		var mainField     = document.getElementById('body_'+border_id).contentWindow;
+                var content_body  = mainField.document.getElementsByTagName('body').item(0).innerHTML;
+                var body_images   = content_body.match(/msg_num=\d*/g);
+                var folder_images = content_body.match(/msg_folder=[^&]*&/g);
+
+                if (body_images != null)
 		{
-			for (var i=0; i<body_images.length; i++){
-				content_body = 	content_body.replace(body_images[i],"msg_num="+openTab.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;
-		}
+                    for (var i=0; i<body_images.length; i++)
+                    {
+                        if( folder_images != null)
+                            content_body = content_body.replace(folder_images[i], "msg_folder=INBOX" + cyrus_delimiter + draftsfolder +"&");
+
+                        content_body = content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]);
+                    }
+
+                    var images_part   = content_body.match(/msg_part=[0-9.]*/g);
+
+                    if(images_part != null)
+                    {
+                        for (var x = 0; x < images_part.length; x++)
+                        {
+                            var position = images_part[x].substr(9,images_part[x].length);
+                            content_body = content_body.replace(images_part[x],'msg_part(||.|||.||)='+data.imagesParts[position]);
+                        }
+
+                    }
+                    content_body = content_body.replace(/msg_part\(\|\|\.\|\|\|\.\|\|\)=/g,'msg_part=');
+
+                    mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body;
+                }
 
 		//Replace all files to new files
 		var divFiles = Element("divFiles_"+border_id);
-		elFiles = divFiles.getElementsByTagName("input");
-		var countCheck =0;
-		for (var i=0; i<elFiles.length; i++) {
-			if(elFiles[i].value !=""){
-				if (elFiles[i].type == "checkbox") {
-					countCheck++;
-				}
-				else {
-					elFiles[i].value ="";
-					parantNodeFile = elFiles[i].parentNode.parentNode;
-					parantNodeFile.removeChild(elFiles[i].parentNode);
-					i--;
-				}
-
-			}
-		};
+		divFiles.innerHTML = '';
 
 		var attach_files = connector.unserialize(data.files);
 		if (attach_files != null) {
-			openTab.countFile[border_id] = attach_files.length;
-			att_index = countCheck;
-		for (att_index; att_index < attach_files.length; att_index++){
-
-			var link_attachment = document.createElement("A");
-			var fileName = attach_files[att_index].substr(0,attach_files[att_index].indexOf('_SIZE_'));
-			var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].indexOf('_SIZE_')+6))/1024
-			link_attachment.innerHTML = fileName + " ("+borkb((parseInt(fileSize)*1024))+")";
-
-			var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','"+(att_index+2)+"','base64'";
-
-			link_attachment.setAttribute("href", "javascript:download_attachments("+href+")");
-
-			var a_tmp = href.split(',');
-			a_tmp[2] = fileName;
-			s_tmp = escape(connector.serialize(a_tmp));
-
-			var check_attachment = document.createElement("INPUT");
-			check_attachment.type = 'CHECKBOX';
-			check_attachment.name = 'forwarding_attachments[]';
-			check_attachment.value = trim(s_tmp);
-
-                        if (!divFiles.childNodes[0])
-                        {
-                            divFiles.appendChild(document.createElement("BR"));
-                        }
-                        else
-                            {
-                                divFiles.insertBefore(document.createElement("BR"),divFiles.childNodes[0]);
-                            }
-
-                        divFiles.insertBefore(link_attachment,divFiles.childNodes[0]);
-                        divFiles.insertBefore(check_attachment,divFiles.childNodes[0]);
-
-			check_attachment.checked = true;
-		}
-	}
+                    openTab.countFile[border_id] = attach_files.length;
+                    for (att_index = 0; att_index < attach_files.length; att_index++){
+
+                        var link_attachment = document.createElement("a");
+                        var fileName = attach_files[att_index].substr(0, attach_files[att_index].lastIndexOf('_SIZE_'));
+                        var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].lastIndexOf('_SIZE_')+6))/1024
+                        link_attachment.innerHTML = fileName + " ("+parseInt(fileSize)+" kb)";
+
+                        var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','0."+(att_index+1)+"','base64'";
+
+                        link_attachment.setAttribute("href", "javascript:download_attachments("+href+")");
+
+                        var a_tmp = href.split(',');
+                        a_tmp[2] = fileName;
+                        s_tmp = escape(connector.serialize(a_tmp));
+
+                        var check_attachment = document.createElement("input");
+                        check_attachment.type = 'checkbox';
+                        check_attachment.name = 'forwarding_attachments[]';
+                        check_attachment.value = s_tmp;
+
+                        check_attachment.checked = true;
+                        check_attachment.setAttribute("checked", "checked");
+
+                        divFiles.appendChild(check_attachment);
+                        divFiles.appendChild(link_attachment);
+                        divFiles.appendChild(document.createElement("br"));
+                    }
+                }
+
 		if (message_id)
 		{
-			cExecute ("$this.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
-			if (openTab.imapBox[0] == "INBOX/"+draftsfolder)
-			{
-				//Update mailbox
-						var tr_msg = document.getElementById(message_id);
-				change_tr_properties(tr_msg, data.msg_no, data.subject);
-			}
-		} else {
-			refresh();
+                    cExecute ("$this.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
+                    if (openTab.imapBox[0] == "INBOX" + cyrus_delimiter + draftsfolder)
+                    {
+                        //Update mailbox
+                        var tr_msg = document.getElementById(message_id);
+                        change_tr_properties(tr_msg, data.msg_no, data.subject);
+                    }
+		
 		}
 
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 4814)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 4820)
@@ -923,5 +923,5 @@
 // Draw the inbox and another folders
 function draw_box(headers_msgs, msg_folder, alternate){
-	/*
+        /*
 	 * When the paging response is not in the correct folder you need to change folder
 	 * This occurs when the Ajax response is not fast enough and the user click in outher
@@ -1221,9 +1221,9 @@
 // Passar o parâmetro offset para esta função
 function make_tr_message(headers_msgs, msg_folder, offsetToGMT){
-		if (typeof offsetToGMT == 'undefined')
-		{
-			// In older local messages headers_msgs.offsetToGMT is undefined.
-			offsetToGMT = typeof headers_msgs.offsetToGMT != 'undefined'?headers_msgs.offsetToGMT:0;
-		}
+                if (typeof offsetToGMT == 'undefined')
+                {
+                    // In older local messages headers_msgs.offsetToGMT is undefined.
+                    offsetToGMT = typeof headers_msgs.offsetToGMT != 'undefined'?headers_msgs.offsetToGMT:0;
+                }
 		var tr_element = document.createElement('tr');
 		if(typeof(preferences.line_height) != 'undefined')
@@ -1235,8 +1235,8 @@
 		if(headers_msgs.msg_sample && preferences.preview_msg_subject == "1")
 		{
-			if (cssForResizing) //Colunas redimensionaveis - nao trunca 
-				tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,180) + "..."; //trecho do body que sera exibido com o assunto; 
- 	        else 
- 	            tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,120) + "..."; //trecho do body que sera exibido com o assunto; 
+			if (cssForResizing) //Colunas redimensionaveis - nao trunca
+				tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,180) + "..."; //trecho do body que sera exibido com o assunto;
+			else
+				tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,120) + "..."; //trecho do body que sera exibido com o assunto;
 		}
 
@@ -1406,15 +1406,15 @@
 		if ((headers_msgs.subject)&&(headers_msgs.subject.length > 50))
 		{
-			if (cssForResizing) 
-				//Colunas redimensionaveis - nao trunca 
- 		        td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>"; 
- 		    else { 
-					//Modificacao para evitar que o truncamento do assunto quebre uma NCR - #1189 
- 		            pos = headers_msgs.subject.indexOf("&",45); 
- 		            if ((pos > 0) && (pos <= 50) && ((headers_msgs.subject.charAt(pos+5) == ";") || (headers_msgs.subject.charAt(pos+6) == ";"))) 
- 		                td_element4.innerHTML += headers_msgs.subject.substring(0,pos+6) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>"; 
- 		            else 
- 		               td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem; 
-				} 
+			if (cssForResizing)
+				//Colunas redimensionaveis - nao trunca
+				td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";
+			else {
+				//Modificacao para evitar que o truncamento do assunto quebre uma NCR - #1189
+				pos = headers_msgs.subject.indexOf("&",45);
+				if ((pos > 0) && (pos <= 50) && ((headers_msgs.subject.charAt(pos+5) == ";") || (headers_msgs.subject.charAt(pos+6) == ";")))
+					td_element4.innerHTML += headers_msgs.subject.substring(0,pos+6) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";
+				else
+					td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
+			}
 		}
 		else
@@ -1567,10 +1567,10 @@
 	img_next_msg.style.cursor = 'pointer';
 
-	var folder_id = ID.match(/\d+/)[0];
-	var folder;
-
-	//Correção para fazer funcionar e-mails assinados no formato encapsulado.
-   // folder_id = info_msg.original_ID ? info_msg.original_ID: info_msg.msg_number;
-	//if ((folder = document.getElementById(info_msg.msg_number)) == null)
+        var folder_id = ID.match(/\d+/)[0];
+        var folder;
+
+        //Correção para fazer funcionar e-mails assinados no formato encapsulado.
+       // folder_id = info_msg.original_ID ? info_msg.original_ID: info_msg.msg_number;
+        //if ((folder = document.getElementById(info_msg.msg_number)) == null)
 	if ((folder = Element(info_msg.original_ID)) == null)
 		folder = Element(info_msg.msg_number);
@@ -1579,5 +1579,5 @@
 		delete_border(ID);
 		return;
-	}
+		}
 	if (folder){ // mensagem local criptografada nao tem ID da pasta local
 		if (folder.nextSibling){
@@ -1801,5 +1801,5 @@
 	option_forward.onclick = function(){new_message('forward', ID);};
 	option_forward.onmouseover=function () { this.className='message_options_active'; };
-	option_forward.onmouseout=function () { this.className='message_options' };
+        option_forward.onmouseout=function () { this.className='message_options' };
 	option_forward.innerHTML = get_lang('Forward');
 	options.appendChild(space1);
@@ -2271,5 +2271,5 @@
 		div_attach.setAttribute("class", "expressomail-attachments");
 		div_attach.setAttribute("className", "expressomail-attachments"); //for IE
-		
+
 		var div_attach_lbl = document.createElement("span");
 		div_attach_lbl.setAttribute("class", "expressomail-attachments-label");
@@ -2282,21 +2282,21 @@
 		div_attach_list.setAttribute("className", "expressomail-attachments-list"); //for IE
 		
-		if(info_msg.attachments.length > 1) {
+			if(info_msg.attachments.length > 1) {
 			var li_link_attachment = document.createElement("LI");
-			var link_attachment	= document.createElement("A");
+				var link_attachment	 = document.createElement("A");
 			link_attachment.setAttribute("class", "expressomail-attachments-link");
 			link_attachment.setAttribute("className", "expressomail-attachments-link"); //for IE
 	
-			if(proxy_mensagens.is_local_folder(current_folder))
-				link_attachment.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-			else
-				link_attachment.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-			link_attachment.innerHTML = " "+info_msg.attachments.length+' '+get_lang('files')+' :: '+get_lang('Download all atachments');
+				 if(proxy_mensagens.is_local_folder(current_folder))
+					link_attachment.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+				else
+					link_attachment.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+				link_attachment.innerHTML = " "+info_msg.attachments.length+' '+get_lang('files')+' :: '+get_lang('Download all atachments');
 			li_link_attachment.appendChild(link_attachment);
 			div_attach_list.appendChild(li_link_attachment);
-		}
+			}
 		
-		if(parseInt(preferences.remove_attachments_function))
-		{
+			if(parseInt(preferences.remove_attachments_function))
+			{
 			var li_link_attachment = document.createElement("LI");
 			var link_attachment	= document.createElement("A");
@@ -2308,6 +2308,6 @@
 			li_link_attachment.appendChild(link_attachment);
 			div_attach_list.appendChild(li_link_attachment);
-		}
-		
+			}
+
 		for (var i=0; i<info_msg.attachments.length; i++)
 		{
@@ -2331,5 +2331,5 @@
 				link_attachment.appendChild(link_import_attachment);
 			}
-		
+
 			li_link_attachment.appendChild(link_attachment);
 			div_attach_list.appendChild(li_link_attachment);
@@ -2346,5 +2346,5 @@
 		tr6.appendChild(td6);
 		tbody_message_others_options.appendChild(tr6);
-	}	
+	}
 	//k!!
 	var div = document.createElement("DIV");
@@ -2457,5 +2457,5 @@
 	//k
 	
-	if ( (info_msg.thumbs) && (info_msg.thumbs.length > 0) ){
+	if ((info_msg.thumbs)&&(info_msg.thumbs.length > 0)){
 		var div_thumbs = document.createElement("DIV");
 		div_thumbs.setAttribute("class", "expressomail-thumbs");
@@ -2473,6 +2473,6 @@
 		var div_thumbs_lbl_a  = document.createElement("A");
 
-		if(info_msg.thumbs.length > 1){				
-			if(proxy_mensagens.is_local_folder(current_folder))
+		if(info_msg.thumbs.length > 1){
+			 if(proxy_mensagens.is_local_folder(current_folder))
 				div_thumbs_lbl_a.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
 			else
@@ -2487,10 +2487,10 @@
 		div_thumbs_lbl_sp.appendChild(div_thumbs_lbl_a);
 		div_thumbs_lbl.appendChild(div_thumbs_lbl_sp);
-		
+
 		var div_thumbs_lbl_sp2   = document.createElement("SPAN");
 		div_thumbs_lbl_sp2.setAttribute("class", "message_tips");
 		div_thumbs_lbl_sp2.setAttribute("className", "message_tips"); //for IE
 		div_thumbs_lbl_sp2.innerHTML = get_lang("<strong>Tip:</strong> <span>For faster save, click over the image with <em>right button</em>.</span>");
-		
+
 		var ul_thumbs_list = document.createElement("UL");
 		ul_thumbs_list.setAttribute("class", "expressomail-thumbs-list");
@@ -2530,5 +2530,5 @@
 			show_div_address_full(ID,'cc');
 	}
-	
+
 	//k!
 	/*
@@ -2555,5 +2555,5 @@
 			});
 		});
-	}
+}
 	//k!!
 }
@@ -2650,5 +2650,5 @@
 		if(!expresso_offline)
 			var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
-		else			
+		else
 			var option_send_and_file='';
 	}
@@ -2671,5 +2671,5 @@
 
 	tr_menu_new_message.appendChild(td_menu_new_message);
-	
+
 	
 	tbody_menu_new_message.appendChild(tr_menu_new_message);
@@ -2705,19 +2705,19 @@
 	var td1_2 = document.createElement("TD");
 	tr1_2.style.display = 'none';
-	td1_2.innerHTML = get_lang("Reply to")+":";
+        td1_2.innerHTML = get_lang("Reply to")+":";
 	td1_2.setAttribute("noWrap","true");
 	td1_2.style.width = "1%";
 
 	var td_replyto = document.createElement("TD");
-	td_replyto.setAttribute("noWrap","true");
+        td_replyto.setAttribute("noWrap","true");
 	td_replyto.style.width = "100%";
 
-	var input_replyto = document.createElement('INPUT');
+        var input_replyto = document.createElement('INPUT');
 	input_replyto.id = "replyto_"+ID;
-	input_replyto.name = "input_replyto";
+        input_replyto.name = "input_replyto";
 	input_replyto.setAttribute("tabIndex","1");
-	input_replyto.style.width = "100%";
+        input_replyto.style.width = "100%";
 	input_replyto.setAttribute("wrap","soft");
-	input_replyto.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
+        input_replyto.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
 	input_replyto.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
 
@@ -3200,27 +3200,27 @@
 	tr5.appendChild(td5);
 	tr5.appendChild(td_return_receipt);
-	
-	 if ( ! expresso_offline )
-        {
-                var text_plain = td_return_receipt.appendChild(
-                        document.createElement( 'span' )
-                ).appendChild(
-                        document.createTextNode( ' | ' )
-                ).parentNode.appendChild(
-                        document.createTextNode( get_lang('Send this mail as text plain') + '.')
+
+        if ( ! expresso_offline )
+	{
+		var text_plain = td_return_receipt.appendChild(
+			document.createElement( 'span' )
+		).appendChild(
+			document.createTextNode( ' | ' )
+		).parentNode.appendChild(
+			document.createTextNode( get_lang('Send this mail as text plain') + '.')		
                 ).parentNode.appendChild(
                         document.createElement( 'input' )
-                );
+		);
                 text_plain.setAttribute( 'tabIndex', '-1' );
                 text_plain.id = 'textplain_rt_checkbox_' + ID ;
                 text_plain.type = "checkbox";
                 text_plain.onclick = function ()
-                {
-                        RichTextEditor.plain( this.checked );
-                        document.getElementById( 'viewsource_rt_checkbox_' + ID ).parentNode.style.display = ( this.checked ) ? 'none' : '';
-                };
+		{
+			RichTextEditor.plain( this.checked );
+			document.getElementById( 'viewsource_rt_checkbox_' + ID ).parentNode.style.display = ( this.checked ) ? 'none' : '';
+		};
 				//text_plain = text_plain.parentNode.appendChild(input_checkbox);
-        }
-	
+	}
+
 	
 	tbody_message.appendChild(tr5);
@@ -3245,17 +3245,27 @@
 	}
 
-	
+        /**
+ 	* event to enable autosave_draft on file attachment
+ 	*/
+ 	function save_onchange_attachment_handler () {
+            away = false;
+            var save_link = Element("save_message_options_"+ID);
+            save_link.onclick = function onclick(event) {
+                openTab.toPreserve[ID] = true;
+                save_msg(ID);
+            };
+            save_link.className = 'message_options';
+        };
+
 	var add_files = document.createElement("A");
 	add_files.setAttribute("href", "javascript:void(0)");
-	
-	add_files.onclick = function () { 
-  	  	 	                var obj = addFile(ID); 
-  	  	 	                if (preferences.auto_save_draft == 1 && obj) { 
-  	  	 	                        if ( obj.addEventListener ) 
-  	  	 	                                obj.addEventListener('click', save_onchange_attachment_handler, false); 
-  	  	 	                } 
-  	  	 	                return false; 
-  	  	 	        }; 
-	
+	add_files.onclick = function () {
+            var obj = addFile(ID);
+            if (preferences.auto_save_draft == 1 && obj) {
+                if ( obj.addEventListener )
+                    obj.addEventListener('click', save_onchange_attachment_handler, false);
+            }
+            return false;
+ 	};
 	add_files.innerHTML =  get_lang("Attachments: add+");
 	add_files.setAttribute("tabIndex","-1");
@@ -3313,5 +3323,5 @@
 		draw_from_field(sel_from,tr1_1);
 	resizeWindow();
-	
+       
         if ( ! expresso_offline )
         {
@@ -3514,6 +3524,6 @@
 		td221.className = 'dsused';
 
-	td221.setAttribute("style","width: 100%");	
-		
+        td221.setAttribute("style","width: 100%");
+        
 	tr221.appendChild(td221);
 	tbody221.appendChild(tr221);
@@ -3700,5 +3710,5 @@
 	content_id_0.appendChild(table);
 }
-var idx_cc = 0;
+	var idx_cc = 0;
 
 function draw_plugin_cc(ID, addrs){
