2006-02-06 [colin] 2.0.0cvs21
authorColin Leroy <colin@colino.net>
Mon, 6 Feb 2006 18:02:18 +0000 (18:02 +0000)
committerColin Leroy <colin@colino.net>
Mon, 6 Feb 2006 18:02:18 +0000 (18:02 +0000)
* src/imap.c
Put the added file directly to cache if possible (will work
with next libetpan)
* src/filtering.c
* src/filtering.h
* src/inc.c
* src/folder.c
* src/mbox.c
Move and copy filtered messages by batches instead of one
by one - faster on IMAP
* src/procmsg.c
Add a function that'll possibly be useful later

ChangeLog
PATCHSETS
configure.ac
src/filtering.c
src/filtering.h
src/folder.c
src/imap.c
src/inc.c
src/mbox.c
src/procmsg.c

index 8b306e6..08118d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-02-06 [colin]     2.0.0cvs21
+
+       * src/imap.c
+               Put the added file directly to cache if possible (will work
+               with next libetpan)
+       * src/filtering.c
+       * src/filtering.h
+       * src/inc.c
+       * src/folder.c
+       * src/mbox.c
+               Move and copy filtered messages by batches instead of one
+               by one - faster on IMAP
+       * src/procmsg.c
+               Add a function that'll possibly be useful later
+
 2006-02-06 [colin]     2.0.0cvs20
 
        * src/addressbook.c
index 2ab8084..5a23b14 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/gtk/icon_legend.c;  ) > 2.0.0cvs18.patchset
 ( cvs diff -u -r 1.34.2.16 -r 1.34.2.17 po/it.po;  ) > 2.0.0cvs19.patchset
 ( cvs diff -u -r 1.60.2.47 -r 1.60.2.48 src/addressbook.c;  cvs diff -u -r 1.382.2.234 -r 1.382.2.235 src/compose.c;  cvs diff -u -r 1.207.2.87 -r 1.207.2.88 src/folderview.c;  cvs diff -u -r 1.20.2.10 -r 1.20.2.11 src/folderview.h;  cvs diff -u -r 1.8.2.14 -r 1.8.2.15 src/headerview.c;  cvs diff -u -r 1.96.2.93 -r 1.96.2.94 src/textview.c;  cvs diff -u -r 1.83.2.63 -r 1.83.2.64 src/mimeview.c;  cvs diff -u -r 1.1.2.10 -r 1.1.2.11 src/prefs_message.c;  cvs diff -u -r 1.395.2.163 -r 1.395.2.164 src/summaryview.c;  cvs diff -u -r 1.5.2.19 -r 1.5.2.20 src/gtk/gtkutils.c;  cvs diff -u -r 1.4.2.16 -r 1.4.2.17 src/gtk/gtkutils.h;  ) > 2.0.0cvs20.patchset
+( cvs diff -u -r 1.179.2.91 -r 1.179.2.92 src/imap.c;  cvs diff -u -r 1.60.2.9 -r 1.60.2.10 src/filtering.c;  cvs diff -u -r 1.21.2.4 -r 1.21.2.5 src/filtering.h;  cvs diff -u -r 1.149.2.42 -r 1.149.2.43 src/inc.c;  cvs diff -u -r 1.213.2.78 -r 1.213.2.79 src/folder.c;  cvs diff -u -r 1.28.2.12 -r 1.28.2.13 src/mbox.c;  cvs diff -u -r 1.150.2.50 -r 1.150.2.51 src/procmsg.c;  ) > 2.0.0cvs21.patchset
index 0d2addf..d670cc3 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=20
+EXTRA_VERSION=21
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 1d3617a..10bc193 100644 (file)
@@ -163,6 +163,72 @@ void filteringprop_free(FilteringProp * prop)
        g_free(prop);
 }
 
+/* move and copy messages by batches to be faster on IMAP */
+void filtering_move_and_copy_msgs(GSList *msgs)
+{
+       GSList *messages = g_slist_copy(msgs);
+       FolderItem *last_item = NULL;
+       gboolean is_copy = FALSE, is_move = FALSE;
+       
+       while (messages) {
+               GSList *batch = NULL, *cur;
+               gint found = 0;
+               debug_print("%d messages to filter\n", g_slist_length(messages));
+               for (cur = messages; cur; cur = cur->next) {
+                       MsgInfo *info = (MsgInfo *)cur->data;
+                       if (last_item == NULL) {
+                               last_item = info->to_folder;
+                       }
+                       if (last_item == NULL)
+                               continue;
+                       debug_print("for %s\n", folder_item_get_path(last_item));
+                       if (!is_copy && !is_move) {
+                               if (info->is_copy)
+                                       is_copy = TRUE;
+                               else if (info->is_move)
+                                       is_move = TRUE;
+                       }
+                       found++;
+                       if (info->to_folder == last_item 
+                       &&  info->is_copy == is_copy
+                       &&  info->is_move == is_move) {
+                               batch = g_slist_append(batch, info);
+                       }
+               }
+               if (found == 0) {
+                       debug_print("no more messages to move/copy\n");
+                       break;
+               }
+               for (cur = batch; cur; cur = cur->next) {
+                       MsgInfo *info = (MsgInfo *)cur->data;
+                       messages = g_slist_remove(messages, info);
+               }
+               if (g_slist_length(batch)) {
+                       debug_print("%s %d messages to %s\n",
+                               is_copy?"copying":"moving",
+                               g_slist_length(batch),
+                               folder_item_get_path(last_item));
+                       if (is_copy) {
+                               folder_item_copy_msgs(last_item, batch);
+                       } else if (is_move) {
+                               if (folder_item_move_msgs(last_item, batch) < 0)
+                                       folder_item_move_msgs(
+                                               folder_get_default_inbox(), 
+                                               batch);
+                       }
+                       /* we don't reference the msginfos, because caller will do */
+                       g_slist_free(batch);
+                       batch = NULL;
+               }
+               last_item = NULL;
+               is_copy = FALSE;
+               is_move = FALSE;
+               debug_print("%d messages remaining\n", g_slist_length(messages));
+       }
+       /* we don't reference the msginfos, because caller will do */
+       g_slist_free(messages);
+}
+
 /*
   fitleringaction_apply
   runs the action on one MsgInfo
@@ -187,11 +253,10 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                        return FALSE;
                }
                
-               if (folder_item_move_msg(dest_folder, info) == -1) {
-                       debug_print("*** could not move message\n");
-                       return FALSE;
-               }       
-
+               /* mark message to be moved */          
+               info->is_move = TRUE;
+               info->to_folder = dest_folder;
+               debug_print("set to move to %s\n", folder_item_get_path(dest_folder));
                return TRUE;
 
        case MATCHACTION_COPY:
@@ -204,9 +269,10 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                        return FALSE;
                }
 
-               if (folder_item_copy_msg(dest_folder, info) == -1)
-                       return FALSE;
-
+               /* mark message to be copied */         
+               info->is_copy = TRUE;
+               info->to_folder = dest_folder;
+               debug_print("set to copy to %s\n", folder_item_get_path(dest_folder));
                return TRUE;
 
        case MATCHACTION_DELETE:
index 0ef0df5..96ef179 100644 (file)
@@ -74,7 +74,7 @@ void prefs_filtering_clear_folder(Folder *folder);
 void prefs_filtering_free(GSList *prefs_filtering);
 
 FilteringProp * filteringprop_copy(FilteringProp *src);
-
+void filtering_move_and_copy_msgs(GSList *msglist);
 extern GSList * filtering_rules;
 extern GSList * pre_global_processing;
 extern GSList * post_global_processing;
index 6111078..08f4339 100644 (file)
@@ -1841,7 +1841,7 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
 
        folder_item_update_freeze();
        if (newmsg_list != NULL) {
-               GSList *elem;
+               GSList *elem, *to_filter = NULL;
                int total = g_slist_length(newmsg_list), cur = 0;
                
                if ((filtering == TRUE) &&
@@ -1861,10 +1861,17 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
                            (item->folder->account != NULL) && 
                            (item->folder->account->filter_on_recv) &&
                            procmsg_msginfo_filter(msginfo))
-                               procmsg_msginfo_free(msginfo);
+                               to_filter = g_slist_append(to_filter, msginfo);
                        else
                                exists_list = g_slist_prepend(exists_list, msginfo);
                }
+               filtering_move_and_copy_msgs(to_filter);
+               for (elem = to_filter; elem; elem = g_slist_next(elem)) {
+                       MsgInfo *msginfo = (MsgInfo *)elem->data;
+                       procmsg_msginfo_free(msginfo);
+               }
+
+               g_slist_free(to_filter);
                g_slist_free(newmsg_list);
 
                statusbar_progress_all(0,0,0);
index c428a0b..f637763 100644 (file)
@@ -932,7 +932,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                make_dir_hier(path);
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
        g_free(path);
-
+       debug_print("trying to fetch cached %s\n", filename);
        if (is_file_exist(filename)) {
                /* see whether the local file represents the whole message
                 * or not. As the IMAP server reports size with \r chars,
@@ -1098,6 +1098,24 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                        statusbar_progress_all(0,0,0);
                        statusbar_pop_all();
                        return -1;
+               } else {
+                       debug_print("appended new message as %d\n", new_uid);
+                       /* put the local file in the imapcache, so that we don't
+                        * have to fetch it back later. */
+                       if (new_uid > 0) {
+                               gchar *cache_path = folder_item_get_path(dest);
+                               if (!is_dir_exist(cache_path))
+                                       make_dir_hier(cache_path);
+                               if (is_dir_exist(cache_path)) {
+                                       gchar *cache_file = g_strconcat(
+                                               cache_path, G_DIR_SEPARATOR_S, 
+                                               itos(new_uid), NULL);
+                                       copy_file(real_file, cache_file, TRUE);
+                                       debug_print("copied to cache: %s\n", cache_file);
+                                       g_free(cache_file);
+                               }
+                               g_free(cache_path);
+                       }
                }
 
                if (relation != NULL)
index 36a66b4..a550e1f 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -637,6 +637,11 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                        if (!pop3_session->ac_prefs->filter_on_recv || 
                            !procmsg_msginfo_filter(msginfo))
                                folder_item_move_msg(inbox, msginfo);
+               }
+               filtering_move_and_copy_msgs(msglist);
+               for(msglist_element = msglist; msglist_element != NULL; 
+                   msglist_element = msglist_element->next) {
+                       MsgInfo *msginfo = (MsgInfo *)msglist_element->data;
                        procmsg_msginfo_free(msginfo);
                }
                folder_item_update_thaw();
index 4f438a8..ec6eb86 100644 (file)
@@ -67,6 +67,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
        gint lines;
        MsgInfo *msginfo;
        gboolean more;
+       GSList *to_filter = NULL, *cur;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(mbox != NULL, -1);
@@ -210,13 +211,21 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
                }
 
                msginfo = folder_item_get_msginfo(dropfolder, msgnum);
-                if (!apply_filter || !procmsg_msginfo_filter(msginfo))
+                if (!apply_filter || !procmsg_msginfo_filter(msginfo)) {
                        folder_item_move_msg(dest, msginfo);
-               procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(msginfo);
+               } else
+                       to_filter = g_slist_append(to_filter, msginfo);
 
                msgs++;
        } while (more);
 
+       filtering_move_and_copy_msgs(to_filter);
+       for (cur = to_filter; cur; cur = g_slist_next(cur)) {
+               MsgInfo *info = (MsgInfo *)cur->data;
+               procmsg_msginfo_free(info);
+       }
+
        folder_item_update_thaw();
        
        g_free(tmp_file);
index 0e0b489..0ee9100 100644 (file)
@@ -980,8 +980,54 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
        fclose(outfp);
        fclose(fp);
        return 0;
+}
+#if 0
+gchar *procmsg_add_special_headers(const gchar *in, FolderItem *item)
+{
+       gchar *out = get_tmp_file();
+       FILE *fp = NULL;
+       PrefsAccount *account = NULL;
+       if (out == NULL)
+               return NULL;
+
+       fp = fopen(out, "wb");
+       if (fp == NULL) {
+               g_free(out);
+               return NULL;
+       }
+
+       if (item && item->prefs && item->prefs->enable_default_account)
+               account = account_find_from_id(item->prefs->default_account);
+
+       if (!account) account = cur_account;
 
+       if (!account) {
+               fclose(fp);
+               g_free(out);
+               return NULL;
+       }
+
+       fprintf(fp, "X-Sylpheed-Account-Id:%d\n", account->account_id);
+       fprintf(fp, "S:%s\n", account->address);
+       if (item && item->prefs && item->prefs->save_copy_to_folder) {
+               gchar *folderidentifier;
+
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
+               folderidentifier = folder_item_get_identifier(item);
+               fprintf(fp, "SCF:%s\n", folderidentifier);
+               g_free(folderidentifier);
+       } else if (account_get_special_folder(account, F_OUTBOX)) {
+               gchar *folderidentifier = folder_item_get_identifier(account_get_special_folder
+                                 (compose->account, F_OUTBOX));
+               fprintf(fp, "SCF:%s\n", folderidentifier);
+               g_free(folderidentifier);
+       }
+
+       fprintf(fp, "\n");
+       fclose(fp);
+       return out;
 }
+#endif
 gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                            gboolean is_queued)
 {