diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2004-11-04 13:47:02 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-11-04 13:47:02 +0800 |
commit | ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1 (patch) | |
tree | 75ea8457e748b5b7fc18958d7ac2a2dc79e5583c | |
parent | 0b736de5187a40f7e2c1414387cc8251e8d5ac9a (diff) | |
download | gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar.gz gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar.bz2 gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar.lz gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar.xz gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.tar.zst gsoc2013-evolution-ee52b57b90ca5ed5bc6468c42d1903427fe0f8f1.zip |
Added mailing list actions plugin from Meilof Veeningen <meilof@wanadoo.nl>
svn path=/trunk/; revision=27835
7 files changed, 367 insertions, 0 deletions
diff --git a/plugins/mailing-list-actions/ChangeLog b/plugins/mailing-list-actions/ChangeLog new file mode 100644 index 0000000000..5cb79d495a --- /dev/null +++ b/plugins/mailing-list-actions/ChangeLog @@ -0,0 +1,2 @@ + Added mailing list actions plugin from Meilof Veeningen <meilof@wanadoo.nl> + diff --git a/plugins/mailing-list-actions/Makefile.am b/plugins/mailing-list-actions/Makefile.am new file mode 100644 index 0000000000..47b5a75cf5 --- /dev/null +++ b/plugins/mailing-list-actions/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir) \ + $(EVOLUTION_MAIL_CFLAGS) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-mailing-list-actions.eplug org-gnome-mailing-list-actions.xml +plugin_LTLIBRARIES = liborg-gnome-mailing-list-actions.la + +liborg_gnome_mailing_list_actions_la_SOURCES = mailing-list-actions.c +liborg_gnome_mailing_list_actions_la_LDFLAGS = -module -avoid-version + +error_DATA = org-gnome-mailing-list-actions-errors.xml +error_i18n = $(error_DATA:.xml=.xml.h) +errordir = $(privdatadir)/errors +%.xml.h: %.xml + $(top_builddir)/e-util/e-error-tool $^ + +BUILT_SOURCES = $(error_i18n) +EXTRA_DIST = $(error_DATA) $(error_i18n) diff --git a/plugins/mailing-list-actions/mailing-list-actions.c b/plugins/mailing-list-actions/mailing-list-actions.c new file mode 100644 index 0000000000..7d32c2ce87 --- /dev/null +++ b/plugins/mailing-list-actions/mailing-list-actions.c @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2004 Meilof Veeningen <meilof@wanadoo.nl> + * + * This file is licensed under the GNU GPL v2 or later + */ + +#include <glib/gi18n-lib.h> +#include <stdio.h> +#include <string.h> +#include <gconf/gconf-client.h> +#include <gtk/gtkcombobox.h> +#include <gtk/gtkliststore.h> +#include <gtk/gtkcellrenderertext.h> +#include <gtk/gtkcelllayout.h> +#include <gtk/gtktable.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkdialog.h> +#include <libgnome/gnome-url.h> + +#include "camel/camel-multipart.h" +#include "camel/camel-mime-part.h" +#include "camel/camel-exception.h" +#include "camel/camel-folder.h" +#include "composer/e-msg-composer.h" +#include "mail/em-composer-utils.h" +#include "mail/em-format-hook.h" +#include "mail/em-format.h" +#include "mail/em-menu.h" +#include "mail/em-config.h" +#include "mail/mail-ops.h" +#include "mail/mail-mt.h" +#include "mail/mail-config.h" +#include "widgets/misc/e-error.h" + +typedef enum { + EMLA_ACTION_HELP, + EMLA_ACTION_UNSUBSCRIBE, + EMLA_ACTION_SUBSCRIBE, + EMLA_ACTION_POST, + EMLA_ACTION_OWNER, + EMLA_ACTION_ARCHIVE +} EmlaAction; + +typedef struct { + EmlaAction action; /* action enumeration */ + gboolean interactive; /* whether the user needs to edit a mailto: message (e.g. for post action) */ + const char* header; /* header representing the action */ +} EmlaActionHeader; + +const EmlaActionHeader emla_action_headers[] = { + { EMLA_ACTION_HELP, FALSE, "List-Help" }, + { EMLA_ACTION_UNSUBSCRIBE, TRUE, "List-Unsubscribe" }, + { EMLA_ACTION_SUBSCRIBE, FALSE, "List-Subscribe" }, + { EMLA_ACTION_POST, TRUE, "List-Post" }, + { EMLA_ACTION_OWNER, TRUE, "List-Owner" }, + { EMLA_ACTION_ARCHIVE, FALSE, "List-Archive" }, +}; + +const int emla_n_action_headers = sizeof(emla_action_headers) / sizeof(EmlaActionHeader); + +void emla_list_action (EPlugin *item, EMMenuTargetSelect* sel, EmlaAction action); +void emla_list_help (EPlugin *item, EMMenuTargetSelect* sel); +void emla_list_unsubscribe (EPlugin *item, EMMenuTargetSelect* sel); +void emla_list_subscribe (EPlugin *item, EMMenuTargetSelect* sel); +void emla_list_post (EPlugin *item, EMMenuTargetSelect* sel); +void emla_list_owner (EPlugin *item, EMMenuTargetSelect* sel); +void emla_list_archive (EPlugin *item, EMMenuTargetSelect* sel); + +void emla_list_action_do (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data); + +typedef struct { + EmlaAction action; + char* uri; +} emla_action_data; + +void emla_list_action (EPlugin *item, EMMenuTargetSelect* sel, EmlaAction action) +{ + emla_action_data *data; + + g_return_if_fail (sel->uids->len == 1); + + data = (emla_action_data *) malloc (sizeof (emla_action_data)); + data->action = action; + data->uri = strdup (sel->uri); + + mail_get_message (sel->folder, (const char*) g_ptr_array_index (sel->uids, 0), + emla_list_action_do, data, mail_thread_new); +} + +void emla_list_action_do (CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *data) +{ + emla_action_data *action_data = (emla_action_data *) data; + EmlaAction action = action_data->action; + const char* header = NULL, *headerpos; + char *end, *url = NULL; + int t; + GError *err; + EMsgComposer *composer; + int send_message_response; + EAccount *account; + + for (t = 0; t < emla_n_action_headers; t++) { + if (emla_action_headers[t].action == action && + (header = camel_medium_get_header (CAMEL_MEDIUM (msg), emla_action_headers[t].header)) != NULL) + break; + } + + if (!header) { + /* there was no header matching the action */ + e_error_run (NULL, "org.gnome.mailing-list-actions:no-header", NULL); + goto exit; + } + + headerpos = header; + + if (action == EMLA_ACTION_POST) { + while (*headerpos == ' ') headerpos++; + if (g_ascii_strcasecmp (headerpos, "NO") == 0) { + e_error_run (NULL, "org.gnome.mailing-list-actions:posting-not-allowed", NULL); + goto exit; + } + } + + /* parse the action value */ + while (*headerpos) { + /* skip whitespace */ + while (*headerpos == ' ') headerpos++; + if (*headerpos != '<' || (end = strchr (headerpos++, '>')) == NULL) { + e_error_run (NULL, "org.gnome.mailing-list-actions:malformed-header", emla_action_headers[t].header, header, NULL); + goto exit; + } + + /* get URL portion */ + url = (char *) malloc (end - headerpos); + strncpy (url, headerpos, end - headerpos); + url[end-headerpos] = '\0'; + + if (strncmp (url, "mailto:", 6) == 0) { + if (emla_action_headers[t].interactive) + send_message_response = GTK_RESPONSE_NO; + else + send_message_response = e_error_run (NULL, "org.gnome.mailing-list-actions:ask-send-message", url, NULL); + + if (send_message_response == GTK_RESPONSE_YES) { + /* directly send message */ + composer = e_msg_composer_new_from_url (url); + if ((account = mail_config_get_account_by_source_url (action_data->uri))) + e_msg_composer_hdrs_set_from_account ((EMsgComposerHdrs *) composer->hdrs, account->name); + em_utils_composer_send_cb (composer, NULL); + } else if (send_message_response == GTK_RESPONSE_NO) { + /* show composer */ + em_utils_compose_new_message_with_mailto (url, action_data->uri); + } + + goto exit; + } else { + err = NULL; + gnome_url_show (url, &err); + if (!err) + goto exit; + g_error_free (err); + } + free (url); + url = NULL; + headerpos = end++; + + /* ignore everything 'till next comma */ + headerpos = strchr (headerpos, ','); + if (!headerpos) + break; + headerpos++; + } + + /* if we got here, there's no valid action */ + e_error_run (NULL, "org.gnome.mailing-list-actions:no-action", header, NULL); + +exit: + free (action_data->uri); + free (action_data); + if (url) + free(url); +} + +void emla_list_help (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_HELP); +} + +void emla_list_unsubscribe (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_UNSUBSCRIBE); +} + +void emla_list_subscribe (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_SUBSCRIBE); +} + +void emla_list_post (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_POST); +} + +void emla_list_owner (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_OWNER); +} + +void emla_list_archive (EPlugin *item, EMMenuTargetSelect* sel) +{ + emla_list_action (item, sel, EMLA_ACTION_ARCHIVE); +} diff --git a/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml b/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml new file mode 100644 index 0000000000..69b20fa834 --- /dev/null +++ b/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<error-list domain="org.gnome.mailing-list-actions"> + + <error id="no-header" type="error"> + <primary>Action not available</primary> + <secondary>This message does not contain the header information required for this action.</secondary> + </error> + + <error id="posting-not-allowed" type="error"> + <primary>Posting not allowed</primary> + <secondary>Posting to this mailing list is not allowed. Possibly, this is a read-only mailing list. Contact the list owner for details.</secondary> + </error> + + <error id="ask-send-message" type="question" default="GTK_RESPONSE_YES"> + <primary>Send e-mail message to mailing list?</primary> + <secondary>An e-mail message will be sent to the URL "{0}". You can either send the message automatically, or see and change it first. + +You should receive an answer from the mailing list shortly after the message has been sent.</secondary> + <button label="_Send message" response="GTK_RESPONSE_YES"/> + <button label="_Edit message" response="GTK_RESPONSE_NO"/> + <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/> + </error> + + <error id="malformed-header" type="error"> + <primary>Malformed header</primary> + <secondary>The {0} header of this message is malformed and could not be processed. + +Header: {1}</secondary> + </error> + + <error id="no-action" type="error"> + <primary>No e-mail action</primary> + <secondary>The action could not be performed. This means the header for this action did not contain any action we could handle. + +Header: {0}</secondary> + </error> + +</error-list> diff --git a/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml.h b/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml.h new file mode 100644 index 0000000000..a5bbbbcc20 --- /dev/null +++ b/plugins/mailing-list-actions/org-gnome-mailing-list-actions-errors.xml.h @@ -0,0 +1,28 @@ +/* org.gnome.mailing-list-actions:no-header primary */ +char *s = N_("Action not available"); +/* org.gnome.mailing-list-actions:no-header secondary */ +char *s = N_("This message does not contain the header information required for this action."); +/* org.gnome.mailing-list-actions:posting-not-allowed primary */ +char *s = N_("Posting not allowed"); +/* org.gnome.mailing-list-actions:posting-not-allowed secondary */ +char *s = N_("Posting to this mailing list is not allowed. Possibly, this is a read-only mailing list. Contact the list owner for details."); +/* org.gnome.mailing-list-actions:ask-send-message primary */ +char *s = N_("Send e-mail message to mailing list?"); +/* org.gnome.mailing-list-actions:ask-send-message secondary */ +char *s = N_("An e-mail message will be sent to the URL \"{0}\". You can either send the message automatically, or see and change it first.\n" + "\n" + "You should receive an answer from the mailing list shortly after the message has been sent."); +char *s = N_("_Send message"); +char *s = N_("_Edit message"); +/* org.gnome.mailing-list-actions:malformed-header primary */ +char *s = N_("Malformed header"); +/* org.gnome.mailing-list-actions:malformed-header secondary */ +char *s = N_("The {0} header of this message is malformed and could not be processed.\n" + "\n" + "Header: {1}"); +/* org.gnome.mailing-list-actions:no-action primary */ +char *s = N_("No e-mail action"); +/* org.gnome.mailing-list-actions:no-action secondary */ +char *s = N_("The action could not be performed. This means the header for this action did not contain any action we could handle.\n" + "\n" + "Header: {0}"); diff --git a/plugins/mailing-list-actions/org-gnome-mailing-list-actions.eplug.in b/plugins/mailing-list-actions/org-gnome-mailing-list-actions.eplug.in new file mode 100644 index 0000000000..749bc9fdc3 --- /dev/null +++ b/plugins/mailing-list-actions/org-gnome-mailing-list-actions.eplug.in @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<e-plugin-list> + <e-plugin + type="shlib" + id="org.gnome.plugin.mailing-list.actions" + domain="eplug-mailing-list-actions" + location="@PLUGINDIR@/liborg-gnome-mailing-list-actions.so" + name="Mailing List Actions plugin" + description="Provide actions for common mailing list commands (subscribe, unsubscribe, ...)"> + <hook class="org.gnome.evolution.mail.bonobomenu:1.0"> + <menu id="org.gnome.evolution.mail.browser" target="select"> + <ui file="@PLUGINDIR@/org-gnome-mailing-list-actions.xml"/> + <item type="item" verb="ListHelp" path="/commands/ListHelp" visible="mailing_list" activate="emla_list_help"/> + <item type="item" verb="ListSubscribe" path="/commands/ListSubscribe" visible="mailing_list" activate="emla_list_subscribe"/> + <item type="item" verb="ListUnsubscribe" path="/commands/ListUnsubscribe" visible="mailing_list" activate="emla_list_unsubscribe"/> + <item type="item" verb="ListPost" path="/commands/ListPost" visible="mailing_list" activate="emla_list_post"/> + <item type="item" verb="ListOwner" path="/commands/ListOwner" visible="mailing_list" activate="emla_list_owner"/> + <item type="item" verb="ListArchive" path="/commands/ListArchive" visible="mailing_list" activate="emla_list_archive"/> + </menu> + <menu id="org.gnome.evolution.mail.messagebrowser" target="select"> + <ui file="@PLUGINDIR@/org-gnome-mailing-list-actions.xml"/> + <item type="item" verb="ListHelp" path="/commands/ListHelp" visible="mailing_list" activate="emla_list_help"/> + <item type="item" verb="ListSubscribe" path="/commands/ListSubscribe" visible="mailing_list" activate="emla_list_subscribe"/> + <item type="item" verb="ListUnsubscribe" path="/commands/ListUnsubscribe" visible="mailing_list" activate="emla_list_unsubscribe"/> + <item type="item" verb="ListPost" path="/commands/ListPost" visible="mailing_list" activate="emla_list_post"/> + <item type="item" verb="ListOwner" path="/commands/ListOwner" visible="mailing_list" activate="emla_list_owner"/> + <item type="item" verb="ListArchive" path="/commands/ListArchive" visible="mailing_list" activate="emla_list_archive"/> + </menu> + </hook> + <hook class="org.gnome.evolution.mail.popup:1.0"> + <menu id="org.gnome.mail.folderview.popup.select" target="select"> + <item type="bar" path="96.list" visible="mailing_list" activate=""/> + <item type="submenu" path="96.list.00" visible="mailing_list" activate="" label="Mailing _List"/> + <item type="item" verb="ListHelp" path="96.list.00/00.help" label="Get list _usage information" visible="mailing_list" activate="emla_list_help"/> + <item type="item" verb="ListSubscribe" path="96.list.00/10.subscribe" label="_Subscribe to list" visible="mailing_list" activate="emla_list_subscribe"/> + <item type="item" verb="ListUnsubscribe" path="96.list.00/20.unsubscribe" label="_Un-subscribe to list" visible="mailing_list" activate="emla_list_unsubscribe"/> + <item type="item" verb="ListPost" path="96.list.00/30.post" label="_Post message to list" visible="mailing_list" activate="emla_list_post"/> + <item type="item" verb="ListOwner" path="96.list.00/40.owner" label="Contact list _owner" visible="mailing_list" activate="emla_list_owner"/> + <item type="item" verb="ListArchive" path="96.list.00/50.archive" label="Get list _archive" visible="mailing_list" activate="emla_list_archive"/> + </menu> + </hook> + </e-plugin> +</e-plugin-list> diff --git a/plugins/mailing-list-actions/org-gnome-mailing-list-actions.xml b/plugins/mailing-list-actions/org-gnome-mailing-list-actions.xml new file mode 100644 index 0000000000..726a9dbaa8 --- /dev/null +++ b/plugins/mailing-list-actions/org-gnome-mailing-list-actions.xml @@ -0,0 +1,23 @@ +<Root> + <commands> + <cmd name="ListHelp" _tip="Get information about the usage of the list this message belongs to"/> + <cmd name="ListSubscribe" _tip="Subscribe to the mailing list this message belongs to"/> + <cmd name="ListUnsubscribe" _tip="Unsubscribe to the mailing list this message belongs to"/> + <cmd name="ListPost" _tip="Post a message to the mailing list this message belongs to"/> + <cmd name="ListOwner" _tip="Contact the owner of the mailing list this message belongs to"/> + <cmd name="ListArchive" _tip="Get an archive of the list this message belongs to"/> + </commands> + + <menu> + <submenu name="Actions"> + <submenu name="List" _label="Mailing _List"> + <menuitem verb="ListHelp" _label="Get list _usage information"/> + <menuitem verb="ListSubscribe" _label="_Subscribe to list"/> + <menuitem verb="ListUnsubscribe" _label="_Un-subscribe to list"/> + <menuitem verb="ListPost" _label="_Post message to list"/> + <menuitem verb="ListOwner" _label="Contact list _owner"/> + <menuitem verb="ListArchive" _label="Get list _archive"/> + </submenu> + </submenu> + </menu> +</Root> |