[evolution/wip/webkit2] Bug 758089 - [prefer-plain] Show plain text if present, or HTML source



commit 35c89696389e88800ed9e075da2f4a8dd0724bdf
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 24 14:25:35 2015 +0100

    Bug 758089 - [prefer-plain] Show plain text if present, or HTML source

 ...me.evolution.plugin.prefer-plain.gschema.xml.in |    2 +-
 modules/prefer-plain/e-mail-parser-prefer-plain.c  |   24 ++++++++++++++++++++
 modules/prefer-plain/plugin/config-ui.c            |   15 +++++------
 3 files changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/data/org.gnome.evolution.plugin.prefer-plain.gschema.xml.in 
b/data/org.gnome.evolution.plugin.prefer-plain.gschema.xml.in
index 2cb7477..b5c2b5c 100644
--- a/data/org.gnome.evolution.plugin.prefer-plain.gschema.xml.in
+++ b/data/org.gnome.evolution.plugin.prefer-plain.gschema.xml.in
@@ -3,7 +3,7 @@
     <key name="mode" type="s">
       <default>'normal'</default>
       <_summary>Mode to use when displaying mails</_summary>
-      <_description>The mode to use for displaying mails. "normal" makes Evolution choose the best part to 
show, "prefer_plain" makes it use the text part, if present, and "only_plain" forces Evolution to only show 
plain text</_description>
+      <_description>The mode to use for displaying mails. "normal" makes Evolution choose the best part to 
show, "prefer_plain" makes it use the text part, if present, "prefer_source" makes it use the text part, if 
present, otherwise shows HTML source, and "only_plain" forces Evolution to only show plain text</_description>
     </key>
     <key name="show-suppressed" type="b">
       <default>true</default>
diff --git a/modules/prefer-plain/e-mail-parser-prefer-plain.c 
b/modules/prefer-plain/e-mail-parser-prefer-plain.c
index 682d49f..7908999 100644
--- a/modules/prefer-plain/e-mail-parser-prefer-plain.c
+++ b/modules/prefer-plain/e-mail-parser-prefer-plain.c
@@ -55,6 +55,7 @@ GType e_mail_parser_prefer_plain_get_type (void);
 enum {
        PREFER_HTML,
        PREFER_PLAIN,
+       PREFER_SOURCE,
        ONLY_PLAIN
 };
 
@@ -83,6 +84,11 @@ static struct {
          N_("Show plain text part, if present, otherwise "
             "let Evolution choose the best part to show.") },
 
+       { "prefer_source",
+         N_("Show plain text if present, or HTML source"),
+         N_("Show plain text part, if present, otherwise "
+            "the HTML part source.") },
+
        { "only_plain",
          N_("Only ever show plain text"),
          N_("Always show plain text part and make attachments "
@@ -204,6 +210,24 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
                if (strstr (part_id->str, ".alternative-prefer-plain.") != NULL)
                        return FALSE;
 
+               if (emp_pp->mode == PREFER_SOURCE && !e_mail_part_is_attachment (part)) {
+                       EMailPart *mail_part;
+
+                       partidlen = part_id->len;
+
+                       g_string_truncate (part_id, partidlen);
+                       g_string_append_printf (part_id, ".alternative-prefer-plain.%d", -1);
+
+                       mail_part = e_mail_part_new (part, part_id->str);
+                       e_mail_part_set_mime_type (mail_part, "application/vnd.evolution.plaintext");
+
+                       g_string_truncate (part_id, partidlen);
+
+                       g_queue_push_tail (out_mail_parts, mail_part);
+
+                       return TRUE;
+               }
+
                /* Not enforcing text/plain, so use real parser. */
                if (emp_pp->mode != ONLY_PLAIN)
                        return FALSE;
diff --git a/modules/prefer-plain/plugin/config-ui.c b/modules/prefer-plain/plugin/config-ui.c
index b8424b9..de30b42 100644
--- a/modules/prefer-plain/plugin/config-ui.c
+++ b/modules/prefer-plain/plugin/config-ui.c
@@ -24,12 +24,6 @@
 
 GtkWidget *prefer_plain_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data);
 
-enum {
-       EPP_NORMAL,
-       EPP_PREFER,
-       EPP_TEXT
-};
-
 static GSettings *epp_settings = NULL;
 static gint epp_mode = -1;
 static gboolean epp_show_suppressed = TRUE;
@@ -48,6 +42,11 @@ static struct {
          N_("Show plain text part, if present, otherwise "
             "let Evolution choose the best part to show.") },
 
+       { "prefer_source",
+         N_("Show plain text if present, or HTML source"),
+         N_("Show plain text part, if present, otherwise "
+            "the HTML part source.") },
+
        { "only_plain",
          N_("Only ever show plain text"),
          N_("Always show plain text part and make attachments "
@@ -58,7 +57,7 @@ static void
 update_info_label (GtkWidget *info_label,
                    guint mode)
 {
-       gchar *str = g_strconcat ("<i>", _(epp_options[mode > 2 ? 0 : mode].description), "</i>", NULL);
+       gchar *str = g_strconcat ("<i>", _(epp_options[mode >= G_N_ELEMENTS (epp_options) ? 0 : 
mode].description), "</i>", NULL);
 
        gtk_label_set_markup (GTK_LABEL (info_label), str);
 
@@ -70,7 +69,7 @@ epp_mode_changed (GtkComboBox *dropdown,
                   GtkWidget *info_label)
 {
        epp_mode = gtk_combo_box_get_active (dropdown);
-       if (epp_mode > 2)
+       if (epp_mode >= G_N_ELEMENTS (epp_options))
                epp_mode = 0;
 
        g_settings_set_string (epp_settings, "mode", epp_options[epp_mode].key);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]