From: Sergio Villar SenĂ­n Date: Tue, 19 Jan 2010 12:03:53 +0000 (+0100) Subject: Show the signature in SecondaryTextColor for HTML emails X-Git-Tag: 3.2.11~10 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=036e2e88da8f0d8129684d146295db8829e074e1 Show the signature in SecondaryTextColor for HTML emails Fixes NB#147995 --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 7b60998..820eee3 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -207,23 +208,26 @@ modest_text_utils_cite (const gchar *text, const gchar *from, time_t sent_date) { - gchar *retval; - gchar *tmp_sig; - + gchar *retval, *tmp; + g_return_val_if_fail (text, NULL); g_return_val_if_fail (content_type, NULL); - - if (!signature) { - tmp_sig = g_strdup (text); - } else { - tmp_sig = g_strconcat (text, "\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER, "\n", signature, NULL); - } if (strcmp (content_type, "text/html") == 0) { - retval = modest_text_utils_convert_to_html_body (tmp_sig, -1, TRUE); - g_free (tmp_sig); + tmp = modest_text_utils_convert_to_html_body (text, -1, TRUE); + if (signature) { + gchar *colored_signature = modest_text_utils_create_colored_signature (signature); + retval = g_strconcat (tmp, colored_signature, NULL); + g_free (colored_signature); + g_free (tmp); + } else { + retval = tmp; + } } else { - retval = tmp_sig; + if (signature) + retval = g_strconcat (text, "\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER, "\n", signature, NULL); + else + retval = g_strdup (text); } return retval; @@ -1140,18 +1144,19 @@ modest_text_utils_quote_html (const gchar *text, { GString *result_string; - result_string = + result_string = g_string_new ( \ "\n" \ "\n" \ - "\n
\n"); + "\n"); if (text || cite || signature) { GString *quoted_text; g_string_append (result_string, "
\n");
 		if (signature) {
-			quote_html_add_to_gstring (result_string, MODEST_TEXT_UTILS_SIGNATURE_MARKER);
-			quote_html_add_to_gstring (result_string, signature);
+			gchar *colored_signature = modest_text_utils_create_colored_signature (signature);
+			g_string_append_printf (result_string, "%s
", colored_signature); + g_free (colored_signature); } quote_html_add_to_gstring (result_string, cite); quoted_text = g_string_new (""); @@ -2297,3 +2302,26 @@ modest_text_utils_no_recipient (GtkTextBuffer *buffer) return retval; } + +gchar * +modest_text_utils_create_colored_signature (const gchar *signature) +{ + gchar *gray_color_markup = NULL, *retval; + GdkColor color; + GtkWidget *widget; + + /* Get color from widgets */ + widget = (GtkWidget *) modest_window_mgr_get_current_top (modest_runtime_get_window_mgr ()); + if (widget && gtk_style_lookup_color (gtk_widget_get_style (widget), "SecondaryTextColor", &color)) + gray_color_markup = modest_text_utils_get_color_string (&color); + + retval = g_strdup_printf ("
\n%s
\n%s
\n
", + (gray_color_markup) ? gray_color_markup : "#babababababa", + MODEST_TEXT_UTILS_SIGNATURE_MARKER, + signature); + + if (gray_color_markup) + g_free (gray_color_markup); + + return retval; +} diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 50f4ee4..5568a1e 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -569,4 +569,6 @@ gchar * modest_text_utils_quote_names (const gchar *recipients); gboolean modest_text_utils_no_recipient (GtkTextBuffer *buffer); +gchar * modest_text_utils_create_colored_signature (const gchar *signature); + #endif /* __MODEST_TEXT_UTILS_H__ */ diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 724f487..523d260 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -827,8 +827,7 @@ modest_ui_actions_compose_msg(ModestWindow *win, TnyMsg *msg = NULL; TnyAccount *account = NULL; TnyFolder *folder = NULL; - gchar *from_str = NULL, *signature = NULL, *body = NULL; - gchar *recipient = NULL; + gchar *from_str = NULL, *signature = NULL, *body = NULL, *recipient = NULL, *tmp = NULL; gboolean use_signature = FALSE; ModestWindow *msg_win = NULL; ModestAccountMgr *mgr = modest_runtime_get_account_mgr(); @@ -897,34 +896,17 @@ modest_ui_actions_compose_msg(ModestWindow *win, goto cleanup; } + recipient = modest_text_utils_get_email_address (from_str); - signature = modest_account_mgr_get_signature_from_recipient (mgr, recipient, &use_signature); + tmp = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr (), + recipient, + &use_signature); + signature = modest_text_utils_create_colored_signature (tmp); + g_free (tmp); g_free (recipient); - if (body_str != NULL) { - body = use_signature ? g_strconcat(body_str, "\n", - MODEST_TEXT_UTILS_SIGNATURE_MARKER, - "\n", signature, NULL) : g_strdup(body_str); - } else { - - gchar *gray_color_markup = NULL, *color_begin = NULL, *color_end = NULL; - GdkColor color; - if (win && gtk_style_lookup_color (gtk_widget_get_style ((GtkWidget *) win), - "SecondaryTextColor", &color)) - gray_color_markup = modest_text_utils_get_color_string (&color); - if (!gray_color_markup) - gray_color_markup = g_strdup ("#babababababa"); - - color_begin = g_strdup_printf ("", gray_color_markup); - color_end = ""; - - body = use_signature ? g_strconcat("
\n", color_begin, - MODEST_TEXT_UTILS_SIGNATURE_MARKER, "
\n", - signature, color_end, NULL) : g_strdup(""); - - g_free (gray_color_markup); - g_free (color_begin); - } + body = use_signature ? g_strconcat ((body_str) ? body_str : "", signature, NULL) : + g_strdup(body_str); msg = modest_tny_msg_new_html_plain (to_str, from_str, cc_str, bcc_str, subject_str, NULL, NULL, body, NULL, NULL, NULL, NULL, NULL); @@ -1792,9 +1774,8 @@ reply_forward_cb (ModestMailOperation *mail_op, gchar *from = NULL; TnyAccount *account = NULL; ModestWindowMgr *mgr = NULL; - gchar *signature = NULL; + gchar *signature = NULL, *recipient = NULL; gboolean use_signature; - gchar *recipient; /* If there was any error. The mail operation could be NULL, this means that we already have the message downloaded and @@ -1805,9 +1786,10 @@ reply_forward_cb (ModestMailOperation *mail_op, from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), rf_helper->account_name, rf_helper->mailbox); + recipient = modest_text_utils_get_email_address (from); - signature = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr(), - recipient, + signature = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr (), + recipient, &use_signature); g_free (recipient);