aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-driver.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-10-21 10:51:38 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-10-21 10:51:38 +0800
commit6d74595779416412b478dd4ae3d38dffd3f4baae (patch)
treef5793662a36daff8df54de77077193920fb5acc3 /filter/filter-driver.c
parent3d17cca7ed57dcde3c6649e15d4ac7fe30174776 (diff)
downloadgsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar.gz
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar.bz2
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar.lz
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar.xz
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.tar.zst
gsoc2013-evolution-6d74595779416412b478dd4ae3d38dffd3f4baae.zip
Added filter-url.[c,h].
2000-10-20 Jeffrey Stedfast <fejj@helixcode.com> * Makefile.am: Added filter-url.[c,h]. * filter-message-search.c (get_source): New callback to get the source url of the message being filtered. (filter_message_search): Now takes a source argument. * filter-element.c (filter_element_new_type_name): Added code to handle URL types. * filter-url.[c,h]: New filter object to handle URLs (ie in the case of filtering on source url). FIXME: find a way to populate the source combo box (including mail-config.h breaks the build in the addressbook - how does including mail-tools.h not break the build???) * filtertypes.xml: Added the source filter type and added the move-to action. * filter-driver.c (do_move): New callback, a "Copy" action should just copy the message to another location while a Move should both copy the message to a new location and delete it from the source location. (do_delete): Set the deleted flag on the message info. (filter_driver_filter_message): Now returns void as we don't care if it was copied or not in the caller functions. Also check the CamelMessageInfo being passed in - if the message has been marked as deleted prior to being filtered, then return immediately as we don't want to apply filter actions to deleted messages. svn path=/trunk/; revision=6094
Diffstat (limited to 'filter/filter-driver.c')
-rw-r--r--filter/filter-driver.c205
1 files changed, 121 insertions, 84 deletions
diff --git a/filter/filter-driver.c b/filter/filter-driver.c
index f4863605a2..d1f132e428 100644
--- a/filter/filter-driver.c
+++ b/filter/filter-driver.c
@@ -86,6 +86,7 @@ static int close_folders (FilterDriver *d);
static ESExpResult *do_delete (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
static ESExpResult *mark_forward (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
static ESExpResult *do_copy (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
+static ESExpResult *do_move (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
static ESExpResult *do_stop (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
static ESExpResult *do_colour (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
static ESExpResult *do_score (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *);
@@ -99,7 +100,8 @@ static struct {
} symbols[] = {
{ "delete", (ESExpFunc *) do_delete, 0 },
{ "forward-to", (ESExpFunc *) mark_forward, 0 },
- { "copy-to", (ESExpFunc *) do_copy, 0 },
+ { "copy-to", (ESExpFunc *) do_copy, 0 },
+ { "move-to", (ESExpFunc *) do_move, 0 },
{ "stop", (ESExpFunc *) do_stop, 0 },
{ "set-colour", (ESExpFunc *) do_colour, 0 },
{ "set-score", (ESExpFunc *) do_score, 0 }
@@ -229,38 +231,40 @@ filter_driver_new (FilterContext *context, FilterGetFolderFunc get_folder, void
void
-filter_driver_set_status_func(FilterDriver *d, FDStatusFunc *func, void *data)
+filter_driver_set_status_func (FilterDriver *d, FDStatusFunc *func, void *data)
{
struct _FilterDriverPrivate *p = _PRIVATE (d);
-
+
p->statusfunc = func;
p->statusdata = data;
}
void
-filter_driver_set_default_folder(FilterDriver *d, CamelFolder *def)
+filter_driver_set_default_folder (FilterDriver *d, CamelFolder *def)
{
struct _FilterDriverPrivate *p = _PRIVATE (d);
-
+
if (p->defaultfolder)
- camel_object_unref((CamelObject *)p->defaultfolder);
+ camel_object_unref (CAMEL_OBJECT (p->defaultfolder));
+
p->defaultfolder = def;
+
if (p->defaultfolder)
- camel_object_ref((CamelObject *)p->defaultfolder);
+ camel_object_ref (CAMEL_OBJECT (p->defaultfolder));
}
static void
-report_status(FilterDriver *driver, enum filter_status_t status, const char *desc, ...)
+report_status (FilterDriver *driver, enum filter_status_t status, const char *desc, ...)
{
struct _FilterDriverPrivate *p = _PRIVATE (driver);
va_list ap;
char *str;
-
+
if (p->statusfunc) {
- va_start(ap, desc);
- str = g_strdup_vprintf(desc, ap);
- p->statusfunc(driver, status, str, p->message, p->statusdata);
- g_free(str);
+ va_start (ap, desc);
+ str = g_strdup_vprintf (desc, ap);
+ p->statusfunc (driver, status, str, p->message, p->statusdata);
+ g_free (str);
}
}
@@ -288,8 +292,9 @@ 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");
-
+ p->info->flags = p->info->flags | CAMEL_MESSAGE_DELETED;
+ report_status (driver, FILTER_STATUS_ACTION, "Delete");
+
return NULL;
}
@@ -300,7 +305,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");
+ report_status (driver, FILTER_STATUS_ACTION, "Forward");
return NULL;
}
@@ -315,7 +320,7 @@ do_copy (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d
p->copied = TRUE;
for (i = 0; i < argc; i++) {
if (argv[i]->type == ESEXP_RES_STRING) {
- /* open folders we intent to copy to */
+ /* open folders we intent to copy to */
char *folder = argv[i]->value.string;
CamelFolder *outbox;
@@ -325,7 +330,37 @@ do_copy (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d
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);
+ report_status (driver, FILTER_STATUS_ACTION, "Copy to folder %s", outbox->full_name);
+ mail_tool_camel_lock_down ();
+ }
+ }
+
+ return NULL;
+}
+
+static ESExpResult *
+do_move (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *driver)
+{
+ struct _FilterDriverPrivate *p = _PRIVATE (driver);
+ int i;
+
+ d(fprintf (stderr, "moving message...\n"));
+ p->copied = TRUE;
+ p->deleted = TRUE; /* a 'move' is a copy & delete */
+ p->info->flags = p->info->flags | CAMEL_MESSAGE_DELETED;
+ for (i = 0; i < argc; i++) {
+ if (argv[i]->type == ESEXP_RES_STRING) {
+ /* open folders we intent to move to */
+ char *folder = argv[i]->value.string;
+ CamelFolder *outbox;
+
+ outbox = open_folder (driver, folder);
+ if (!outbox)
+ 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);
mail_tool_camel_lock_down ();
}
}
@@ -338,7 +373,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");
+ report_status (driver, FILTER_STATUS_ACTION, "Stopped processing");
d(fprintf (stderr, "terminating message processing\n"));
p->terminated = TRUE;
@@ -353,7 +388,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);
+ report_status (driver, FILTER_STATUS_ACTION, "Set colour to %s", argv[0]->value.string);
}
return NULL;
@@ -370,7 +405,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);
+ report_status (driver, FILTER_STATUS_ACTION, "Set score to %d", argv[0]->value.number);
g_free (value);
}
@@ -439,28 +474,29 @@ free_key (gpointer key, gpointer value, gpointer user_data)
void
-filter_driver_status_log(FilterDriver *driver, enum filter_status_t status, const char *desc, CamelMimeMessage *msg, void *data)
+filter_driver_status_log (FilterDriver *driver, enum filter_status_t status,
+ const char *desc, CamelMimeMessage *msg, void *data)
{
FILE *out = data;
-
+
switch(status) {
case FILTER_STATUS_END: {
/* write log header */
time_t t;
char date[50];
- 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, msg?camel_mime_message_get_from(msg):"unknown",
- msg?camel_mime_message_get_subject(msg):"", date);
+ 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, msg ? camel_mime_message_get_from (msg) : "unknown",
+ msg ? camel_mime_message_get_subject (msg) : "", date);
break;
}
case FILTER_STATUS_START:
- fprintf(out, "\n");
+ fprintf (out, "\n");
break;
case FILTER_STATUS_ACTION:
- fprintf(out, "Action: %s\n", desc);
+ fprintf (out, "Action: %s\n", desc);
break;
default:
/* nothing else is loggable */
@@ -471,61 +507,61 @@ filter_driver_status_log(FilterDriver *driver, enum filter_status_t status, cons
/* will filter only an mbox - is more efficient as it doesn't need to open the folder through camel directly */
void
-filter_driver_filter_mbox(FilterDriver *driver, const char *mbox, const char *source, CamelException *ex)
+filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *source, CamelException *ex)
{
- CamelMimeParser *mp =NULL;
+ CamelMimeParser *mp = NULL;
int fd = -1;
int i = 0;
struct stat st;
-
- fd = open(mbox, O_RDONLY);
+
+ fd = open (mbox, O_RDONLY);
if (fd == -1) {
- camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, "Unable to open spool folder");
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, "Unable to open spool folder");
goto fail;
}
/* to get the filesize */
- fstat(fd, &st);
-
- mp = camel_mime_parser_new();
- camel_mime_parser_scan_from(mp, TRUE);
- if (camel_mime_parser_init_with_fd(mp, fd) == -1) {
- camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, "Unable to process spool folder");
+ fstat (fd, &st);
+
+ mp = camel_mime_parser_new ();
+ camel_mime_parser_scan_from (mp, TRUE);
+ if (camel_mime_parser_init_with_fd (mp, fd) == -1) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, "Unable to process spool folder");
goto fail;
}
fd = -1;
- while (camel_mime_parser_step(mp, 0, 0) == HSCAN_FROM) {
+ while (camel_mime_parser_step (mp, 0, 0) == HSCAN_FROM) {
CamelMimeMessage *msg;
int pc;
-
- pc = camel_mime_parser_tell(mp) * 100 / st.st_size;
- report_status(driver, FILTER_STATUS_START, "Getting message %d (%d%% of file)", i, pc);
-
- msg = camel_mime_message_new();
- if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp) == -1) {
- report_status(driver, FILTER_STATUS_END, "Failed message %d", i);
- camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, "Cannot open message");
- camel_object_unref((CamelObject *)msg);
+
+ pc = camel_mime_parser_tell (mp) * 100 / st.st_size;
+ report_status (driver, FILTER_STATUS_START, "Getting message %d (%d%% of file)", i, pc);
+
+ msg = camel_mime_message_new ();
+ if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg), mp) == -1) {
+ report_status (driver, FILTER_STATUS_END, "Failed message %d", i);
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, "Cannot open message");
+ camel_object_unref (CAMEL_OBJECT (msg));
goto fail;
}
-
- filter_driver_filter_message(driver, msg, NULL, source, ex);
- camel_object_unref((CamelObject *)msg);
- if (camel_exception_is_set(ex)) {
- report_status(driver, FILTER_STATUS_END, "Failed message %d", i);
+
+ filter_driver_filter_message (driver, msg, NULL, source, ex);
+ camel_object_unref (CAMEL_OBJECT (msg));
+ if (camel_exception_is_set (ex)) {
+ report_status (driver, FILTER_STATUS_END, "Failed message %d", i);
goto fail;
}
-
- report_status(driver, FILTER_STATUS_END, "Finished message %d", i);
+
+ report_status (driver, FILTER_STATUS_END, "Finished message %d", i);
i++;
-
+
/* skip over the FROM_END state */
- camel_mime_parser_step(mp, 0, 0);
+ camel_mime_parser_step (mp, 0, 0);
}
fail:
if (fd != -1)
- close(fd);
+ close (fd);
if (mp)
- camel_object_unref((CamelObject *)mp);
+ camel_object_unref (CAMEL_OBJECT (mp));
}
/* will filter a folder */
@@ -574,7 +610,7 @@ filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const ch
camel_folder_free_uids (folder, uids);
}
-gboolean
+void
filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info,
const char *source, CamelException *ex)
{
@@ -583,18 +619,21 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C
GString *fsearch, *faction;
FilterFilter *rule;
int freeinfo = FALSE;
-
+
if (info == NULL) {
- struct _header_raw *h = CAMEL_MIME_PART(message)->headers;
-
- info = g_malloc0(sizeof(*info));
+ struct _header_raw *h = CAMEL_MIME_PART (message)->headers;
+
+ info = g_new0 (CamelMessageInfo, 1);
freeinfo = TRUE;
- info->subject = camel_folder_summary_format_string(h, "subject");
- info->from = camel_folder_summary_format_address(h, "from");
- info->to = camel_folder_summary_format_address(h, "to");
- info->cc = camel_folder_summary_format_address(h, "cc");
+ info->subject = camel_folder_summary_format_string (h, "subject");
+ info->from = camel_folder_summary_format_address (h, "from");
+ info->to = camel_folder_summary_format_address (h, "to");
+ info->cc = camel_folder_summary_format_address (h, "cc");
+ } else {
+ if (info->flags & CAMEL_MESSAGE_DELETED)
+ return;
}
-
+
p->ex = ex;
p->terminated = FALSE;
p->deleted = FALSE;
@@ -618,7 +657,7 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C
d(fprintf (stderr, "applying rule %s\n action %s\n", fsearch->str, faction->str));
mail_tool_camel_lock_up ();
- matched = filter_message_search (p->message, p->info, fsearch->str, p->ex);
+ matched = filter_message_search (p->message, p->info, source, fsearch->str, p->ex);
mail_tool_camel_lock_down ();
if (matched) {
@@ -640,21 +679,19 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C
if (!p->deleted && !p->copied && p->defaultfolder) {
/* copy it to the default inbox */
- report_status(driver, FILTER_STATUS_ACTION, "Copy to default folder");
+ report_status (driver, FILTER_STATUS_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 ();
}
-
+
if (freeinfo) {
- camel_flag_list_free(&info->user_flags);
- camel_tag_list_free(&info->user_tags);
- g_free(info->subject);
- g_free(info->from);
- g_free(info->to);
- g_free(info->cc);
- g_free(info);
+ camel_flag_list_free (&info->user_flags);
+ camel_tag_list_free (&info->user_tags);
+ g_free (info->subject);
+ g_free (info->from);
+ g_free (info->to);
+ g_free (info->cc);
+ g_free (info);
}
-
- return p->copied;
}