diff -u -r evolution-0.12.99.orig/camel/camel-filter-driver.c evolution-0.12.99/camel/camel-filter-driver.c --- evolution-0.12.99.orig/camel/camel-filter-driver.c Mon Jul 23 09:59:17 2001 +++ evolution-0.12.99/camel/camel-filter-driver.c Thu Aug 9 14:35:10 2001 @@ -25,10 +25,12 @@ #include #endif +#include #include #include #include +#include /* for gnome_execute stuff */ #include "camel-filter-driver.h" #include "camel-filter-search.h" @@ -87,6 +89,10 @@ const char *uid; /* message uid */ CamelFolder *source; /* message source folder */ + /* two lists to handle play-sound and execute-command filter actions */ + GSList *pending_commands; + GSList *pending_sounds; + FILE *logfile; /* log file */ EDList rules; /* list of _filter_rule structs */ @@ -99,9 +105,9 @@ #define _PRIVATE(o) (((CamelFilterDriver *)(o))->priv) -static void camel_filter_driver_class_init (CamelFilterDriverClass *klass); -static void camel_filter_driver_init (CamelFilterDriver *obj); -static void camel_filter_driver_finalise (CamelObject *obj); +static void camel_filter_driver_class_init (CamelFilterDriverClass *klass); +static void camel_filter_driver_init (CamelFilterDriver *obj); +static void camel_filter_driver_finalise (CamelObject *obj); static void camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_t status, const char *desc, ...); @@ -116,6 +122,8 @@ static ESExpResult *do_colour (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_score (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *do_add_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *do_add_sound (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); /* these are our filter actions - each must have a callback */ static struct { @@ -124,14 +132,16 @@ int type; /* set to 1 if a function can perform shortcut evaluation, or doesn't execute everything, 0 otherwise */ } symbols[] = { - { "delete", (ESExpFunc *) do_delete, 0 }, - { "forward-to", (ESExpFunc *) mark_forward, 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 }, - { "set-system-flag", (ESExpFunc *) do_flag, 0 } + { "delete", (ESExpFunc *) do_delete, 0 }, + { "forward-to", (ESExpFunc *) mark_forward, 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 }, + { "set-system-flag", (ESExpFunc *) do_flag, 0 }, + { "execute-command", (ESExpFunc *) do_add_command, 0 }, + { "play-sound", (ESExpFunc *) do_add_sound, 0 } }; static CamelObjectClass *camel_filter_driver_parent; @@ -185,6 +195,63 @@ p->globals = g_hash_table_new (g_str_hash, g_str_equal); p->folders = g_hash_table_new (g_str_hash, g_str_equal); + + p->pending_commands = NULL; + p->pending_sounds = NULL; +} + +void +camel_filter_driver_handle_pending_actions(CamelFilterDriver *driver) +{ + /* execute pending commands and play pending sounds */ + + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + + g_slist_foreach(p->pending_commands,camel_filter_driver_execute_pending_commands,driver); + g_slist_foreach(p->pending_sounds,camel_filter_driver_play_pending_sounds,driver); + g_slist_free(p->pending_commands); + g_slist_free(p->pending_sounds); + p->pending_commands = NULL; + p->pending_sounds = NULL; + +} + + +void +camel_filter_driver_execute_pending_commands (gpointer list_data, gpointer user_data) +{ + CamelFilterDriver *d = (CamelFilterDriver*)user_data; + char* command = (char*)list_data; + int pid = 0; + + pid = gnome_execute_shell(NULL,command); + if(pid == -1){ + camel_filter_driver_log (d, FILTER_LOG_ACTION, + "Executing Command: [%s] (childID=%d, errno=%d [%s])", + command,pid,errno,sys_errlist[errno]); + } + else{ + camel_filter_driver_log (d, FILTER_LOG_ACTION, + "Executing Command: [%s] (childID=%d)",command,pid); + } + + g_free(command); +} + + +void +camel_filter_driver_play_pending_sounds (gpointer list_data, gpointer user_data) +{ + CamelFilterDriver *d = (CamelFilterDriver*)user_data; + char* sound = (char*)list_data; + + gnome_sound_init(NULL); + gnome_sound_play((char*) sound); + gnome_sound_shutdown(); + camel_filter_driver_log (d, FILTER_LOG_ACTION, + "Playing Sound: [%s]",sound); + + g_free(sound); } static void @@ -194,6 +261,14 @@ g_free (value); } +static int +compare_slist_strings (gconstpointer list_value, gconstpointer user_value) +{ + /* this function is used by g_slist_find_custom() */ + /* return 0 if the strings are equal. 1 otherwise */ + return (strcmp((const char*)list_value, (const char*)user_value)); +} + static void camel_filter_driver_finalise (CamelObject *obj) { @@ -489,6 +564,85 @@ camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Set %s flag", argv[0]->value.string); } + return NULL; +} + + +static ESExpResult * +do_add_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +{ + /* this function adds a sound to execute to p->pending_commands + * after all filtering is done, these commands will be executed in + * camel_filter_execute_pending_commands(). the GSList*->data + * malloc'ed here will be free'd there. */ + + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + int per_retrieval = 0; /* 1 means that we only add this command to the list once */ + char *cmd_string = g_strdup(argv[0]->value.string); + + /* see if we're PerRetrieval or PerMessage */ + if(!strcmp(argv[1]->value.string,"PerRetrieval")){ + per_retrieval = 1; + } + + d(fprintf (stderr, "adding command [%s]\n",cmd_string)); + if(per_retrieval == 0){ + /* we're per-message, so just tack ourselves onto the end of the list */ + p->pending_commands = g_slist_append(p->pending_commands, cmd_string); + camel_filter_driver_log (driver, FILTER_LOG_ACTION, + "Added Per-Message Command: [%s]", cmd_string); + } + else{ + /* this is per-retrieval, so we check look for the string in the + * current list of pending commands. if we find it, we do nothing. + * if it's not there, we append it */ + + if(g_slist_find_custom(p->pending_commands, cmd_string, compare_slist_strings) == NULL){ + p->pending_commands = g_slist_append(p->pending_commands, cmd_string); + camel_filter_driver_log (driver, FILTER_LOG_ACTION, + "Added Per-Retrieval Command: [%s]", cmd_string); + } + } + + return NULL; +} + +static ESExpResult * +do_add_sound (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +{ + /* this function adds a sound to execute to p->pending_sounds + * after all filtering is done, these sounds will be played in + * camel_filter_play_pending_sounds(). the GSList*->data + * malloc'ed here will be free'd there. */ + + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + int per_retrieval = 0; /* 1 means that we only add this sound to the list once */ + char *sound_string = g_strdup(argv[0]->value.string); + + /* see if we're PerRetrieval or PerMessage */ + if(!strcmp(argv[1]->value.string,"PerRetrieval")){ + per_retrieval = 1; + } + + d(fprintf (stderr, "adding sound [%s]\n",sound_string)); + if(per_retrieval == 0){ + /* we're per-message, so just tack ourselves onto the end of the list */ + p->pending_sounds = g_slist_append(p->pending_sounds, sound_string); + camel_filter_driver_log (driver, FILTER_LOG_ACTION, + "Added Per-Message Sound: [%s]", sound_string); + } + else{ + /* this is per-retrieval, so we check look for the string in the + * current list of pending commands. if we find it, we do nothing. + * if it's not there, we append it */ + + if(g_slist_find_custom(p->pending_sounds, sound_string, compare_slist_strings) == NULL){ + p->pending_sounds = g_slist_append(p->pending_sounds, sound_string); + camel_filter_driver_log (driver, FILTER_LOG_ACTION, + "Added Per-Retrieval Sound: [%s]", sound_string); + } + } + return NULL; } diff -u -r evolution-0.12.99.orig/camel/camel-filter-driver.h evolution-0.12.99/camel/camel-filter-driver.h --- evolution-0.12.99.orig/camel/camel-filter-driver.h Fri Jul 13 08:06:13 2001 +++ evolution-0.12.99/camel/camel-filter-driver.h Thu Aug 9 14:35:10 2001 @@ -72,6 +72,10 @@ void camel_filter_driver_add_rule (CamelFilterDriver *d, const char *name, const char *match, const char *action); +void camel_filter_driver_handle_pending_actions (CamelFilterDriver *driver); +void camel_filter_driver_execute_pending_commands (gpointer list_data, gpointer user_data); +void camel_filter_driver_play_pending_sounds (gpointer list_data, gpointer user_data); + /*void camel_filter_driver_set_global(CamelFilterDriver *, const char *name, const char *value);*/ int camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage *message, diff -u -r evolution-0.12.99.orig/filter/filtertypes.xml evolution-0.12.99/filter/filtertypes.xml --- evolution-0.12.99.orig/filter/filtertypes.xml Fri Jul 20 14:22:31 2001 +++ evolution-0.12.99/filter/filtertypes.xml Thu Aug 9 14:34:41 2001 @@ -624,5 +624,31 @@ + + Play Sound + (play-sound ${sound} ${sound_per_xxx}) + + + + + + + + Execute Command + (execute-command ${command} ${command_per_xxx}) + + + + + + diff -u -r evolution-0.12.99.orig/mail/mail-ops.c evolution-0.12.99/mail/mail-ops.c --- evolution-0.12.99.orig/mail/mail-ops.c Thu Aug 2 21:35:06 2001 +++ evolution-0.12.99/mail/mail-ops.c Thu Aug 9 14:34:54 2001 @@ -117,6 +117,7 @@ folder_uids = uids = camel_folder_get_uids (folder); camel_filter_driver_filter_folder (m->driver, folder, m->cache, uids, m->delete, &mm->ex); + camel_filter_driver_handle_pending_actions(m->driver); if (folder_uids) camel_folder_free_uids (folder, folder_uids); @@ -252,6 +253,7 @@ camel_folder_freeze (fm->destination); camel_filter_driver_set_default_folder (fm->driver, fm->destination); camel_filter_driver_filter_mbox (fm->driver, path, m->source_uri, &mm->ex); + camel_filter_driver_handle_pending_actions(fm->driver); camel_folder_thaw (fm->destination); if (!camel_exception_is_set (&mm->ex)) @@ -533,6 +535,7 @@ if (driver) { camel_filter_driver_filter_message (driver, message, info, NULL, NULL, NULL, "", ex); + camel_filter_driver_handle_pending_actions(driver); if (camel_exception_is_set (ex)) { camel_message_info_free (info);