From ed8a08ed1a4befb75d8d883b973f8d9516a0a80a Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 2 Nov 2000 03:52:05 +0000 Subject: Use filter_driver_log() where appropriate. (do_copy): Use the service url 2000-11-01 Jeffrey Stedfast * filter-driver.c (filter_driver_filter_message): Use filter_driver_log() where appropriate. (do_copy): Use the service url for the path rather than the folder->full_name because that'll only get you a "/mbox" which is entirely useless. Replace occurences of report_status with filter_driver_log. (do_move): Same. (report_status): Don't use this for logging anymore, use only for reporting the status back to the caller. (filter_driver_log): Renamed from filter_driver_status_log. Now ONLY handles file logging and is for INTERNAL USE ONLY. (do_flag): Replace occurences of report_status with filter_driver_log. (do_score): Same. (do_colour): Same. (do_stop): Same. svn path=/trunk/; revision=6340 --- filter/ChangeLog | 19 ++++++++ filter/filter-driver.c | 128 ++++++++++++++++++++++++++++++++----------------- filter/filter-driver.h | 9 ++-- 3 files changed, 106 insertions(+), 50 deletions(-) (limited to 'filter') diff --git a/filter/ChangeLog b/filter/ChangeLog index 1b232056ba..983f34beba 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,22 @@ +2000-11-01 Jeffrey Stedfast + + * filter-driver.c (filter_driver_filter_message): Use + filter_driver_log() where appropriate. + (do_copy): Use the service url for the path rather than the + folder->full_name because that'll only get you a "/mbox" which is + entirely useless. Replace occurences of report_status with + filter_driver_log. + (do_move): Same. + (report_status): Don't use this for logging anymore, use only for + reporting the status back to the caller. + (filter_driver_log): Renamed from filter_driver_status_log. Now + ONLY handles file logging and is for INTERNAL USE ONLY. + (do_flag): Replace occurences of report_status with + filter_driver_log. + (do_score): Same. + (do_colour): Same. + (do_stop): Same. + 2000-11-01 Jeffrey Stedfast * filter-datespec.c (validate): Check to make sure the user has diff --git a/filter/filter-driver.c b/filter/filter-driver.c index ac49bf0ac4..98f46592b8 100644 --- a/filter/filter-driver.c +++ b/filter/filter-driver.c @@ -42,13 +42,22 @@ #define d(x) +/* type of status for a log report */ +enum filter_log_t { + FILTER_LOG_NONE, + FILTER_LOG_START, /* start of new log entry */ + FILTER_LOG_ACTION, /* an action performed */ + FILTER_LOG_END, /* end of log */ +}; + struct _FilterDriverPrivate { GHashTable *globals; /* global variables */ CamelFolder *defaultfolder; /* defualt folder */ + FDStatusFunc *statusfunc; /* status callback */ void *statusdata; /* status callback data */ - + FilterContext *context; /* for callback */ @@ -65,7 +74,7 @@ struct _FilterDriverPrivate { CamelMimeMessage *message; /* input message */ CamelMessageInfo *info; /* message summary info */ - + FILE *logfile; /* log file */ CamelException *ex; @@ -80,6 +89,8 @@ static void filter_driver_class_init (FilterDriverClass *klass); static void filter_driver_init (FilterDriver *obj); static void filter_driver_finalise (GtkObject *obj); +static void filter_driver_log (FilterDriver *driver, enum filter_log_t status, const char *desc, ...); + static CamelFolder *open_folder (FilterDriver *d, const char *folder_url); static int close_folders (FilterDriver *d); @@ -197,7 +208,7 @@ filter_driver_finalise (GtkObject *obj) gtk_object_unref (GTK_OBJECT (p->eval)); if (p->defaultfolder) - camel_object_unref((CamelObject *)p->defaultfolder); + camel_object_unref (CAMEL_OBJECT (p->defaultfolder)); g_free (p); @@ -231,6 +242,13 @@ filter_driver_new (FilterContext *context, FilterGetFolderFunc get_folder, void return new; } +void +filter_driver_set_logfile (FilterDriver *d, FILE *logfile) +{ + struct _FilterDriverPrivate *p = _PRIVATE (d); + + p->logfile = logfile; +} void filter_driver_set_status_func (FilterDriver *d, FDStatusFunc *func, void *data) @@ -258,6 +276,7 @@ filter_driver_set_default_folder (FilterDriver *d, CamelFolder *def) static void report_status (FilterDriver *driver, enum filter_status_t status, const char *desc, ...) { + /* call user-defined status report function */ struct _FilterDriverPrivate *p = _PRIVATE (driver); va_list ap; char *str; @@ -265,7 +284,7 @@ report_status (FilterDriver *driver, enum filter_status_t status, const char *de if (p->statusfunc) { va_start (ap, desc); str = g_strdup_vprintf (desc, ap); - p->statusfunc (driver, status, str, p->message, p->statusdata); + p->statusfunc (driver, status, str, p->statusdata); g_free (str); } } @@ -294,7 +313,7 @@ do_delete (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver d(fprintf (stderr, "doing delete\n")); p->deleted = TRUE; - report_status (driver, FILTER_STATUS_ACTION, "Delete"); + filter_driver_log (driver, FILTER_LOG_ACTION, "Delete"); return NULL; } @@ -306,7 +325,7 @@ mark_forward (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriv d(fprintf (stderr, "marking message for forwarding\n")); /* FIXME: do stuff here */ - report_status (driver, FILTER_STATUS_ACTION, "Forward"); + filter_driver_log (driver, FILTER_LOG_ACTION, "Forward"); return NULL; } @@ -323,6 +342,7 @@ do_copy (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d if (argv[i]->type == ESEXP_RES_STRING) { /* open folders we intent to copy to */ char *folder = argv[i]->value.string; + char *service_url; CamelFolder *outbox; outbox = open_folder (driver, folder); @@ -330,8 +350,13 @@ do_copy (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d continue; mail_tool_camel_lock_up (); + camel_folder_append_message (outbox, p->message, p->info, p->ex); - report_status (driver, FILTER_STATUS_ACTION, "Copy to folder %s", outbox->full_name); + + service_url = camel_service_get_url (CAMEL_SERVICE (camel_folder_get_parent_store (outbox))); + filter_driver_log (driver, FILTER_LOG_ACTION, "Copy to folder %s", service_url); + g_free (service_url); + mail_tool_camel_lock_down (); } } @@ -352,6 +377,7 @@ do_move (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d if (argv[i]->type == ESEXP_RES_STRING) { /* open folders we intent to move to */ char *folder = argv[i]->value.string; + char *service_url; CamelFolder *outbox; outbox = open_folder (driver, folder); @@ -359,8 +385,13 @@ do_move (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d continue; mail_tool_camel_lock_up (); + camel_folder_append_message (outbox, p->message, p->info, p->ex); - report_status (driver, FILTER_STATUS_ACTION, "Move to folder %s", outbox->full_name); + + service_url = camel_service_get_url (CAMEL_SERVICE (camel_folder_get_parent_store (outbox))); + filter_driver_log (driver, FILTER_LOG_ACTION, "Move to folder %s", service_url); + g_free (service_url); + mail_tool_camel_lock_down (); } } @@ -373,7 +404,7 @@ do_stop (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d { struct _FilterDriverPrivate *p = _PRIVATE (driver); - report_status (driver, FILTER_STATUS_ACTION, "Stopped processing"); + filter_driver_log (driver, FILTER_LOG_ACTION, "Stopped processing"); d(fprintf (stderr, "terminating message processing\n")); p->terminated = TRUE; @@ -388,7 +419,7 @@ do_colour (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver d(fprintf (stderr, "setting colour tag\n")); if (argc > 0 && argv[0]->type == ESEXP_RES_STRING) { camel_tag_set (&p->info->user_tags, "colour", argv[0]->value.string); - report_status (driver, FILTER_STATUS_ACTION, "Set colour to %s", argv[0]->value.string); + filter_driver_log (driver, FILTER_LOG_ACTION, "Set colour to %s", argv[0]->value.string); } return NULL; @@ -405,7 +436,7 @@ do_score (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver * value = g_strdup_printf ("%d", argv[0]->value.number); camel_tag_set (&p->info->user_tags, "score", value); - report_status (driver, FILTER_STATUS_ACTION, "Set score to %d", argv[0]->value.number); + filter_driver_log (driver, FILTER_LOG_ACTION, "Set score to %d", argv[0]->value.number); g_free (value); } @@ -445,7 +476,7 @@ do_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d default: flag = "Unknown"; } - report_status (driver, FILTER_STATUS_ACTION, "Set %s flag", flag); + filter_driver_log (driver, FILTER_LOG_ACTION, "Set %s flag", flag); } return NULL; @@ -512,41 +543,47 @@ free_key (gpointer key, gpointer value, gpointer user_data) #endif -void -filter_driver_status_log (FilterDriver *driver, enum filter_status_t status, - const char *desc, CamelMimeMessage *msg, void *data) +static void +filter_driver_log (FilterDriver *driver, enum filter_log_t status, const char *desc, ...) { - FILE *out = data; - - switch(status) { - case FILTER_STATUS_START: { - /* write log header */ - time_t t; - char date[50]; - char *from = NULL; - char *subject = NULL; + struct _FilterDriverPrivate *p = _PRIVATE (driver); + + if (p->logfile) { + va_list ap; + char *str; - if (msg) { - from = camel_mime_message_get_from (msg); - subject = camel_mime_message_get_subject (msg); + va_start (ap, desc); + str = g_strdup_vprintf (desc, ap); + + switch (status) { + case FILTER_LOG_START: { + /* write log header */ + const char *subject = NULL; + const char *from = NULL; + char date[50]; + time_t t; + + from = camel_mime_message_get_from (p->message); + subject = camel_mime_message_get_subject (p->message); + + time (&t); + strftime (date, 49, "%a, %d %b %Y %H:%M:%S", localtime (&t)); + fprintf (p->logfile, "Applied filter \"%s\" to message from %s - \"%s\" at %s\n", + str, from ? from : "unknown", subject ? subject : "", date); + break; + } + case FILTER_LOG_ACTION: + fprintf (p->logfile, "Action: %s\n", str); + break; + case FILTER_LOG_END: + fprintf (p->logfile, "\n"); + break; + default: + /* nothing else is loggable */ + break; } - time (&t); - strftime (date, 49, "%a, %d %b %Y %H:%M:%S", localtime (&t)); - fprintf (out, " - Applied filter \"%s\" to message from %s - \"%s\" at %s\n", - desc, from ? from : "unknown", - subject ? subject : "", date); - break; - } - case FILTER_STATUS_END: - fprintf (out, "\n"); - break; - case FILTER_STATUS_ACTION: - fprintf (out, "Action: %s\n", desc); - break; - default: - /* nothing else is loggable */ - break; + g_free (str); } } @@ -715,6 +752,7 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C filter_filter_build_action (rule, faction); d(fprintf (stderr, "applying rule %s\n action %s\n", fsearch->str, faction->str)); + filter_driver_log (driver, FILTER_LOG_START, fsearch->str); mail_tool_camel_lock_up (); matched = filter_message_search (p->message, p->info, source_url, fsearch->str, p->ex); @@ -739,7 +777,7 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C if (p->defaultfolder && !p->deleted) { /* copy it to the default inbox */ - report_status (driver, FILTER_STATUS_ACTION, "Copy to default folder"); + filter_driver_log (driver, FILTER_LOG_ACTION, "Copy to default folder"); mail_tool_camel_lock_up (); camel_folder_append_message (p->defaultfolder, p->message, p->info, p->ex); mail_tool_camel_lock_down (); @@ -758,4 +796,6 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C g_free (info->cc); g_free (info); } + + filter_driver_log (driver, FILTER_LOG_END, NULL); } diff --git a/filter/filter-driver.h b/filter/filter-driver.h index 471118631e..8c6454c9b4 100644 --- a/filter/filter-driver.h +++ b/filter/filter-driver.h @@ -47,6 +47,7 @@ struct _FilterDriverClass { GtkObjectClass parent_class; }; +/* FIXME: this maybe should change... */ /* type of status for a status report */ enum filter_status_t { FILTER_STATUS_NONE, @@ -58,28 +59,24 @@ enum filter_status_t { typedef CamelFolder * (*FilterGetFolderFunc) (FilterDriver *, const char *uri, void *data); /* report status */ -typedef void (FDStatusFunc)(FilterDriver *driver, enum filter_status_t status, const char *desc, CamelMimeMessage *msg, void *data); +typedef void (FDStatusFunc)(FilterDriver *driver, enum filter_status_t status, const char *desc, void *data); guint filter_driver_get_type (void); FilterDriver *filter_driver_new (FilterContext *ctx, FilterGetFolderFunc fetcher, void *data); /* modifiers */ +void filter_driver_set_logfile (FilterDriver *d, FILE *logfile); void filter_driver_set_status_func (FilterDriver *d, FDStatusFunc *func, void *data); void filter_driver_set_default_folder (FilterDriver *d, CamelFolder *def); /*void filter_driver_set_global(FilterDriver *, const char *name, const char *value);*/ -/* filter a message - returns TRUE if the message was filtered into some location other than inbox */ void filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info, const char *source_url, const char *source, CamelException *ex); void filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *source, CamelException *ex); void filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const char *source, GPtrArray *uids, gboolean remove, CamelException *ex); -/* convenience function to log the status, data should be the FILE * of the logfile */ -void filter_driver_status_log (FilterDriver *driver, enum filter_status_t status, - const char *desc, CamelMimeMessage *msg, void *data); - #if 0 /* generate the search query/action string for a filter option */ void filter_driver_expand_option (FilterDriver *d, GString *s, GString *action, struct filter_option *op); -- cgit