Index: composer/ChangeLog
===================================================================
--- composer/ChangeLog	(revision 36769)
+++ composer/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2008-11-10  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #553535
+
+	* e-msg-composer.c: (is_top_signature), (get_signature_html),
+	(set_editor_text), (e_msg_composer_show_sig_file): Do not eat
+	lines of text when changing signature at top of the message.
+	Add one extra empty line between the signature and the body
+	of the mail when placing signature to the bottom.
+
 2008-11-05  Matthew Barnes  <mbarnes@redhat.com>
 
 	** Fixes part of bug #559371
Index: composer/e-msg-composer.c
===================================================================
--- composer/e-msg-composer.c	(revision 36769)
+++ composer/e-msg-composer.c	(working copy)
@@ -1267,7 +1267,25 @@ decode_signature_name (const gchar *name
 	return dname;
 }
 
+static gboolean
+is_top_signature (void)
+{
+	GConfClient *gconf;
+	gboolean res = FALSE;
+
+	gconf = gconf_client_get_default ();
+
+	res = gconf_client_get_bool (gconf, COMPOSER_GCONF_TOP_SIGNATURE_KEY, NULL);
+
+	g_object_unref (gconf);
+
+	return res;
+}
+
 #define CONVERT_SPACES CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES
+#define NO_SIGNATURE_TEXT	\
+	"<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->" \
+	"<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature_name\" value=\"uid:Noname\">--><BR>"
 
 static gchar *
 get_signature_html (EMsgComposer *composer)
@@ -1333,14 +1351,15 @@ get_signature_html (EMsgComposer *compos
 		 */
 		html = g_strdup_printf ("<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->"
 					"<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature_name\" value=\"uid:%s\">-->"
-					"<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD>"
+					"<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD><BR>"
 					"%s%s%s%s"
-					"</TD></TR></TABLE>",
+					"%s</TD></TR></TABLE>",
 				        encoded_uid ? encoded_uid : "",
 					format_html ? "" : "<PRE>\n",
 					format_html || (!strncmp ("-- \n", text, 4) || strstr (text, "\n-- \n")) ? "" : "-- \n",
 					text,
-					format_html ? "" : "</PRE>\n");
+					format_html ? "" : "</PRE>\n",
+					is_top_signature () ? "<BR>" : "");
 		g_free (text);
 		g_free (encoded_uid);
 		text = html;
@@ -1354,15 +1373,11 @@ set_editor_text (EMsgComposer *composer,
                  const gchar *text,
                  gboolean set_signature)
 {
-	gboolean reply_signature_on_top;
-	gchar *body = NULL, *html = NULL;
-	GConfClient *gconf;
+	gchar *body = NULL;
 
 	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 	g_return_if_fail (text != NULL);
 
-	gconf = gconf_client_get_default ();
-
 	/*
 
 	   Keeping Signatures in the beginning of composer
@@ -1377,38 +1392,17 @@ set_editor_text (EMsgComposer *composer,
 
 	 */
 
-	reply_signature_on_top = gconf_client_get_bool (gconf, COMPOSER_GCONF_TOP_SIGNATURE_KEY, NULL);
-
-	g_object_unref (gconf);
-
-	if (set_signature && reply_signature_on_top) {
-		gchar *tmp = NULL;
-		tmp = get_signature_html (composer);
-		if (tmp) {
-			/* Minimizing the damage. Make it just a part of the body instead of a signature */
-			html = strstr (tmp, "-- \n");
-			if (html) {
-				/* That two consecutive - symbols followed by a space */
-				*(html+1) = ' ';
-				body = g_strdup_printf ("</br>%s</br>%s", tmp, text);
-			} else {
-				/* HTML Signature. Make it as part of body */
-				body = g_strdup_printf ("</br>%s</br>%s", tmp, text);
-			}
-			g_free (tmp);
-		} else {
-			/* No signature set */
-			body = g_strdup_printf ("<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->"
-					"<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature_name\" value=\"uid:Noname\">-->"
-					"<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD> </TD></TR></TABLE>%s", text);
-		}
+	if (is_top_signature ()) {
+		/* put marker to the top */
+		body = g_strdup_printf ("<BR>" NO_SIGNATURE_TEXT "%s", text);
 	} else {
-		body = g_strdup (text);
+		/* no marker => to the bottom */
+		body = g_strdup_printf ("%s<BR>", text);
 	}
 
 	gtkhtml_editor_set_text_html (GTKHTML_EDITOR (composer), body, -1);
 
-	if (set_signature && !reply_signature_on_top)
+	if (set_signature)
 		e_msg_composer_show_sig_file (composer);
 }
 
@@ -4475,6 +4469,7 @@ e_msg_composer_show_sig_file (EMsgCompos
 	GtkhtmlEditor *editor;
 	GtkHTML *html;
 	gchar *html_text;
+	gboolean top_signature;
 
 	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 
@@ -4501,6 +4496,8 @@ e_msg_composer_show_sig_file (EMsgCompos
 	}
 	gtkhtml_editor_run_command (editor, "unblock-selection");
 
+	top_signature = is_top_signature ();
+
 	html_text = get_signature_html (composer);
 	if (html_text) {
 		gtkhtml_editor_run_command (editor, "insert-paragraph");
@@ -4508,11 +4505,16 @@ e_msg_composer_show_sig_file (EMsgCompos
 			gtkhtml_editor_run_command (editor, "insert-paragraph");
 		else
 			gtkhtml_editor_run_command (editor, "cursor-forward");
+
 		gtkhtml_editor_set_paragraph_data (editor, "orig", "0");
 		gtkhtml_editor_run_command (editor, "indent-zero");
 		gtkhtml_editor_run_command (editor, "style-normal");
 		gtkhtml_editor_insert_html (editor, html_text);
 		g_free (html_text);
+	} else if (top_signature) {
+		/* insert paragraph after the signature ClueFlow things */
+		gtkhtml_editor_run_command (editor, "cursor-forward");
+		gtkhtml_editor_run_command (editor, "insert-paragraph");
 	}
 
 	gtkhtml_editor_undo_end (editor);
