aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-08-09 15:20:37 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-08-09 15:20:37 +0800
commit443b5a82a99f5b3ea9e82d7c05508c0140ee87a1 (patch)
tree1b896f8c95557569e4cc93fddff1f66e942c7d5f /mail
parent2f6003c9ed5291b6feb4694bbf5f88084adeded6 (diff)
downloadgsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar.gz
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar.bz2
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar.lz
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar.xz
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.tar.zst
gsoc2013-evolution-443b5a82a99f5b3ea9e82d7c05508c0140ee87a1.zip
Helper function to add with confirm.
2000-08-09 Not Zed <NotZed@HelixCode.com> * mail-autofilter.c (filter_gui_add_from_message): Helper function to add with confirm. * message-list.c (on_right_click): Added menu to install vfolders/filters from message. svn path=/trunk/; revision=4646
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog8
-rw-r--r--mail/Makefile.am1
-rw-r--r--mail/mail-autofilter.c119
-rw-r--r--mail/mail-autofilter.h21
-rw-r--r--mail/mail-vfolder.c11
-rw-r--r--mail/mail-vfolder.h2
-rw-r--r--mail/message-list.c59
7 files changed, 137 insertions, 84 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 70ce338611..fbd10ed9e4 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,13 @@
2000-08-09 Not Zed <NotZed@HelixCode.com>
+ * mail-autofilter.c (filter_gui_add_from_message): Helper function to add with confirm.
+
+ * message-list.c (on_right_click): Added menu to install vfolders/filters from message.
+
+<<<<<<< ChangeLog
+<<<<<<< ChangeLog
+2000-08-09 Not Zed <NotZed@HelixCode.com>
+
* mail-autofilter.c: New file to hold auto filter/vfolder stuff.
2000-08-09 Christopher James Lahey <clahey@helixcode.com>
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 076340c6cd..63c15e7e7e 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -43,6 +43,7 @@ evolution_mail_SOURCES = \
folder-browser.h \
folder-browser-factory.c \
mail-autofilter.c \
+ mail-autofilter.h \
mail-config.c \
mail-config.h \
mail-config-gui.c \
diff --git a/mail/mail-autofilter.c b/mail/mail-autofilter.c
index eec67758cd..7f1b9bc69a 100644
--- a/mail/mail-autofilter.c
+++ b/mail/mail-autofilter.c
@@ -18,6 +18,7 @@
#include "evolution-shell-component.h"
#include "folder-browser.h"
#include "mail-vfolder.h"
+#include "mail-autofilter.h"
#include "camel/camel.h"
@@ -30,12 +31,6 @@
#include "filter/filter-editor.h"
#include "filter/filter-option.h"
-enum {
- AUTO_SUBJECT = 0x01,
- AUTO_FROM = 0x02,
- AUTO_TO = 0x04,
-};
-
static void
rule_match_recipients(RuleContext *context, FilterRule *rule, CamelInternetAddress *iaddr)
{
@@ -43,6 +38,7 @@ rule_match_recipients(RuleContext *context, FilterRule *rule, CamelInternetAddre
FilterElement *element;
int i;
const char *real, *addr;
+ char *namestr;
/* address types etc should handle multiple values */
for (i=0;camel_internet_address_get(iaddr, i, &real, &addr);i++) {
@@ -52,6 +48,10 @@ rule_match_recipients(RuleContext *context, FilterRule *rule, CamelInternetAddre
filter_option_set_current((FilterOption *)element, "contains");
element = filter_part_find_element(part, "recipient");
filter_input_set_value((FilterInput *)element, addr);
+
+ namestr = g_strdup_printf("Mail to %s", real?real:addr);
+ filter_rule_set_name(rule, namestr);
+ g_free(namestr);
}
}
@@ -187,17 +187,27 @@ rule_from_message(FilterRule *rule, RuleContext *context, CamelMimeMessage *msg,
if (flags & AUTO_SUBJECT) {
rule_match_subject(context, rule, msg->subject);
+ filter_rule_set_name(rule, strip_re(msg->subject));
}
/* should parse the from address into an internet address? */
if (flags & AUTO_FROM) {
struct _header_address *haddr, *scan;
+ char *name, *namestr;
haddr = header_address_decode(msg->from);
scan = haddr;
while (scan) {
if (scan->type == HEADER_ADDRESS_NAME) {
rule_add_sender(context, rule, scan->v.addr);
+ if (scan->name)
+ name = scan->name;
+ else
+ name = scan->v.addr;
+ namestr = g_strdup_printf("Mail from %s", name);
+ filter_rule_set_name(rule, namestr);
+ g_free(namestr);
}
+ scan = scan->next;
}
header_address_unref(haddr);
}
@@ -210,101 +220,46 @@ rule_from_message(FilterRule *rule, RuleContext *context, CamelMimeMessage *msg,
}
FilterRule *
-vfolder_rule_from_message(RuleContext *context, FolderBrowser *fb, CamelMimeMessage *msg, int flags)
+vfolder_rule_from_message(VfolderContext *context, CamelMimeMessage *msg, int flags, const char *source)
{
VfolderRule *rule;
rule = vfolder_rule_new();
- vfolder_rule_add_source(rule, fb->uri);
- rule_from_message((FilterRule *)rule, context, msg, flags);
+ vfolder_rule_add_source(rule, source);
+ rule_from_message((FilterRule *)rule, (RuleContext *)context, msg, flags);
return (FilterRule *)rule;
}
FilterRule *
-filter_rule_from_message(RuleContext *context, FolderBrowser *fb, CamelMimeMessage *msg, int flags)
+filter_rule_from_message(FilterContext *context, CamelMimeMessage *msg, int flags)
{
FilterFilter *rule;
rule = filter_filter_new();
- rule_from_message((FilterRule *)rule, context, msg, flags);
+ rule_from_message((FilterRule *)rule, (RuleContext *)context, msg, flags);
/* should we define the default action? */
return (FilterRule *)rule;
}
-#if 0
-
-#error "Ok, this is all useless because we're not using gnome-libs afteralll ..."
-
-static void create_filter(GtkWidget *w, void *data);
-static void create_vfolder(GtkWidget *w, void *data);
-
-static GnomeUIInfo auto_filter_popup[] = {
- GNOMEUIINFO_ITEM_NONE("Subject", "", create_filter),
- GNOMEUIINFO_ITEM_NONE("From", "", create_filter),
- GNOMEUIINFO_ITEM_NONE("To", "", create_filter),
- GNOMEUIINFO_ITEM_NONE("Subject & To", "", create_filter),
- GNOMEUIINFO_ITEM_NONE("Subject & From", "", create_filter),
- GNOMEUIINFO_END
-};
-
-static GnomeUIInfo auto_vfolder_popup[] = {
- GNOMEUIINFO_ITEM_NONE("Subject", "", create_vfolder),
- GNOMEUIINFO_ITEM_NONE("From", "", create_vfolder),
- GNOMEUIINFO_ITEM_NONE("To", "", create_vfolder),
- GNOMEUIINFO_ITEM_NONE("Subject & To", "", create_vfolder),
- GNOMEUIINFO_ITEM_NONE("Subject & From", "", create_vfolder),
- GNOMEUIINFO_END
-};
-
-static GnomeUIInfo auto_popup[] = {
- GNOMEUIINFO_SUBTREE("New Filter", auto_filter_popup),
- GNOMEUIINFO_SUBTREE("New vFolder", auto_vfolder_popup),
- GNOMEUIINFO_END
-};
-
-static int flags[] = {
- AUTO_SUBJECT, AUTO_FROM, AUTO_TO,
- AUTO_SUBJECT|AUTO_TO, AUTO_SUBJECT|AUTO_FROM
-};
-
-static int widget_index(GnomeUIInfo *info, GtkWidget *w)
-{
- int i;
-
- for (i=0;info[i].widget;i++)
- if (info[i].widget == w)
- return i;
- return -1;
-}
-
-static void
-create_filter(GtkWidget *w, void *data)
-{
- int index;
-
- index = widget_index(auto_filter_popup, w);
- printf("filter index = %d\n", index);
-}
-
-static void
-create_vfolder(GtkWidget *w, void *data)
-{
- int index;
-
- index = widget_index(auto_vfolder_popup, w);
- printf("filter index = %d\n", index);
-}
-
void
-message_popup(GdkEventButton *event, FolderBrowser *fb)
+filter_gui_add_from_message(CamelMimeMessage *msg, int flags)
{
- GtkWidget *popup_menu;
- int i;
-
- popup_menu = gnome_popup_menu_new(auto_popup);
- gnome_popup_menu_do_popup(popup_menu, NULL, NULL, event, fb);
+ FilterContext *fc;
+ char *userrules, *systemrules;
+ FilterRule *rule;
+ extern char *evolution_dir;
+
+ fc = filter_context_new();
+ userrules = g_strdup_printf("%s/filters.xml", evolution_dir);
+ systemrules = g_strdup_printf("%s/evolution/filtertypes.xml", EVOLUTION_DATADIR);
+ rule_context_load((RuleContext *)fc, systemrules, userrules);
+ rule = filter_rule_from_message(fc, msg, flags);
+ rule_context_add_rule_gui((RuleContext *)fc, rule, "Add Filter Rule", userrules);
+ g_free (userrules);
+ g_free (systemrules);
+ gtk_object_unref((GtkObject *)fc);
}
-#endif
+
diff --git a/mail/mail-autofilter.h b/mail/mail-autofilter.h
new file mode 100644
index 0000000000..61df9273fd
--- /dev/null
+++ b/mail/mail-autofilter.h
@@ -0,0 +1,21 @@
+#ifndef _MAIL_AUTOFILTER_H
+#define _MAIL_AUTOFILTER_H
+
+#include "filter/filter-rule.h"
+#include "filter/filter-context.h"
+#include "filter/vfolder-context.h"
+#include "camel/camel-mime-message.h"
+
+enum {
+ AUTO_SUBJECT = 1,
+ AUTO_FROM = 2,
+ AUTO_TO = 4
+};
+
+FilterRule *vfolder_rule_from_message(VfolderContext *context, CamelMimeMessage *msg, int flags, const char *source);
+FilterRule *filter_rule_from_message(FilterContext *context, CamelMimeMessage *msg, int flags);
+
+/* easiest place to put this */
+void filter_gui_add_from_message(CamelMimeMessage *msg, int flags);
+
+#endif
diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c
index cd613040b1..fab59ef991 100644
--- a/mail/mail-vfolder.c
+++ b/mail/mail-vfolder.c
@@ -19,6 +19,7 @@
#include "evolution-shell-component.h"
#include "folder-browser.h"
#include "mail-vfolder.h"
+#include "mail-autofilter.h"
#include "camel/camel.h"
@@ -304,3 +305,13 @@ vfolder_gui_add_rule(VfolderRule *rule)
gtk_signal_connect((GtkObject *)gd, "clicked", new_rule_clicked, NULL);
gtk_widget_show((GtkWidget *)gd);
}
+
+void
+vfolder_gui_add_from_message(CamelMimeMessage *msg, int flags, const char *source)
+{
+ VfolderRule *rule;
+
+ rule = (VfolderRule*)vfolder_rule_from_message(context, msg, flags, source);
+ vfolder_gui_add_rule(rule);
+}
+
diff --git a/mail/mail-vfolder.h b/mail/mail-vfolder.h
index 10f20777d2..4e87276322 100644
--- a/mail/mail-vfolder.h
+++ b/mail/mail-vfolder.h
@@ -9,6 +9,7 @@
#include "evolution-shell-component.h"
#include "camel/camel-folder.h"
+#include "camel/camel-mime-message.h"
#include "filter/vfolder-rule.h"
#include "filter/filter-part.h"
@@ -18,5 +19,6 @@ CamelFolder *vfolder_uri_to_folder(const char *uri);
void vfolder_edit(void);
FilterPart *vfolder_create_part(const char *name);
void vfolder_gui_add_rule(VfolderRule *rule);
+void vfolder_gui_add_from_message(CamelMimeMessage *msg, int flags, const char *source);
#endif
diff --git a/mail/message-list.c b/mail/message-list.c
index 34cf89664a..eac938bb36 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -25,6 +25,9 @@
#include "widgets/e-table/e-table-header-item.h"
#include "widgets/e-table/e-table-item.h"
+#include "mail-vfolder.h"
+#include "mail-autofilter.h"
+
#include "art/mail-new.xpm"
#include "art/mail-read.xpm"
#include "art/mail-replied.xpm"
@@ -978,11 +981,51 @@ select_row (ETableScrolled *table, gpointer user_data)
gtk_idle_add (idle_select_row, message_list->etable);
}
+static void
+vfolder_subject(GtkWidget *w, FolderBrowser *fb)
+{
+ vfolder_gui_add_from_message(fb->mail_display->current_message, AUTO_SUBJECT,
+ fb->uri);
+}
+
+static void
+vfolder_sender(GtkWidget *w, FolderBrowser *fb)
+{
+ vfolder_gui_add_from_message(fb->mail_display->current_message, AUTO_FROM,
+ fb->uri);
+}
+
+static void
+vfolder_recipient(GtkWidget *w, FolderBrowser *fb)
+{
+ vfolder_gui_add_from_message(fb->mail_display->current_message, AUTO_TO,
+ fb->uri);
+}
+
+static void
+filter_subject(GtkWidget *w, FolderBrowser *fb)
+{
+ filter_gui_add_from_message(fb->mail_display->current_message, AUTO_SUBJECT);
+}
+
+static void
+filter_sender(GtkWidget *w, FolderBrowser *fb)
+{
+ filter_gui_add_from_message(fb->mail_display->current_message, AUTO_FROM);
+}
+
+static void
+filter_recipient(GtkWidget *w, FolderBrowser *fb)
+{
+ filter_gui_add_from_message(fb->mail_display->current_message, AUTO_TO);
+}
+
static gint
on_right_click (ETableScrolled *table, gint row, gint col, GdkEvent *event, MessageList *list)
{
FolderBrowser *fb = list->parent_folder_browser;
extern CamelFolder *drafts_folder;
+ int enable_mask = 0;
EPopupMenu menu[] = {
{ "Open in New Window", NULL, GTK_SIGNAL_FUNC (view_msg), 0 },
{ "Edit Message", NULL, GTK_SIGNAL_FUNC (edit_msg), 1 },
@@ -994,10 +1037,22 @@ on_right_click (ETableScrolled *table, gint row, gint col, GdkEvent *event, Mess
{ "", NULL, GTK_SIGNAL_FUNC (NULL), 0 },
{ "Delete Message", NULL, GTK_SIGNAL_FUNC (delete_msg), 0 },
{ "Move Message", NULL, GTK_SIGNAL_FUNC (move_msg), 0 },
+ { "", NULL, GTK_SIGNAL_FUNC (NULL), 0 },
+ { "Vfolder from Subject", NULL, GTK_SIGNAL_FUNC (vfolder_subject), 2 },
+ { "Vfolder from Sender", NULL, GTK_SIGNAL_FUNC (vfolder_sender), 2 },
+ { "Vfolder from Recipients", NULL, GTK_SIGNAL_FUNC (vfolder_recipient), 2 },
+ { "Filter from Subject", NULL, GTK_SIGNAL_FUNC (filter_subject), 2 },
+ { "Filter from Sender", NULL, GTK_SIGNAL_FUNC (filter_sender), 2 },
+ { "Filter from Recipients", NULL, GTK_SIGNAL_FUNC (filter_recipient), 2 },
{ NULL, NULL, NULL, 0 }
};
-
- e_popup_menu_run (menu, (GdkEventButton *)event, (fb->folder == drafts_folder) ? 0 : 1, 0, fb);
+
+ if (fb->folder != drafts_folder)
+ enable_mask |= 1;
+ if (fb->mail_display->current_message == NULL)
+ enable_mask |= 2;
+
+ e_popup_menu_run (menu, (GdkEventButton *)event, enable_mask, 0, fb);
return TRUE;
}