Index: /trunk/expressoMail1_2/templates/classic/print.css
===================================================================
--- /trunk/expressoMail1_2/templates/classic/print.css	(revision 4757)
+++ /trunk/expressoMail1_2/templates/classic/print.css	(revision 4757)
@@ -0,0 +1,7 @@
+.print-all-messages h1 { font-size: 1.35em; }
+.print-all-messages h2 { font-size: 1.05em; }
+.print-all-messages tbody { font-size: 0.95em; }
+.print-all-messages thead td { font-weight: bold; padding: 3px; border-bottom: solid 2px #999; }
+.print-all-messages tbody td { border-bottom: solid 1px #ccc; }
+.print-all-messages img { display: none; }
+.print-all-messages input { display: none; }
Index: /trunk/expressoMail1_2/templates/default/print.css
===================================================================
--- /trunk/expressoMail1_2/templates/default/print.css	(revision 4757)
+++ /trunk/expressoMail1_2/templates/default/print.css	(revision 4757)
@@ -0,0 +1,7 @@
+.print-all-messages h1 { font-size: 1.35em; }
+.print-all-messages h2 { font-size: 1.05em; }
+.print-all-messages tbody { font-size: 0.95em; }
+.print-all-messages thead td { font-weight: bold; padding: 3px; border-bottom: solid 2px #999; }
+.print-all-messages tbody td { border-bottom: solid 1px #ccc; }
+.print-all-messages img { display: none; }
+.print-all-messages input { display: none; }
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 4733)
+++ /trunk/expressoMail1_2/js/main.js	(revision 4757)
@@ -3,7 +3,5 @@
 // tempo do auto save (em milisegundos)
 // 20000 = 20 segundos
-var autosave_time = 5000;
-
-var cabecalho = '<h4>ExpressoLivre - ExpressoMail</h4>'; 
+var autosave_time = 20000;
 
 function init(){
@@ -22,13 +20,4 @@
 
 		preferences = data;
-		
-		if(preferences.show_name_print_messages == "1") { 
-			var getUserName = document.getElementById("user_info"); 
-			var userName = getUserName.innerHTML; 
-			var position = userName.indexOf("-"); 
-			var userName = userName.substring(3, position); 
-			cabecalho = '<h4>' + userName; 
- 	  	}  
-		
 		current_folder="INBOX";
 		
@@ -90,9 +79,8 @@
 
 	cExecute ("$this.functions.get_preferences", save_preferences);
-	cExecute ("phpgwapi.browser.isMobile", function( data ) 
- 	{ 
- 	    mobile_device = ( ( data.constructor == Boolean ) ? data : ( data === 'true' ) ); 
- 	} );
-	
+        cExecute ("phpgwapi.browser.isMobile", function( data )
+	{
+		mobile_device = ( ( data.constructor == Boolean ) ? data : ( data === 'true' ) );
+	} );
 	setTimeout('auto_refresh()', time_refresh);
 
@@ -902,11 +890,10 @@
 		}
 	var new_border_ID = draw_new_message(parseInt(border_ID));
-
 	if(typeof(openTab.type[new_border_ID]) != "undefined") {
 		if(tabTypes[type] == openTab.type[new_border_ID]) {
-			if (type != 'edit') 
-			{ 
- 		        return new_border_ID; 
- 		    }
+                    if (type != 'edit')
+                    {
+                        return new_border_ID;
+                    }			
 		} else {
 			var a_types = { 6 : get_lang("Forward"),7 : get_lang("Reply"), 
@@ -926,5 +913,4 @@
 		}
 	}
-
 	if (new_border_ID == false)
 	{
@@ -1386,4 +1372,14 @@
 	}
 
+        if ( ! expresso_offline )
+	{
+		if ( mobile_device )
+		{
+			var text_plain = document.getElementById( 'textplain_rt_checkbox_' + new_border_ID );
+			text_plain.click( );
+			text_plain.parentNode.style.display = 'none';
+		}
+	}
+
 	if (preferences.auto_save_draft == 1)
 	{
@@ -1670,14 +1666,12 @@
 	};
 
-	var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + ID ); 
- 	mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false; 
-	
+        var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + ID );
+	mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false;
+
 	var textArea = document.createElement("TEXTAREA");
 	textArea.style.display='none';
 	textArea.name = "body";
 	body = document.getElementById("body_"+ID);
-
 	textArea.value = ( ( mail_as_plain ) ? body.previousSibling.value : ( '<body>\r\n' + body.contentWindow.document.body.innerHTML + '\r\n</body>' ) );
-	
 	var input_folder = document.createElement("INPUT");
 	input_folder.style.display='none';
@@ -1714,11 +1708,10 @@
 	form.appendChild(msg_id);
 
-	var mail_type = document.createElement('input');
-    mail_type.setAttribute('type', 'hidden');
- 	mail_type.name = 'type'; 
- 	mail_type.value = ( mail_as_plain ) ? 'plain' : 'html';
-	form.parentNode.appendChild(mail_type);
-	
-	
+    var mail_type = document.createElement('input');
+	mail_type.setAttribute('type', 'hidden');
+	mail_type.name = 'type';
+	mail_type.value = ( mail_as_plain ) ? 'plain' : 'html';
+    form.parentNode.appendChild(mail_type);
+
 	var _subject = trim(Element("subject_"+ID).value);
 	if((_subject.length == 0) && !confirm(get_lang("Send this message without a subject?"))) {
@@ -1747,7 +1740,5 @@
 	}
 	else
-	{
 		cExecuteForm("$this.imap_functions.send_mail", form, handler_send_message, ID);
-	}
 }
 function change_tr_properties(tr_element, newUid, newSubject){
@@ -1769,14 +1760,17 @@
 }
 
-function return_save(data,border_id,folder_name,folder_id,message_id){
+function return_save(data,border_id,folder_name,folder_id,message_id)
+{
 	Element("send_button_"+border_id).style.visibility="visible";
-	var handler_delete_msg = function(data){refresh(preferences.alert_new_msg);};
-
-	if (data == null || data.append != true )
+	var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg); };
+
+	if (data.append != true || !data)
 	{
-
-                RichTextEditor.saveFlag = 0;
+		RichTextEditor.saveFlag = 0;
 		if (! data.append)
-			write_msg('ERROR saving your message.');
+			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.'));
 		else
 		{
@@ -1798,95 +1792,118 @@
 		openTab.imapUid[border_id] = data.msg_no;
 		openTab.imapBox[border_id] = data.folder_id;
-		
+
 		var newTitle = document.getElementById('subject_'+border_id).value;
-		if (newTitle.length > 18)
-			newTitle = newTitle.substr(18) + '...';
-		else if (newTitle == '')
+		if (newTitle == '')
 			newTitle = get_lang("No subject");
-		document.getElementById('font_border_id_'+border_id).innerHTML = newTitle;
-		
+		set_border_caption('border_id_'+border_id, 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 folder_images = content_body.match(/msg_folder=[^&]*&/g); 		
-		
-		if (body_images != null)
+		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)
 		{
-                    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;
-                 }       
-		
-
-	
+			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;
+		}
+
 		//Replace all files to new files
 		var divFiles = Element("divFiles_"+border_id);
-		
-		divFiles.innerHTML = '';
-		
+		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--;
+				}
+
+			}
+		};
+
 		var attach_files = connector.unserialize(data.files);
 		if (attach_files != null) {
 			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"));
-			}			
-		}
-		
-		
+			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;
+		}
+	}
 		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" + cyrus_delimiter + draftsfolder)
+			if (openTab.imapBox[0] == "INBOX/"+draftsfolder)
 			{
 				//Update mailbox
-				var tr_msg = document.getElementById(message_id);
+						var tr_msg = document.getElementById(message_id);
 				change_tr_properties(tr_msg, data.msg_no, data.subject);
 			}
-		
-		}
+		} else {
+			refresh();
+		}
+
 		var save_link = Element("save_message_options_"+border_id);
 		save_link.onclick = '';
@@ -1894,6 +1911,6 @@
 		watch_changes_in_msg(border_id);
 		write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder(folder_name)));
-		setTimeout( function(){ RichTextEditor.saveFlag = 1; }, 1000 );
-	}		
+                setTimeout( function(){ RichTextEditor.saveFlag = 1; }, 1000 );
+	}
 }
 
@@ -1929,7 +1946,7 @@
 	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 mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + border_id ); 
- 	mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false;
-	
+        var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + border_id );
+	mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false;
+
 	var textArea = document.createElement("TEXTAREA");
 	textArea.style.display='none';
@@ -1938,7 +1955,5 @@
 	if (! body)
 		return;
-	
 	textArea.value = ( ( mail_as_plain ) ? body.previousSibling.value : ( '<body>\r\n' + body.contentWindow.document.body.innerHTML + '\r\n</body>' ) );
-	
 	var input_folder = document.createElement("INPUT");
 	input_folder.style.display='none';
@@ -1955,5 +1970,6 @@
 
 
-	if (is_ie){
+	if (is_ie)
+        {
 		var i = 0;
 		while (document.forms(i).name != "form_message_"+border_id){i++}
@@ -1961,5 +1977,8 @@
 	}
 	else
+        {
 		form = document.forms["form_message_"+border_id];
+        }
+        
 	form.appendChild(textArea);
 	form.appendChild(input_folder);
@@ -1967,22 +1986,21 @@
 	form.appendChild(input_insertImg);
 
-	
-	var mail_type;       
- 
-	if (is_ie) 
-	{ 
-		mail_type = document.createElement('<input type="hidden" />'); 
- 	} 
- 	else 
- 	{ 
-		mail_type = document.createElement('input'); 
-		mail_type.setAttribute('type', 'hidden'); 
- 	} 
- 	mail_type.setAttribute('name', 'type'); 
- 	var mail_type_value = ( mail_as_plain ) ? 'plain' : 'html'; 
- 	mail_type.setAttribute("value", mail_type_value);
-
-	form.parentNode.appendChild( mail_type );
-	
+        var mail_type;
+        
+        if (is_ie)
+        {
+            mail_type = document.createElement('<input type="hidden" />');
+        }
+        else
+            {
+                mail_type = document.createElement('input');
+                mail_type.setAttribute('type', 'hidden');
+            }
+        mail_type.setAttribute('name', 'type');
+        var mail_type_value = ( mail_as_plain ) ? 'plain' : 'html';
+	mail_type.setAttribute("value", mail_type_value);
+
+	form.parentNode.appendChild(mail_type);
+
 	cExecuteForm ("$this.imap_functions.save_msg", form, handler_save_msg,border_id);
 }
@@ -2165,27 +2183,32 @@
 
 	var folder= Element('border_id_0').innerHTML;
-	var body = Element('divScrollMain_'+numBox).innerHTML;
+	var thead = Element('divScrollHead_'+numBox).firstChild.firstChild.innerHTML;
+	var tbody = Element('divScrollMain_'+numBox).firstChild.firstChild.innerHTML;
 	var print_width = screen.width - 200;
 	var x = ((screen.width - print_width) / 2);
 	var y = ((screen.height - 400) / 2) - 35;
 	var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y);
-	var seekDot = /\<img /gi;
-	body = body.replace(seekDot, "<img style='display:none' ");
-	seekDot = /\<input /gi;
-	body = body.replace(seekDot, "<input style='display:none' ");
+	seekDot = /width="24"/gi;
+	thead = thead.replace(seekDot, "style='display:none'");
+	tbody = tbody.replace(seekDot, "style='display:none'");
+	seekDot = /width="16"/gi;
+	thead = thead.replace(seekDot, "style='display:none'");
+	tbody = tbody.replace(seekDot, "style='display:none'");
+	seekDot = /width="12"/gi;
+	thead = thead.replace(seekDot, "style='display:none'");
+	tbody = tbody.replace(seekDot, "style='display:none'");
 
 	while (1){
 		try{
-			var html = '<br>';
-			html += cabecalho + "</h4><hr>";
-			html += folder+"<hr>";
-
-			window_print.document.body.innerHTML = html + '<blockquote><font size="2">' +
-			'<table style="font-size:12" width="'+(is_ie ? "94%" : "100%" )+'">' + 
-			'<TD width="25%" align="center">'+get_lang("Who")+'</TD>' + 
-			'<TD align="center" width="'+(is_ie ? "50%" : "55%" )+'">'+get_lang("Subject")+'</TD>' + 
-			'<TD align="center" width="11%">'+get_lang("Date")+'</TD>' + 
-			'<TD align="center" width="'+(is_ie ? "10%" : "9%" )+'">'+get_lang("Size")+'</TD></TR></table>'
-			+ body + '</font></blockquote>';
+			window_print.document.open();
+			var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>'
+			+ '<head><link rel="stylesheet" type="text/css" href="templates/'+template+'/print.css"></head>'
+			+ '<body class="print-all-messages"><h1>ExpressoLivre - ExpressoMail</h1>'
+			+ '<h2>'+folder+'</h2><hr/><blockquote><font size="2">'
+			+ '<table width="100%" cellpadding="0" cellspacing="0">'
+			+ '<thead>' + thead + '</thead><tbody>' + tbody + '</tbody>'
+			+ '</table></font></blockquote></body></html>';
+			window_print.document.write(html);
+			window_print.document.close();
 			break;
 		}
@@ -2246,6 +2269,6 @@
 		var attachs = "";
 		var show_attachs = "";
-		var ii = a.length >2?2:1; 
- 	    for(i=ii;i<a.length;i++)
+                var ii = a.length >2?2:1;
+		for(i=ii;i<a.length;i++)
 		{
 			if(a[i].tagName && a[i].tagName == "A")
@@ -2257,15 +2280,13 @@
 	} else{
 		show_attachs = "";
-	}
-        
+	}       
 	var current_path = window.location.href.substr(0,window.location.href.lastIndexOf("/"));
-
-	var head = '<head><title></title><link href="'+current_path+'/templates/default/main.css" type="text/css" rel="stylesheet"></head>'; 
-	window_print.document.write(head); 
-	
+	var head = '<head><title></title><link href="'+current_path+'/templates/default/main.css" type="text/css" rel="stylesheet"></head>';
+	window_print.document.write(head);
+
 	while (1){
 		try{
 			var html ='<body>';
-			html += cabecalho + "</h4><hr>";
+			html += "<h4>ExpressoLivre - ExpressoMail</h4><hr>";
 			html += '<table><tbody>';
 			if(sender)
@@ -2293,5 +2314,5 @@
 			html += show_attachs; //to show the names of the attachments
 			html += "</tbody></table><hr>";
-			window_print.document.write(html + body.innerHTML); 
+			window_print.document.write(html + body.innerHTML);
 			if(!is_ie){
 				var tab_tags = window_print.document.getElementsByTagName("IMG");
@@ -2361,9 +2382,9 @@
 
 function export_all_selected_msgs(){
-	var msgs_to_export = this.get_selected_messages(); 
-
 	if (openTab.type[currentTab] > 1){
-		msgs_to_export = currentTab.substr(0,(currentTab.length - 2));
-	}
+		source_msg(currentTab,current_folder);
+		return;
+	}
+	var msgs_to_export = this.get_selected_messages();
 
 	var handler_export_all_selected_msgs = function(data){
@@ -2372,21 +2393,6 @@
 			write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'));
 		}
-		else 
-		{ 
-			if (data.substr(data.length-3, 3) == "zip") { 
-				download_attachments(null, null, data, null, null,'mensagens.zip'); 
-			} else if (data.substr(data.length-3, 3) == "eml") { 
-				//extracts the file name from file path 
-				var string_start  = data.lastIndexOf("/") + 1; 
-				var string_length = data.length - string_start; 
-				var fname = data.substr(string_start, string_length); 
-				//extracts the session_id from file name 
-				var string_end  = data.lastIndexOf("_") - 5; 
-				fname = fname.substr(0, string_end).concat(".eml"); 
-				download_attachments(null, null, data, null, null, fname); 
-			} else { 
-				download_attachments(null, null, data, null, null, 'mensagens'); 
-			} 
-		} 
+		else
+			download_attachments(null, null, data, null,null,'mensagens.zip');
 	}
 
@@ -2536,5 +2542,5 @@
 	}
 	form_upload.innerHTML = '<form method="POST" name="form_import" enctype="multipart/form-data">'+get_lang('zip mails to import')+':<br>'+
-	'<input name="file_1" maxlength="255" size="40" id="file_1" type="file"><br>' +
+	'<input name="file_1" maxlength="255" size="50" id="file_1" type="file"><br>' +
 	'<input title="'+get_lang('Select a folder')+'"  value="' + get_lang('Select a folder') + '"' + 'type="button" onclick="javascript:select_import_folder()">&nbsp;' +
 	'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
@@ -2546,5 +2552,4 @@
 	function handler(data){
 		// Its necessary to encapsulate the data returned (IE bugfix)
-		clear_msg();
 		return_import_msgs(data,wfolders_tree);
 	}
@@ -2562,5 +2567,5 @@
 	folder.value = wfolders_tree._selected.id;
 	document.form_import.appendChild(folder);
-	write_msg(get_lang('You must wait while the messages will be imported...'), undefined, true);
+	write_msg(get_lang('You must wait while the messages will be imported...'));
 
 	cExecuteForm('$this.imap_functions.import_msgs', document.form_import, handler);
