From 28791c1cf64f52248c79ac532266b2631eb7fcec Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 20 Oct 2004 08:17:14 +0000 Subject: Imported prefer-plain plugin. 2004-10-20 Not Zed * Imported prefer-plain plugin. svn path=/trunk/; revision=27645 --- plugins/prefer-plain/ChangeLog | 4 + plugins/prefer-plain/Makefile.am | 11 ++ .../prefer-plain/org-gnome-prefer-plain.eplug.in | 33 ++++ plugins/prefer-plain/prefer-plain.c | 191 +++++++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 plugins/prefer-plain/ChangeLog create mode 100644 plugins/prefer-plain/Makefile.am create mode 100644 plugins/prefer-plain/org-gnome-prefer-plain.eplug.in create mode 100644 plugins/prefer-plain/prefer-plain.c (limited to 'plugins/prefer-plain') diff --git a/plugins/prefer-plain/ChangeLog b/plugins/prefer-plain/ChangeLog new file mode 100644 index 0000000000..dfacee6e46 --- /dev/null +++ b/plugins/prefer-plain/ChangeLog @@ -0,0 +1,4 @@ +2004-10-20 Not Zed + + * Imported prefer-plain plugin. + diff --git a/plugins/prefer-plain/Makefile.am b/plugins/prefer-plain/Makefile.am new file mode 100644 index 0000000000..c71bcf65fb --- /dev/null +++ b/plugins/prefer-plain/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = \ + -I$(top_srcdir) \ + $(EVOLUTION_MAIL_CFLAGS) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-prefer-plain.eplug +plugin_LTLIBRARIES = liborg-gnome-prefer-plain.la + +liborg_gnome_prefer_plain_la_SOURCES = prefer-plain.c +liborg_gnome_prefer_plain_la_LDFLAGS = -module -avoid-version diff --git a/plugins/prefer-plain/org-gnome-prefer-plain.eplug.in b/plugins/prefer-plain/org-gnome-prefer-plain.eplug.in new file mode 100644 index 0000000000..06218f7972 --- /dev/null +++ b/plugins/prefer-plain/org-gnome-prefer-plain.eplug.in @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/prefer-plain/prefer-plain.c b/plugins/prefer-plain/prefer-plain.c new file mode 100644 index 0000000000..2a105c656b --- /dev/null +++ b/plugins/prefer-plain/prefer-plain.c @@ -0,0 +1,191 @@ + +/* Copyright (C) 2004 Michael Zucchi */ + +/* This file is licensed under the GNU GPL v2 or later */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "camel/camel-multipart.h" +#include "camel/camel-mime-part.h" +#include "mail/em-format-hook.h" +#include "mail/em-format.h" + +#include +#include +#include +#include +#include +#include +#include +#include "mail/em-config.h" + +void org_gnome_prefer_plain_multipart_alternative(void *ep, EMFormatHookTarget *t); +void org_gnome_prefer_plain_text_html(void *ep, EMFormatHookTarget *t); +GtkWidget *org_gnome_prefer_plain_config_mode(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data); + +enum { + EPP_NORMAL, + EPP_PREFER, + EPP_TEXT +}; + +static GConfClient *epp_gconf; +static int epp_mode; + +void +org_gnome_prefer_plain_text_html(void *ep, EMFormatHookTarget *t) +{ + /* In text-only mode, all html output is suppressed */ + if (epp_mode != EPP_TEXT) + t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old); + else + em_format_part_as(t->format, t->stream, t->part, NULL); +} + +void +org_gnome_prefer_plain_multipart_alternative(void *ep, EMFormatHookTarget *t) +{ + CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)t->part); + CamelMimePart *part, *display_part = NULL; + int i, nparts, partidlen, displayid = 0; + + if (epp_mode == EPP_NORMAL) { + t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old); + return; + } else if (!CAMEL_IS_MULTIPART(mp)) { + em_format_format_source(t->format, t->stream, t->part); + return; + } + + nparts = camel_multipart_get_number(mp); + for (i=0; iformat->part_id->len; + + /* if we found a text part, show it */ + if (display_part) { + g_string_append_printf(t->format->part_id, ".alternative.%d", displayid); + em_format_part_as(t->format, t->stream, display_part, "text/plain"); + g_string_truncate(t->format->part_id, partidlen); + } + + /* all other parts are attachments */ + for (i=0;iformat->part_id, ".alternative.%d", i); + + em_format_part_as(t->format, t->stream, t->part, NULL); + + g_string_truncate(t->format->part_id, partidlen); + } + } + + g_string_truncate(t->format->part_id, partidlen); +} + +static struct { + const char *label; + const char *key; +} epp_options[] = { + { N_("Show HTML if present"), "normal" }, + { N_("Prefer PLAIN"), "prefer_plain" }, + { N_("Only ever show PLAIN"), "only_plain" }, +}; + +static void +epp_mode_changed(GtkComboBox *dropdown, void *dummy) +{ + epp_mode = gtk_combo_box_get_active(dropdown); + if (epp_mode > 2) + epp_mode = 0; + + gconf_client_set_string(epp_gconf, "/apps/evolution/eplugin/prefer_plain/mode", epp_options[epp_mode].key, NULL); +} + +GtkWidget * +org_gnome_prefer_plain_config_mode(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data) +{ + /*EMConfigTargetPrefs *ep = (EMConfigTargetPrefs *)data->target;*/ + GtkComboBox *dropdown; + GtkCellRenderer *cell; + GtkListStore *store; + GtkWidget *w; + int i; + GtkTreeIter iter; + + if (data->old) + return data->old; + + dropdown = (GtkComboBox *)gtk_combo_box_new(); + cell = gtk_cell_renderer_text_new(); + store = gtk_list_store_new(1, G_TYPE_STRING); + for (i=0;iparent)->nrows; + gtk_table_attach((GtkTable *)data->parent, w, 0, 1, i, i+1, 0, 0, 0, 0); + gtk_table_attach((GtkTable *)data->parent, (GtkWidget *)dropdown, 1, 2, i, i+1, GTK_FILL|GTK_EXPAND, 0, 0, 0); + + /* since this isnt dynamic, we don't need to track each item */ + + return (GtkWidget *)dropdown; +} + +int org_gnome_prefer_plain_enable(EPluginLib *ep, int enable); + +int +org_gnome_prefer_plain_enable(EPluginLib *ep, int enable) +{ + char *key; + int i; + + if (enable) { + epp_gconf = gconf_client_get_default(); + key = gconf_client_get_string(epp_gconf, "/apps/evolution/eplugin/prefer_plain/mode", NULL); + if (key) { + for (i=0;i