From ed36776c405565fb6909328d0578aa099e38d398 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 1 Feb 2022 11:23:40 +0100 Subject: [PATCH] Add option to unset colors provided in HTML mails for preview into Preferences It's located in Edit->Preferences->Mail Preferences->HTML Messages->Unset colors provided in HTML mails in message preview. Related to https://gitlab.gnome.org/GNOME/evolution/issues/695 --- data/webkit/e-web-view.js | 11 ++++++---- src/mail/e-mail-display.c | 34 +++++++++++++++++++++++++----- src/mail/mail-config.ui | 18 +++++++++++++++- src/modules/mail/em-mailer-prefs.c | 6 ++++++ 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/data/webkit/e-web-view.js b/data/webkit/e-web-view.js index c01707b070..7f47fe4b26 100644 --- a/data/webkit/e-web-view.js +++ b/data/webkit/e-web-view.js @@ -1069,10 +1069,10 @@ Evo.unsetHTMLColors = function(doc) continue; if (rule.style.color) - rule.style.color = "inherit"; + rule.style.removeProperty("color"); if (rule.style.backgroundColor) - rule.style.backgroundColor = "inherit"; + rule.style.removeProperty("background-color"); } } @@ -1086,10 +1086,13 @@ Evo.unsetHTMLColors = function(doc) if (elem.tagName != "HTML" && elem.tagName != "IFRAME" && elem.tagName != "INPUT" && elem.tagName != "BUTTON" && elem.tagName != "IMG") { if (elem.style) { if (elem.style.color) - elem.style.color = "inherit"; + elem.style.removeProperty("color"); if (elem.style.backgroundColor) - elem.style.backgroundColor = "inherit"; + elem.style.removeProperty("background-color"); + + if (!elem.style.length) + elem.removeAttribute("style"); } elem.removeAttribute("color"); diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c index ba0ec8892a..fabe6f9c94 100644 --- a/src/mail/e-mail-display.c +++ b/src/mail/e-mail-display.c @@ -2108,12 +2108,13 @@ mail_display_drag_data_get (GtkWidget *widget, g_free (uri); } -static void -e_mail_display_test_change_and_update_fonts_cb (EMailDisplay *mail_display, - const gchar *key, - GSettings *settings) +static gboolean +e_mail_display_test_key_changed (EMailDisplay *mail_display, + const gchar *key, + GSettings *settings) { GVariant *new_value, *old_value; + gboolean changed = FALSE; new_value = g_settings_get_value (settings, key); old_value = g_hash_table_lookup (mail_display->priv->old_settings, key); @@ -2124,10 +2125,30 @@ e_mail_display_test_change_and_update_fonts_cb (EMailDisplay *mail_display, else g_hash_table_remove (mail_display->priv->old_settings, key); - e_web_view_update_fonts (E_WEB_VIEW (mail_display)); + changed = TRUE; } else if (new_value) { g_variant_unref (new_value); } + + return changed; +} + +static void +e_mail_display_test_change_and_update_fonts_cb (EMailDisplay *mail_display, + const gchar *key, + GSettings *settings) +{ + if (e_mail_display_test_key_changed (mail_display, key, settings)) + e_web_view_update_fonts (E_WEB_VIEW (mail_display)); +} + +static void +e_mail_display_test_change_and_reload_cb (EMailDisplay *mail_display, + const gchar *key, + GSettings *settings) +{ + if (e_mail_display_test_key_changed (mail_display, key, settings)) + e_mail_display_reload (mail_display); } static void @@ -2408,6 +2429,9 @@ e_mail_display_init (EMailDisplay *display) g_signal_connect_swapped ( display->priv->settings , "changed::use-custom-font", G_CALLBACK (e_mail_display_test_change_and_update_fonts_cb), display); + g_signal_connect_swapped ( + display->priv->settings , "changed::preview-unset-html-colors", + G_CALLBACK (e_mail_display_test_change_and_reload_cb), display); g_signal_connect ( display, "load-changed", diff --git a/src/mail/mail-config.ui b/src/mail/mail-config.ui index 7a92ef2d63..890837162a 100644 --- a/src/mail/mail-config.ui +++ b/src/mail/mail-config.ui @@ -2407,6 +2407,22 @@ 0 + + + Unset colors provided in HTML mails in message previe_w + True + True + False + True + 0.5 + True + + + False + False + 1 + + _Prompt on sending HTML mail to contacts that do not want them @@ -2420,7 +2436,7 @@ False False - 1 + 2 diff --git a/src/modules/mail/em-mailer-prefs.c b/src/modules/mail/em-mailer-prefs.c index e83fdf228c..fa5af4a2ea 100644 --- a/src/modules/mail/em-mailer-prefs.c +++ b/src/modules/mail/em-mailer-prefs.c @@ -1786,6 +1786,12 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs, widget, "active", G_SETTINGS_BIND_DEFAULT); + widget = e_builder_get_widget (prefs->priv->builder, "chkUnsetHTMLColors"); + g_settings_bind ( + settings, "preview-unset-html-colors", + widget, "active", + G_SETTINGS_BIND_DEFAULT); + widget = e_builder_get_widget (prefs->priv->builder, "chkPromptWantHTML"); g_settings_bind ( settings, "prompt-on-unwanted-html",