aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-ops.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-10-12 21:48:36 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-10-12 21:48:36 +0800
commit80237e0c26dd375b0269dc2099d49fc3cd50a4f2 (patch)
tree8083431b7966dc91fd725b599d1366009bbc518e /mail/mail-ops.c
parent1deca02b41aae9bf2632ea1420cc900fcf41531d (diff)
downloadgsoc2013-evolution-80237e0c26dd375b0269dc2099d49fc3cd50a4f2.tar.gz
gsoc2013-evolution-80237e0c26dd375b0269dc2099d49fc3cd50a4f2.tar.zst
gsoc2013-evolution-80237e0c26dd375b0269dc2099d49fc3cd50a4f2.zip
Duh, fix the test for the folder name, strstr != strcmp is it.
2000-10-12 Not Zed <NotZed@HelixCode.com> * message-list.c (message_list_setup_etable): Duh, fix the test for the folder name, strstr != strcmp is it. 2000-10-10 Not Zed <NotZed@HelixCode.com> * message-list.c (folder_to_cachename): Removed, changed callers to use mail_config_folder_to_cachename instead. * mail-config.c (mail_config_folder_to_cachename): New utility function to get a cache name for a folder. * mail-tools.c (mail_tool_do_movemail): Changed to return the path to the mbox, rather than opening a folder of it. * mail-ops.c (mail_incorporate_messages): Dont bother making the pseudo messageinfo, filder_driver_filter_message will do it for us. (report_status): Callback to report status of filtering operation. (do_fetch_mail): Changed significantly - for the api changes to the filtering system. Also now incorporates a mailbox file directly, without having to import it into a camel folder first. (mail_incorporate_messages): Removed entirely, no longer needed. * mail-vfolder.c (vfolder_refresh): Fix for context api changes. (vfolder_uri_to_folder): Likewise. * folder-browser-factory.c (create_ondemand_hooks): Changed for api changes. Also only adds demand filters to the menu (fixed a small logic bug). svn path=/trunk/; revision=5883
Diffstat (limited to 'mail/mail-ops.c')
-rw-r--r--mail/mail-ops.c207
1 files changed, 160 insertions, 47 deletions
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index 4a784d3688..d74f343134 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -98,6 +98,8 @@ mail_load_evolution_rule_context ()
return fc;
}
+#if 0
+/* to be removed */
static void
mail_incorporate_messages (CamelFolder *folder,
fetch_mail_input_t *input,
@@ -158,7 +160,7 @@ mail_incorporate_messages (CamelFolder *folder,
/* get/filter the new messages */
for (i = 0; i < uids->len; i++) {
CamelMimeMessage *message;
- CamelMessageInfo *info;
+ const CamelMessageInfo *info;
gboolean free_info;
gboolean last_message = (i+1 == uids->len);
time_t now;
@@ -176,19 +178,13 @@ mail_incorporate_messages (CamelFolder *folder,
if (camel_exception_is_set (ex))
continue;
- if (camel_folder_has_summary_capability (folder)) {
- info = (CamelMessageInfo *) camel_folder_get_message_info (folder, uids->pdata[i]);
- free_info = FALSE;
- } else {
- info = g_new0 (CamelMessageInfo, 1);
- free_info = TRUE;
- }
-
- filter_driver_run (filter, message, info, input->destination,
- FILTER_SOURCE_INCOMING, logfile, ex);
+ if (camel_folder_has_summary_capability (folder))
+ info = camel_folder_get_message_info (folder, uids->pdata[i]);
+ else
+ info = NULL;
- if (free_info)
- camel_message_info_free (info);
+ filter_driver_filter_message(filter, message, info, input->destination,
+ FILTER_SOURCE_INCOMING, logfile, ex);
/* we don't care if it was filtered or not here because no matter
what it's been copied to at least 1 folder - even if it's just
@@ -228,14 +224,40 @@ mail_incorporate_messages (CamelFolder *folder,
data->empty = FALSE;
}
+#endif
+
+static void
+mail_op_report_status(FilterDriver *driver, enum filter_status_t status, const char *desc, CamelMimeMessage *msg, void *data)
+{
+ printf("reporting status: %s\n", desc);
+
+ /* FIXME: make it work */
+ switch(status) {
+ case FILTER_STATUS_START:
+ mail_op_set_message (_("Retrieving messages : %s"), desc);
+ break;
+ case FILTER_STATUS_END:
+ break;
+ case FILTER_STATUS_ACTION:
+ break;
+ default:
+ break;
+ }
+
+ /* use the 'standard' logging function, data is already the fd */
+ if (data)
+ filter_driver_status_log(driver, status, desc, msg, data);
+}
static void
do_fetch_mail (gpointer in_data, gpointer op_data, CamelException *ex)
{
fetch_mail_input_t *input = (fetch_mail_input_t *) in_data;
fetch_mail_data_t *data = (fetch_mail_data_t *) op_data;
- CamelFolder *folder = NULL;
-
+ FilterContext *fc;
+ FilterDriver *filter;
+ FILE *logfile = NULL;
+
/* If using IMAP, don't do anything... */
if (!strncmp (input->source_url, "imap:", 5)) {
data->empty = FALSE;
@@ -248,31 +270,82 @@ do_fetch_mail (gpointer in_data, gpointer op_data, CamelException *ex)
if (input->destination == NULL)
return;
}
-
- if (!strncmp (input->source_url, "mbox:", 5))
- folder = mail_tool_do_movemail (input->source_url, ex);
- else
- folder = mail_tool_get_inbox (input->source_url, ex);
-
- if (folder == NULL) {
- /* This happens with an IMAP source and on error
- * and on "no new mail"
- */
- camel_object_unref (CAMEL_OBJECT (input->destination));
- input->destination = NULL;
- data->empty = TRUE;
- return;
+
+ /* setup filter driver */
+ fc = mail_load_evolution_rule_context();
+ filter = filter_driver_new(fc, mail_tool_filter_get_folder_func, 0);
+ filter_driver_set_default_folder(filter, input->destination);
+
+ if (TRUE /* perform_logging */) {
+ char *filename = g_strdup_printf ("%s/evolution-filter-log", evolution_dir);
+ logfile = fopen (filename, "a+");
+ g_free (filename);
}
-
+ filter_driver_set_status_func(filter, mail_op_report_status, logfile);
+
+ /* why on earth we 'up' a lock to get it, ... */
mail_tool_camel_lock_up ();
- if (camel_folder_get_message_count (folder) == 0)
- data->empty = TRUE;
- else
- mail_incorporate_messages (folder, input, data, ex);
+
+ camel_folder_freeze(input->destination);
+
+ if (!strncmp (input->source_url, "mbox:", 5)) {
+ char *path = mail_tool_do_movemail (input->source_url, ex);
+
+ if (path && !camel_exception_is_set(ex)) {
+ filter_driver_filter_mbox(filter, path, FILTER_SOURCE_INCOMING, ex);
+
+ /* ok? zap the output file */
+ if (!camel_exception_is_set(ex)) {
+ unlink(path);
+ }
+ }
+ g_free(path);
+ } else {
+ CamelFolder *folder = mail_tool_get_inbox (input->source_url, ex);
+
+ if (folder) {
+ if (camel_folder_get_message_count (folder) > 0) {
+ GPtrArray *uids, *new_uids = NULL;
+ CamelUIDCache *cache = NULL;
+
+ uids = camel_folder_get_uids(folder);
+ if (input->keep_on_server) {
+ char *cachename = mail_config_folder_to_cachename(folder, "cache-");
+
+ cache = camel_uid_cache_new(cachename);
+ if (cache) {
+ new_uids = camel_uid_cache_get_new_uids(cache, uids);
+ camel_folder_free_uids(folder, uids);
+ uids = new_uids;
+ }
+ }
+ filter_driver_filter_folder(filter, folder, FILTER_SOURCE_INCOMING, uids, !input->keep_on_server, ex);
+ if (new_uids) {
+ camel_uid_cache_free_uids(new_uids);
+ if (!camel_exception_is_set(ex))
+ camel_uid_cache_save(cache);
+ camel_uid_cache_destroy(cache);
+ } else {
+ camel_folder_free_uids(folder, uids);
+ }
+ } else {
+ data->empty = TRUE;
+ }
+ camel_object_unref (CAMEL_OBJECT (folder));
+ } else {
+ data->empty = TRUE;
+ }
+ }
+
+ if (logfile)
+ fclose(logfile);
+
+ camel_folder_thaw(input->destination);
mail_tool_camel_lock_down ();
-
- camel_object_unref (CAMEL_OBJECT (folder));
+
+ /*camel_object_unref (CAMEL_OBJECT (input->destination));*/
+ gtk_object_unref((GtkObject *)filter);
}
static void
@@ -328,6 +401,9 @@ mail_do_fetch_mail (const gchar *source_url, gboolean keep_on_server,
/* ** FILTER ON DEMAND ********************************************************** */
+/* why do we have this separate code, it is basically a copy of the code above,
+ should be consolidated */
+
typedef struct filter_ondemand_input_s
{
FilterContext *context;
@@ -360,20 +436,56 @@ static void
do_filter_ondemand (gpointer in_data, gpointer op_data, CamelException *ex)
{
filter_ondemand_input_t *input = (filter_ondemand_input_t *) in_data;
+ FilterDriver *driver;
+ GPtrArray *uids, *new_uids;
+ char *filename;
+ FILE *logfile = NULL;
+ int i;
mail_tool_camel_lock_up ();
- if (camel_folder_get_message_count (input->source) != 0) {
- FilterDriver *driver;
- GPtrArray *uids;
- char *filename;
- FILE *logfile;
- int i;
-
- uids = camel_folder_get_uids (input->source);
-
- camel_folder_freeze (input->source);
+ if (camel_folder_get_message_count (input->source) == 0) {
+ mail_tool_camel_lock_down();
+ return;
+ }
+
+ /* setup filter driver */
+ driver = filter_driver_new (input->context, mail_tool_filter_get_folder_func, NULL);
+ /* -- we want no default destination this time */
+ if (TRUE /* perform_logging */) {
+ filename = g_strdup_printf ("%s/evolution-filter-log", evolution_dir);
+ logfile = fopen (filename, "a+");
+ g_free (filename);
+ }
+ filter_driver_set_status_func(driver, mail_op_report_status, logfile);
+ /* build the uid list - all uid's not deleted already */
+ uids = camel_folder_get_uids (input->source);
+ new_uids = g_ptr_array_new();
+ for (i=0;i<uids->len;i++) {
+ CamelMessageInfo *info = camel_folder_get_message_info(input->source, uids->pdata[i]);
+ if (info && (info->flags & CAMEL_MESSAGE_DELETED) == 0) {
+ g_ptr_array_add(new_uids, uids->pdata[i]);
+ }
+ }
+
+ /* run the filter */
+ filter_driver_filter_folder(driver, input->source, FILTER_SOURCE_DEMAND, new_uids, TRUE, ex);
+
+ camel_folder_free_uids (input->source, uids);
+ g_ptr_array_free(new_uids, TRUE);
+
+ if (logfile)
+ fclose(logfile);
+
+ gtk_object_unref((GtkObject *)driver);
+ mail_tool_camel_lock_down ();
+}
+
+#if 0
+/* to be removed, old version */
+{
+ {
+
- driver = filter_driver_new (input->context, mail_tool_filter_get_folder_func, NULL);
/* FIXME: find out if we want to log or not - config option */
if (TRUE /* perform_logging */) {
@@ -442,6 +554,7 @@ do_filter_ondemand (gpointer in_data, gpointer op_data, CamelException *ex)
}
mail_tool_camel_lock_down ();
}
+#endif
static void
cleanup_filter_ondemand (gpointer in_data, gpointer op_data, CamelException *ex)