Index: branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4165)
+++ branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4202)
@@ -2132,5 +2132,5 @@
 		$mail->AddReplyTo($replytoaddress);
 		$mail->Subject = $subject;
-		$mail->IsHTML($params['type'] != 'textplain');
+		$mail->IsHTML( ( array_key_exists( 'type', $params ) && in_array( strtolower( $params[ 'type' ] ), array( 'html', 'plain' ) ) ) ? strtolower( $params[ 'type' ] ) != 'plain' : true );
 		$mail->Body = $body;
 
Index: branches/2.2/expressoMail1_2/js/abas.js
===================================================================
--- branches/2.2/expressoMail1_2/js/abas.js	(revision 4136)
+++ branches/2.2/expressoMail1_2/js/abas.js	(revision 4202)
@@ -56,5 +56,5 @@
 				try
 				{
-					if (Element('viewsource_rt_checkbox').checked)
+					if (Element('viewsource_rt_checkbox_' + ID).checked)
 					{  
 						connector.loadScript("rich_text_editor");
Index: branches/2.2/expressoMail1_2/js/main.js
===================================================================
--- branches/2.2/expressoMail1_2/js/main.js	(revision 4136)
+++ branches/2.2/expressoMail1_2/js/main.js	(revision 4202)
@@ -79,4 +79,8 @@
 
 	cExecute ("$this.functions.get_preferences", save_preferences);
+	cExecute ("phpgwapi.browser.isMobile", function( data )
+	{
+		mobile_device = ( ( data.constructor == Boolean ) ? data : ( data === 'true' ) );
+	} );
 	setTimeout('auto_refresh()', time_refresh);
 
@@ -1645,6 +1649,6 @@
 	}
 
-	if ( document.getElementById('viewsource_rt_checkbox').checked == true )
-		document.getElementById('viewsource_rt_checkbox').click();
+	if ( document.getElementById('viewsource_rt_checkbox_' + ID).checked == true )
+		document.getElementById('viewsource_rt_checkbox_' + ID).click();
 
 	var save_link = Element("save_message_options_"+ID);
@@ -1657,4 +1661,7 @@
 		send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug
 	};
+
+	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");
@@ -1662,7 +1669,5 @@
 	textArea.name = "body";
 	body = document.getElementById("body_"+ID);
-	textArea.value += '<body>\r\n';
-	textArea.value += body.contentWindow.document.body.innerHTML;
-	textArea.value += '\r\n</body>';
+	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';
@@ -1698,4 +1703,9 @@
 	form.appendChild(input_folder);
 	form.appendChild(msg_id);
+
+	var mail_type = form.appendChild( document.createElement( 'input' ) );
+	mail_type.name = 'type';
+	mail_type.type = 'hidden';
+	mail_type.value = ( mail_as_plain ) ? 'plain' : 'html';
 
 	var _subject = trim(Element("subject_"+ID).value);
@@ -1903,5 +1913,5 @@
 		withImage = false;
 
-	var rt_checkbox = Element('viewsource_rt_checkbox');
+	var rt_checkbox = Element('viewsource_rt_checkbox_' + ID);
 	if (rt_checkbox == null)
 		return false;
Index: branches/2.2/expressoMail1_2/js/globals.js
===================================================================
--- branches/2.2/expressoMail1_2/js/globals.js	(revision 3384)
+++ branches/2.2/expressoMail1_2/js/globals.js	(revision 4202)
@@ -45,3 +45,3 @@
 var divStatusBar = document.getElementById("divStatusBar");
 var denyFileExtensions = new Array('exe','com','reg','chm','cnf','hta','ins','jse','job','lnk','pif','src','scf','sct','shb','vbe','vbs','wsc','wsf','wsh','cer','its','mau','','mda','mar','mdz','prf','pst');
-
+var mobile_device = false;
Index: branches/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- branches/2.2/expressoMail1_2/js/draw_api.js	(revision 4136)
+++ branches/2.2/expressoMail1_2/js/draw_api.js	(revision 4202)
@@ -2270,4 +2270,26 @@
 
 	tr_menu_new_message.appendChild(td_menu_new_message);
+
+	if ( ! expresso_offline )
+	{
+		var text_plain = td_menu_new_message.appendChild(
+			document.createElement( 'span' )
+		).appendChild(
+			document.createTextNode( ' | ' )
+		).parentNode.appendChild(
+			document.createElement( 'input' )
+		).parentNode.appendChild(
+			document.createTextNode( get_lang('Send this mail as text plain') + '.')
+		).previousSibling;
+		text_plain.setAttribute( 'tabIndex', '-1' );
+		text_plain.id = 'textplain_rt_checkbox_' + ID ;
+		text_plain.type = "checkbox";
+		text_plain.onclick = function ()
+		{
+			RichTextEditor.plain( ( ! this.checked ) ? this.checked : mobile_device || ( this.checked = confirm( 'The text format will be lost.' ) ) );
+			document.getElementById( 'viewsource_rt_checkbox_' + ID ).parentNode.style.display = ( this.checked ) ? 'none' : '';
+		};
+	}
+
 	tbody_menu_new_message.appendChild(tr_menu_new_message);
 	table_menu_new_message.appendChild(tbody_menu_new_message);
@@ -2866,4 +2888,14 @@
 		draw_from_field(sel_from,tr1_1);
 	resizeWindow();
+
+	if ( ! expresso_offline )
+	{
+		if ( mobile_device )
+		{
+			text_plain.click( );
+			text_plain.parentNode.style.display = 'none';
+		}
+	}
+
 	return ID;
 }
Index: branches/2.2/expressoMail1_2/js/color_palette.js
===================================================================
--- branches/2.2/expressoMail1_2/js/color_palette.js	(revision 320)
+++ branches/2.2/expressoMail1_2/js/color_palette.js	(revision 4202)
@@ -24,6 +24,9 @@
 cColorPalette.prototype.repos = function (intElemScrollTop)
 {
-	var new_pos = findPosY(Element("forecolor")) - intElemScrollTop + 20;
-	this.div.style.top = new_pos;
+	if ( Element("forecolor") )
+	{
+		var new_pos = findPosY(Element("forecolor")) - intElemScrollTop + 20;
+		this.div.style.top = new_pos;
+	}
 }
 
Index: branches/2.2/expressoMail1_2/js/rich_text_editor.js
===================================================================
--- branches/2.2/expressoMail1_2/js/rich_text_editor.js	(revision 3865)
+++ branches/2.2/expressoMail1_2/js/rich_text_editor.js	(revision 4202)
@@ -25,4 +25,7 @@
 		parentDiv.appendChild(this.table);
 
+	var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + this.id );
+	this.table.style.visibility = ( mail_as_plain && mail_as_plain.checked ) ? 'hidden' : 'visible';
+
 	if(!Element(this.editor))
 	{
@@ -31,5 +34,5 @@
 	else
 	{
-		Element("viewsource_rt_checkbox").checked=false;
+		Element( 'viewsource_rt_checkbox_' + this.id ).checked=false;
 	}
 
@@ -50,5 +53,7 @@
 		config_events( iframe, 'onload', function( )
 		{
-			iframe.contentWindow.document.designMode = "on";
+			if ( iframe.contentWindow.document.body && iframe.contentWindow.document.body.contentEditable )
+				iframe.contentWindow.document.body.contentEditable = true;
+
 			if ( iframe.contentWindow.document.documentElement ){
 				iframe.contentWindow.document.documentElement.style.background = '#fff';
@@ -57,13 +62,19 @@
 		});
 
-		var checkbox = document.createElement("INPUT");
-		checkbox.id = 'viewsource_rt_checkbox';
-		checkbox.type = "checkbox";
-		checkbox.setAttribute("tabIndex","-1");
-		checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)};
-		var text = document.createTextNode(get_lang('View HTML source') + '.');
 		parentDiv.appendChild(iframe);
-		parentDiv.appendChild(checkbox);
-		parentDiv.appendChild(text);
+
+		var source = document.createElement( 'input' );
+		source.id = 'viewsource_rt_checkbox_' + this.id;
+		source.type = "checkbox";
+		source.setAttribute("tabIndex","-1");
+		source.onclick = function( )
+		{
+			RichTextEditor.viewsource(this.checked);
+		};
+		source = parentDiv.appendChild(
+			document.createElement( 'span' ).appendChild( source ).parentNode
+		).appendChild(
+			document.createTextNode( get_lang( 'View HTML source' ) + '.' )
+		).parentNode;
 }
 
@@ -138,4 +149,55 @@
 			document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString();
 			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
+		}
+	}
+}
+
+cRichTextEditor.prototype.plain = function(source) {
+	var html;
+	var editor = document.getElementById( this.editor );
+
+	if (source) {
+		if (is_ie){
+			connector.loadScript('html2xhtml');
+			html = frames[this.editor].document.body;
+			var xhtml = get_xhtml(html, 'en', 'iso-8859-1');
+			frames[this.editor].document.body.innerText = xhtml;
+			document.getElementById("table_richtext_toolbar").style.visibility="hidden";
+		}
+		else{
+			html = document.createTextNode( editor.contentWindow.document.body.innerHTML );
+			this.table.style.visibility="hidden";
+			editor.contentWindow.document.body.innerHTML = '';
+
+			var textarea = document.createElement( 'textarea' );
+			textarea.style.width = '99%';
+			textarea.style.height = '300px';
+			textarea.style.fontSize = '12pt';
+			textarea.innerHTML = html.nodeValue.replace( /<br\s*\/?>/mg, "\n" ).replace( /(<([^>]+)>)/ig, '' );
+
+			editor.style.width = '0px';
+			editor.style.height = '0px';
+			editor.style.visibility = 'hidden';
+
+			editor.parentNode.insertBefore( textarea, editor );
+			textarea.focus( );
+		}
+	} else {
+		if (is_ie){
+			var output = escape(frames[this.editor].document.body.innerText);
+			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
+			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
+			frames[this.editor].document.body.innerHTML = unescape(output);
+			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
+		}
+		else{
+			editor.contentWindow.document.body.innerHTML = editor.previousSibling.value.replace( /\n/g, '<br/>' );
+			editor.parentNode.removeChild( editor.previousSibling );
+
+			editor.style.width = '99%';
+			editor.style.height = '300px';
+			editor.style.visibility = 'visible';
+
+			this.loadEditor( this.id );
 		}
 	}
