aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-07-02 23:04:27 +0800
committerDan Winship <danw@src.gnome.org>2001-07-02 23:04:27 +0800
commit5bd925e997d1b3cb74bdcb44b7bfc61c262a282b (patch)
treee354ab0ce6a85f40d9cb13814acf505dd0694329
parentfaac871501ee1935cdbaf044e2f8ac4dc00eadc2 (diff)
downloadgsoc2013-evolution-5bd925e997d1b3cb74bdcb44b7bfc61c262a282b.tar.gz
gsoc2013-evolution-5bd925e997d1b3cb74bdcb44b7bfc61c262a282b.tar.zst
gsoc2013-evolution-5bd925e997d1b3cb74bdcb44b7bfc61c262a282b.zip
Implement this, based on code that used to be in mail-ops.c
* mail-session.c (get_filter_driver): Implement this, based on code that used to be in mail-ops.c * mail-ops.c (mail_load_filter_context, setup_filter_driver): Moved into MailSession::get_filter_driver. (filter_get_folder): Moved to mail-session.c (mail_filter_folder, mail_filter_on_demand, mail_fetch_mail, mail_send_mail, mail_send_queue): Remove FilterContext args, use camel_session_get_filter_driver. * mail-send-recv.c (mail_send_receive, mail_receive_uri): Remove FilterContexts svn path=/trunk/; revision=10682
-rw-r--r--mail/ChangeLog15
-rw-r--r--mail/mail-ops.c100
-rw-r--r--mail/mail-ops.h14
-rw-r--r--mail/mail-send-recv.c17
-rw-r--r--mail/mail-session.c67
5 files changed, 102 insertions, 111 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 12e19839a9..59ce1e2d9b 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,18 @@
+2001-07-02 Dan Winship <danw@ximian.com>
+
+ * mail-session.c (get_filter_driver): Implement this, based on
+ code that used to be in mail-ops.c
+
+ * mail-ops.c (mail_load_filter_context, setup_filter_driver):
+ Moved into MailSession::get_filter_driver.
+ (filter_get_folder): Moved to mail-session.c
+ (mail_filter_folder, mail_filter_on_demand, mail_fetch_mail,
+ mail_send_mail, mail_send_queue): Remove FilterContext args, use
+ camel_session_get_filter_driver.
+
+ * mail-send-recv.c (mail_send_receive, mail_receive_uri):
+ Remove FilterContexts
+
2001-07-01 Chris Toshok <toshok@ximian.com>
* subscribe-dialog.c (subscribe_dialog_gui_init): the FolderSearch
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index f433d99c5a..02b936d1f8 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -49,68 +49,6 @@
#define d(x) x
-FilterContext *
-mail_load_filter_context(void)
-{
- char *user;
- char *system;
- FilterContext *fc;
-
- user = g_strdup_printf ("%s/filters.xml", evolution_dir);
- system = EVOLUTION_DATADIR "/evolution/filtertypes.xml";
- fc = filter_context_new ();
- rule_context_load ((RuleContext *)fc, system, user);
- g_free (user);
-
- return fc;
-}
-
-static void
-setup_filter_driver(CamelFilterDriver *driver, FilterContext *fc, const char *source)
-{
- GString *fsearch, *faction;
- FilterFilter *rule = NULL;
-
- if (TRUE /* perform_logging */) {
- char *filename = g_strdup_printf("%s/evolution-filter-log", evolution_dir);
- /* FIXME: This is a nasty little thing to stop leaking file handles.
- Needs to be setup elsewhere. */
- static FILE *logfile = NULL;
-
- if (logfile == NULL)
- logfile = fopen(filename, "a+");
- g_free(filename);
- if (logfile)
- camel_filter_driver_set_logfile(driver, logfile);
- }
-
- fsearch = g_string_new ("");
- faction = g_string_new ("");
-
- while ((rule = (FilterFilter *)rule_context_next_rule((RuleContext *)fc, (FilterRule *)rule, source))) {
- g_string_truncate (fsearch, 0);
- g_string_truncate (faction, 0);
-
- filter_rule_build_code ((FilterRule *)rule, fsearch);
- filter_filter_build_action (rule, faction);
-
- camel_filter_driver_add_rule(driver, ((FilterRule *)rule)->name, fsearch->str, faction->str);
- }
-
- g_string_free (fsearch, TRUE);
- g_string_free (faction, TRUE);
-}
-
-static CamelFolder *
-filter_get_folder(CamelFilterDriver *d, const char *uri, void *data, CamelException *ex)
-{
- CamelFolder *folder;
-
- folder = mail_tool_uri_to_folder(uri, ex);
-
- return folder;
-}
-
/* used for both just filtering a folder + uid's, and for filtering a whole folder */
/* used both for fetching mail, and for filtering mail */
struct _filter_mail_msg {
@@ -225,8 +163,7 @@ static struct _mail_msg_op filter_folder_op = {
void
mail_filter_folder(CamelFolder *source_folder, GPtrArray *uids,
- FilterContext *fc, const char *type,
- CamelOperation *cancel)
+ const char *type, CamelOperation *cancel)
{
struct _filter_mail_msg *m;
@@ -239,22 +176,17 @@ mail_filter_folder(CamelFolder *source_folder, GPtrArray *uids,
m->cancel = cancel;
camel_operation_ref (cancel);
}
-
- m->driver = camel_filter_driver_new (filter_get_folder, NULL);
- setup_filter_driver (m->driver, fc, type);
-
- e_thread_put (mail_thread_new, (EMsg *)m);
+
+ m->driver = camel_session_get_filter_driver (session, type, NULL);
+
+ e_thread_put(mail_thread_new, (EMsg *)m);
}
/* convenience function for it */
void
mail_filter_on_demand (CamelFolder *folder, GPtrArray *uids)
{
- FilterContext *fc;
-
- fc = mail_load_filter_context ();
- mail_filter_folder (folder, uids, fc, FILTER_SOURCE_INCOMING, NULL);
- gtk_object_unref (GTK_OBJECT (fc));
+ mail_filter_folder (folder, uids, FILTER_SOURCE_INCOMING, NULL);
}
/* ********************************************************************** */
@@ -389,8 +321,7 @@ static struct _mail_msg_op fetch_mail_op = {
/* ouch, a 'do everything' interface ... */
void mail_fetch_mail(const char *source, int keep,
- FilterContext *fc, const char *type,
- CamelOperation *cancel,
+ const char *type, CamelOperation *cancel,
CamelFilterGetFolderFunc get_folder, void *get_data,
CamelFilterStatusFunc *status, void *status_data,
void (*done)(char *source, void *data), void *data)
@@ -409,8 +340,8 @@ void mail_fetch_mail(const char *source, int keep,
m->done = done;
m->data = data;
- fm->driver = camel_filter_driver_new(get_folder, get_data);
- setup_filter_driver(fm->driver, fc, type);
+ fm->driver = camel_session_get_filter_driver (session, type, NULL);
+ camel_filter_driver_set_folder_func (fm->driver, get_folder, get_data);
if (status)
camel_filter_driver_set_status_func(fm->driver, status, status_data);
@@ -657,7 +588,6 @@ mail_send_mail(const char *uri, CamelMimeMessage *message, void (*done) (char *u
{
struct _send_mail_msg *m;
int id;
- FilterContext *fc;
m = mail_msg_new(&send_mail_op, NULL, sizeof(*m));
m->destination = g_strdup(uri);
@@ -668,10 +598,7 @@ mail_send_mail(const char *uri, CamelMimeMessage *message, void (*done) (char *u
id = m->msg.seq;
- m->driver = camel_filter_driver_new(filter_get_folder, NULL);
- fc = mail_load_filter_context();
- setup_filter_driver(m->driver, fc, FILTER_SOURCE_OUTGOING);
- gtk_object_unref((GtkObject *)fc);
+ m->driver = camel_session_get_filter_driver(session, FILTER_SOURCE_OUTGOING, NULL);
e_thread_put(mail_thread_new, (EMsg *)m);
return id;
@@ -797,8 +724,7 @@ static struct _mail_msg_op send_queue_op = {
/* same interface as fetch_mail, just 'cause i'm lazy today (and we need to run it from the same spot?) */
void
mail_send_queue(CamelFolder *queue, const char *destination,
- FilterContext *fc, const char *type,
- CamelOperation *cancel,
+ const char *type, CamelOperation *cancel,
CamelFilterGetFolderFunc get_folder, void *get_data,
CamelFilterStatusFunc *status, void *status_data,
void (*done)(char *destination, void *data), void *data)
@@ -818,8 +744,8 @@ mail_send_queue(CamelFolder *queue, const char *destination,
m->done = done;
m->data = data;
- m->driver = camel_filter_driver_new(get_folder, get_data);
- setup_filter_driver(m->driver, fc, type);
+ m->driver = camel_session_get_filter_driver (session, type, NULL);
+ camel_filter_driver_set_folder_func (m->driver, get_folder, get_data);
e_thread_put(mail_thread_new, (EMsg *)m);
}
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index cf8cc892ff..a7b777116c 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -36,14 +36,9 @@ extern "C" {
#include "camel/camel-mime-message.h"
#include "camel/camel-operation.h"
-#include "filter/filter-context.h"
-
#include "evolution-storage.h" /*EvolutionStorage */
#include "e-util/e-msgport.h"
-/* utility functions */
-FilterContext *mail_load_filter_context (void);
-
void mail_append_mail (CamelFolder *folder, CamelMimeMessage *message, CamelMessageInfo *info,
void (*done)(CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, int ok, void *data),
void *data);
@@ -133,24 +128,21 @@ int mail_update_subfolders (CamelStore *store, EvolutionStorage *storage,
/* yeah so this is messy, but it does a lot, maybe i can consolidate all user_data's to be the one */
void mail_send_queue (CamelFolder *queue, const char *destination,
- FilterContext *fc, const char *type,
- CamelOperation *cancel,
+ const char *type, CamelOperation *cancel,
CamelFilterGetFolderFunc get_folder, void *get_data,
CamelFilterStatusFunc *status, void *status_data,
void (*done)(char *destination, void *data),
void *data);
void mail_fetch_mail (const char *source, int keep,
- FilterContext *fc, const char *type,
- CamelOperation *cancel,
+ const char *type, CamelOperation *cancel,
CamelFilterGetFolderFunc get_folder, void *get_data,
CamelFilterStatusFunc *status, void *status_data,
void (*done)(char *source, void *data),
void *data);
void mail_filter_folder (CamelFolder *source_folder, GPtrArray *uids,
- FilterContext *fc, const char *type,
- CamelOperation *cancel);
+ const char *type, CamelOperation *cancel);
/* convenience function for above */
void mail_filter_on_demand (CamelFolder *folder, GPtrArray *uids);
diff --git a/mail/mail-send-recv.c b/mail/mail-send-recv.c
index 03411b5433..f4186ff340 100644
--- a/mail/mail-send-recv.c
+++ b/mail/mail-send-recv.c
@@ -34,7 +34,6 @@
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-window-icon.h>
-#include "filter/filter-context.h"
#include "filter/filter-filter.h"
#include "camel/camel-filter-driver.h"
#include "camel/camel-folder.h"
@@ -589,7 +588,6 @@ void mail_send_receive(void)
{
GSList *sources;
GList *scan;
- FilterContext *fc;
static GtkWidget *gd = NULL;
struct _send_data *data;
extern CamelFolder *outbox_folder;
@@ -609,8 +607,6 @@ void mail_send_receive(void)
if (!account || !account->transport)
return;
- fc = mail_load_filter_context();
-
/* what to do about pop before smtp ?
Well, probably hook into receive_done or receive_status on
the right pop account, and when it is, then kick off the
@@ -625,7 +621,7 @@ void mail_send_receive(void)
switch(info->type) {
case SEND_RECEIVE:
mail_fetch_mail(info->uri, info->keep,
- fc, FILTER_SOURCE_INCOMING,
+ FILTER_SOURCE_INCOMING,
info->cancel,
receive_get_folder, info,
receive_status, info,
@@ -634,7 +630,7 @@ void mail_send_receive(void)
case SEND_SEND:
/* todo, store the folder in info? */
mail_send_queue(outbox_folder, info->uri,
- fc, FILTER_SOURCE_OUTGOING,
+ FILTER_SOURCE_OUTGOING,
info->cancel,
receive_get_folder, info,
receive_status, info,
@@ -647,8 +643,6 @@ void mail_send_receive(void)
}
scan = scan->next;
}
-
- gtk_object_unref((GtkObject *)fc);
}
struct _auto_data {
@@ -743,7 +737,6 @@ mail_autoreceive_setup(void)
them in to add them. */
void mail_receive_uri(const char *uri, int keep)
{
- FilterContext *fc;
struct _send_info *info;
struct _send_data *data;
extern CamelFolder *outbox_folder;
@@ -777,11 +770,10 @@ void mail_receive_uri(const char *uri, int keep)
g_hash_table_insert(data->active, info->uri, info);
- fc = mail_load_filter_context();
switch(info->type) {
case SEND_RECEIVE:
mail_fetch_mail(info->uri, info->keep,
- fc, FILTER_SOURCE_INCOMING,
+ FILTER_SOURCE_INCOMING,
info->cancel,
receive_get_folder, info,
receive_status, info,
@@ -790,7 +782,7 @@ void mail_receive_uri(const char *uri, int keep)
case SEND_SEND:
/* todo, store the folder in info? */
mail_send_queue(outbox_folder, info->uri,
- fc, FILTER_SOURCE_OUTGOING,
+ FILTER_SOURCE_OUTGOING,
info->cancel,
receive_get_folder, info,
receive_status, info,
@@ -801,5 +793,4 @@ void mail_receive_uri(const char *uri, int keep)
mail_get_store(info->uri, receive_update_got_store, info);
break;
}
- gtk_object_unref((GtkObject *)fc);
}
diff --git a/mail/mail-session.c b/mail/mail-session.c
index 88a69f8097..9a3e519d5e 100644
--- a/mail/mail-session.c
+++ b/mail/mail-session.c
@@ -30,8 +30,12 @@
#include <libgnomeui/gnome-dialog-util.h>
#include <libgnomeui/gnome-messagebox.h>
#include <libgnomeui/gnome-stock.h>
+#include "camel/camel-filter-driver.h"
+#include "filter/filter-context.h"
+#include "filter/filter-filter.h"
#include "mail.h"
#include "mail-session.h"
+#include "mail-tools.h"
#include "mail-mt.h"
CamelSession *session;
@@ -48,6 +52,7 @@ typedef struct _MailSession {
GHashTable *passwords;
gboolean interaction_enabled;
+ FILE *filter_logfile;
} MailSession;
typedef struct _MailSessionClass {
@@ -66,6 +71,9 @@ static gboolean alert_user (CamelSession *session, CamelSessionAlertType type,
static guint register_timeout (CamelSession *session, guint32 interval,
CamelTimeoutCallback cb, gpointer camel_data);
static gboolean remove_timeout (CamelSession *session, guint handle);
+static CamelFilterDriver *get_filter_driver (CamelSession *session,
+ const char *type,
+ CamelException *ex);
static char *decode_base64 (char *base64);
@@ -102,6 +110,7 @@ class_init (MailSessionClass *mail_session_class)
camel_session_class->alert_user = alert_user;
camel_session_class->register_timeout = register_timeout;
camel_session_class->remove_timeout = remove_timeout;
+ camel_session_class->get_filter_driver = get_filter_driver;
}
static CamelType
@@ -280,6 +289,64 @@ remove_timeout (CamelSession *session, guint handle)
return TRUE;
}
+static CamelFolder *
+get_folder (CamelFilterDriver *d, const char *uri, void *data, CamelException *ex)
+{
+ return mail_tool_uri_to_folder(uri, ex);
+}
+
+static CamelFilterDriver *
+get_filter_driver (CamelSession *session, const char *type, CamelException *ex)
+{
+ CamelFilterDriver *driver;
+ RuleContext *fc;
+ GString *fsearch, *faction;
+ FilterRule *rule = NULL;
+ char *user, *system, *filename;
+
+ user = g_strdup_printf ("%s/filters.xml", evolution_dir);
+ system = EVOLUTION_DATADIR "/evolution/filtertypes.xml";
+ fc = (RuleContext *)filter_context_new ();
+ rule_context_load (fc, system, user);
+ g_free (user);
+
+ driver = camel_filter_driver_new ();
+ camel_filter_driver_set_folder_func (driver, get_folder, NULL);
+
+ if (TRUE /* perform_logging FIXME */) {
+ MailSession *ms = (MailSession *)session;
+
+ if (ms->filter_logfile == NULL) {
+ filename = g_strdup_printf ("%s/evolution-filter-log",
+ evolution_dir);
+ ms->filter_logfile = fopen (filename, "a+");
+ g_free (filename);
+ }
+ if (ms->filter_logfile)
+ camel_filter_driver_set_logfile (driver, ms->filter_logfile);
+ }
+
+ fsearch = g_string_new ("");
+ faction = g_string_new ("");
+
+ while ((rule = rule_context_next_rule (fc, rule, type))) {
+ g_string_truncate (fsearch, 0);
+ g_string_truncate (faction, 0);
+
+ filter_rule_build_code (rule, fsearch);
+ filter_filter_build_action ((FilterFilter *)rule, faction);
+
+ camel_filter_driver_add_rule (driver, rule->name,
+ fsearch->str, faction->str);
+ }
+
+ g_string_free (fsearch, TRUE);
+ g_string_free (faction, TRUE);
+
+ gtk_object_unref (GTK_OBJECT (fc));
+ return driver;
+}
+
static char *
decode_base64 (char *base64)