[PATCH] : enable automatic filtering on local mailboxes + bug fixes
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: [PATCH] : enable automatic filtering on local mailboxes + bug fixes
- Date: Thu, 14 Feb 2002 16:23:28 +0100
Hi all,
here is a patch that will enable automatic filtering (ie "On reception")
for local mailboxes. This is still not perfect because it won't work for a
check on startup (I explained the reasons I see in a previous post). But
still it seems to be OK out of this case.
I used the libmutt message flag "old" to tell if a message has just
arrived so that the filter will act only on those messages, what is
commonly assumed when you set up a filter to run "On reception".
Moreover it fixes a bug in the pop3 filter code that will prevent filters
to be run automatically in most cases (in fact the code did not load the
filters associated to the mailbox, so if you didn't do it before, opening
the Edit/Apply dialog box for this mailbox, the code just thought there
was no filter), plus a memory leak fixed.
Usual disclaimer from me : I have tested that only on 1.2.4, so I don't
know how it integrates in CVS, so comments, remarks, tests will be greatly
appreciated ;-)
Attached patch touches :
-filter.c, filter.h : add a function to extract "new" messages
from the mailbox;
-libbalsa.c : set a libmutt flag so that libmutt keeps track of
the "old" flag;
-mailbox_local.c, mailbox_pop3.c : adds/cleans the actual
filtering code.
Bye
Manu
--- ../balsa-cvs/balsa/libbalsa/filter.h Mon Nov 26 10:07:00 2001
+++ balsa-cvs/balsa/libbalsa/filter.h Thu Feb 14 15:54:21 2002
@@ -189,6 +189,12 @@
LibBalsaFilter* libbalsa_filter_get_by_name(const gchar* fname);
+/* libbalsa_filter_new_messages : returns a sublist of the
+ messages list containing all "new" messages, ie just retrieved mails
+*/
+
+GList * libbalsa_filter_new_messages(GList * messages);
+
/*
* Dialog calls
*/
--- ../balsa-cvs/balsa/libbalsa/filter.c Wed Jan 30 17:48:58 2002
+++ balsa-cvs/balsa/libbalsa/filter.c Thu Feb 14 15:56:00 2002
@@ -320,6 +320,20 @@
return result;
}
+/* libbalsa_filter_new_messages : returns a sublist of the messages
+ list containing all "new" messages, ie just retrieved mails
+*/
+
+GList * libbalsa_filter_new_messages(GList * messages)
+{
+ GList * extracted=NULL;
+
+ for (;messages;messages=g_list_next(messages))
+ if (!LIBBALSA_MESSAGE(messages->data)->header->old)
+ extracted = g_list_prepend(extracted,messages->data);
+ return extracted;
+}
+
/*--------- End of Filtering functions -------------------------------*/
LibBalsaFilter*
--- ../balsa-cvs/balsa/libbalsa/libbalsa.c Sun Dec 16 10:29:09 2001
+++ balsa-cvs/balsa/libbalsa/libbalsa.c Thu Feb 14 15:58:16 2002
@@ -134,6 +134,15 @@
set_option(OPTSAVEEMPTY);
set_option(OPTCHECKNEW);
set_option(OPTMHPURGE);
+
+#ifdef BALSA_SHOW_ALL
+ /* FIXME : I want libmutt to keep track of "new" messages
+ We use this to know which messages have been just appended
+ to the mailbox, this way we can do automatic filtering
+ on incoming mails only */
+ set_option(OPTMARKOLD);
+#endif /* BALSA_SHOW_ALL */
+
#ifdef USE_SSL
set_option(OPTSSLSYSTEMCERTS);
#endif /* USE_SSL */
--- ../balsa-cvs/balsa/libbalsa/mailbox_pop3.c Sun Jan 6 20:41:09 2002
+++ balsa-cvs/balsa/libbalsa/mailbox_pop3.c Thu Feb 14 16:03:10 2002
@@ -299,12 +299,18 @@
if((m->inbox) && (tmp_mailbox->messages)) {
#ifdef BALSA_SHOW_ALL
- GSList * filters=
- libbalsa_mailbox_filters_when(LIBBALSA_MAILBOX(m)->filters,
- FILTER_WHEN_INCOMING);
+ GSList * filters;
+ /* Load associated filters if needed */
+ if (LIBBALSA_MAILBOX(m)->filters)
+ config_mailbox_filters_load(LIBBALSA_MAILBOX(m));
+
+ filters = libbalsa_mailbox_filters_when(LIBBALSA_MAILBOX(m)->filters,
+ FILTER_WHEN_INCOMING);
+
/* We apply filter if needed */
filters_run_on_messages(filters, tmp_mailbox->message_list);
+ g_slist_free(filters);
#endif /*BALSA_SHOW_ALL*/
if (!libbalsa_messages_move(tmp_mailbox->message_list, m->inbox)) {
--- ../balsa-cvs/balsa/libbalsa/mailbox_local.c Mon Jan 21 15:16:11 2002
+++ balsa-cvs/balsa/libbalsa/mailbox_local.c Thu Feb 14 16:11:47 2002
@@ -39,6 +39,10 @@
#include "threads.h"
#endif
+#ifdef BALSA_SHOW_ALL
+#include "mailbox-filter.h"
+#endif /*BALSA_SHOW_ALL*/
+
enum {
REMOVE_FILES,
LAST_SIGNAL
@@ -338,6 +342,20 @@
UNLOCK_MAILBOX(mailbox);
}
}
+#ifdef BALSA_SHOW_ALL
+ /* Load associated filters if needed */
+ if (!mailbox->filters)
+ config_mailbox_filters_load(LIBBALSA_MAILBOX(mailbox));
+
+ filters = libbalsa_mailbox_filters_when(LIBBALSA_MAILBOX(mailbox)->filters,
+ FILTER_WHEN_INCOMING);
+
+ /* We apply filter if needed */
+ new_messages = libbalsa_filter_new_messages(mailbox->message_list);
+ filters_run_on_messages(filters, new_messages);
+ g_list_free(new_messages);
+ g_slist_free(filters);
+#endif /*BALSA_SHOW_ALL*/
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]