2005-06-12 [colin] 1.9.11cvs60
authorColin Leroy <colin@colino.net>
Sun, 12 Jun 2005 16:51:03 +0000 (16:51 +0000)
committerColin Leroy <colin@colino.net>
Sun, 12 Jun 2005 16:51:03 +0000 (16:51 +0000)
* src/imap.c
Remove flags-processing deferring... Too hard
to get it to work in all cases.

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/imap.c

index 5da7566501625a2f5f17e688c9c0cf03729dcbf1..2f8c4573b6ea9b2cbe245a9085d0e1c9c2f91cad 100644 (file)
@@ -1,3 +1,9 @@
+2005-06-12 [colin]     1.9.11cvs60
+
+       * src/imap.c
+               Remove flags-processing deferring... Too hard
+               to get it to work in all cases.
+
 2005-06-11 [colin]     1.9.11cvs59
 
        * src/imap.c
index 86785ca82215c16cbfebfea9add60116ac2f12bb..3c8a2564dcd4d2df10c6a1037ee2b729ce8137c1 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.179.2.24 -r 1.179.2.25 src/imap.c;  cvs diff -u -r 1.49.2.46 -r 1.49.2.47 src/procmime.c;  cvs diff -u -r 1.11.2.11 -r 1.11.2.12 src/common/smtp.c;  cvs diff -u -r 1.2.2.8 -r 1.2.2.9 src/gtk/inputdialog.c;  ) > 1.9.11cvs57.patchset
 ( cvs diff -u -r 1.179.2.25 -r 1.179.2.26 src/imap.c;  ) > 1.9.11cvs58.patchset
 ( cvs diff -u -r 1.179.2.26 -r 1.179.2.27 src/imap.c;  ) > 1.9.11cvs59.patchset
+( cvs diff -u -r 1.179.2.27 -r 1.179.2.28 src/imap.c;  ) > 1.9.11cvs60.patchset
index a7fee39c8ac0d251c3f58499870d49d4a5353974..5c8695d55a03e8a814c13d6d7c6a9863e531b641 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=59
+EXTRA_VERSION=60
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index f86c1302dd2cf8ff451f29bf730dad1e416455dc..39f12f35cc7b660c8206d9946abcd19eae2b72bc 100644 (file)
@@ -567,6 +567,7 @@ FolderClass *imap_get_class(void)
                imap_class.is_msg_changed = imap_is_msg_changed;
                imap_class.change_flags = imap_change_flags;
                imap_class.get_flags = imap_get_flags;
+
        }
        
        return &imap_class;
@@ -1076,8 +1077,9 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
        g_return_val_if_fail(msglist != NULL, -1);
 
        session = imap_session_get(folder);
-       if (!session) return -1;
-
+       if (!session) {
+               return -1;
+       }
        msginfo = (MsgInfo *)msglist->data;
 
        src = msginfo->folder;
@@ -1088,8 +1090,9 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
 
        ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
                         NULL, NULL, NULL, NULL, FALSE);
-       if (ok != IMAP_SUCCESS)
+       if (ok != IMAP_SUCCESS) {
                return ok;
+       }
 
        destdir = imap_get_real_path(IMAP_FOLDER(folder), dest->path);
        seq_list = imap_get_seq_set_from_msglist(msglist);
@@ -1190,13 +1193,14 @@ static gint imap_remove_all_msg(Folder *folder, FolderItem *item)
        g_return_val_if_fail(item != NULL, -1);
 
        session = imap_session_get(folder);
-       if (!session) return -1;
-
+       if (!session) {
+               return -1;
+       }
        ok = imap_select(session, IMAP_FOLDER(folder), item->path,
                         NULL, NULL, NULL, NULL, FALSE);
-       if (ok != IMAP_SUCCESS)
+       if (ok != IMAP_SUCCESS) {
                return ok;
-
+       }
        imap_gen_send(session, "STORE 1:* +FLAGS.SILENT (\\Deleted)");
        ok = imap_cmd_ok(session, NULL);
        if (ok != IMAP_SUCCESS) {
@@ -4311,72 +4315,12 @@ gboolean imap_scan_required(Folder *folder, FolderItem *_item)
        return FALSE;
 }
 
-static GHashTable *flags_set_table = NULL;
-static GHashTable *flags_unset_table = NULL;
-static gint hashtable_process_tag = -1;
-
-typedef struct _hashtable_data {
-       IMAPSession *session;
-       GSList *msglist;
-       FolderItem *item;
-} hashtable_data;
-
-static gboolean process_flags(gpointer key, gpointer value, gpointer user_data)
-{
-       gboolean flags_set = GPOINTER_TO_INT(user_data);
-       gint flags_value = GPOINTER_TO_INT(key);
-       hashtable_data *data = (hashtable_data *)value;
-       
-       data->msglist = g_slist_reverse(data->msglist);
-       
-       imap_set_message_flags(data->session, data->msglist, flags_value, flags_set);
-
-       if (flags_value == IMAP_FLAG_DELETED && flags_set == TRUE) {
-               if (!data->session->uidplus) {
-                       imap_cmd_expunge(data->session, NULL);
-               } else {
-                       GSList *seq_list;
-                       IMAPSet imapset;
-                       seq_list = imap_get_seq_set_from_numlist(data->msglist);
-                       imapset = get_seq_set_from_seq_list(seq_list);
-
-                       imap_cmd_expunge(data->session, imapset);
-                       g_free(imapset);
-                       g_free(seq_list);
-               }
-       }
-       g_slist_free(data->msglist);    
-       g_free(data);
-       return TRUE;
-}
-
-static FolderItem *last_deferred_item = NULL;
-static gboolean process_hashtable(void *data)
-{
-       FolderItem *item = (FolderItem *)data;
-       debug_print("processing flags change hashtables\n");
-       if (flags_set_table) {
-               g_hash_table_foreach_remove(flags_set_table, process_flags, GINT_TO_POINTER(TRUE));
-               g_free(flags_set_table);
-               flags_set_table = NULL;
-       }
-       if (flags_unset_table) {
-               g_hash_table_foreach_remove(flags_unset_table, process_flags, GINT_TO_POINTER(FALSE));
-               g_free(flags_unset_table);
-               flags_unset_table = NULL;
-       }
-       
-       folder_item_scan_full(item, FALSE);
-       hashtable_process_tag = -1;
-       return FALSE;
-}
-
 void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPermFlags newflags)
 {
        IMAPSession *session;
        IMAPFlags flags_set = 0, flags_unset = 0;
        gint ok = IMAP_SUCCESS;
-       hashtable_data *ht_data = NULL;
+       MsgNumberList numlist;
        
        g_return_if_fail(folder != NULL);
        g_return_if_fail(folder->klass == &imap_class);
@@ -4389,29 +4333,11 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
        if (!session) return;
 
        debug_print("-> changing flags\n");
-
-       if (hashtable_process_tag != -1 && item != last_deferred_item
-       &&  last_deferred_item != NULL) {
-               debug_print("forcing flush for %s (!= %s)\n",
-                               last_deferred_item->path,
-                               item->path);
-               gtk_timeout_remove(hashtable_process_tag);
-               process_hashtable(last_deferred_item);
-               hashtable_process_tag = -1;
-       }
-       last_deferred_item = item;
        
        if ((ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
            NULL, NULL, NULL, NULL, FALSE)) != IMAP_SUCCESS)
                return;
                
-       if (!flags_set_table) {
-               flags_set_table = g_hash_table_new(NULL, g_direct_equal);
-       }
-       if (!flags_unset_table) {
-               flags_unset_table = g_hash_table_new(NULL, g_direct_equal);
-       }
-
        if (!MSG_IS_MARKED(msginfo->flags) &&  (newflags & MSG_MARKED))
                flags_set |= IMAP_FLAG_FLAGGED;
        if ( MSG_IS_MARKED(msginfo->flags) && !(newflags & MSG_MARKED))
@@ -4427,40 +4353,20 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
        if ( MSG_IS_REPLIED(msginfo->flags) && !(newflags & MSG_REPLIED))
                flags_set |= IMAP_FLAG_ANSWERED;
 
-       /* instead of performing an UID STORE command for each message change,
-        * as a lot of them can change "together", we just fill in hashtables
-        * and defer the treatment 100ms so that we're able to send only one
-        * command.
-        */
+       numlist.next = NULL;
+       numlist.data = GINT_TO_POINTER(msginfo->msgnum);
+
        if (flags_set) {
-               ht_data = g_hash_table_lookup(flags_set_table, GINT_TO_POINTER(flags_set));
-               if (ht_data == NULL) {
-                       ht_data = g_new0(hashtable_data, 1);
-                       ht_data->session = session;
-                       g_hash_table_insert(flags_set_table, GINT_TO_POINTER(flags_set), ht_data);
-               }
-               if (!g_slist_find(ht_data->msglist, GINT_TO_POINTER(msginfo->msgnum)))
-                       ht_data->msglist = g_slist_prepend(ht_data->msglist, GINT_TO_POINTER(msginfo->msgnum));
+               ok = imap_set_message_flags(session, &numlist, flags_set, TRUE);
+               if (ok != IMAP_SUCCESS) return;
        }
 
        if (flags_unset) {
-               ht_data = g_hash_table_lookup(flags_unset_table, GINT_TO_POINTER(flags_unset));
-               if (ht_data == NULL) {
-                       ht_data = g_new0(hashtable_data, 1);
-                       ht_data->session = session;
-                       g_hash_table_insert(flags_unset_table, GINT_TO_POINTER(flags_unset), ht_data);
-               }
-               if (!g_slist_find(ht_data->msglist, GINT_TO_POINTER(msginfo->msgnum)))
-                       ht_data->msglist = g_slist_prepend(ht_data->msglist, GINT_TO_POINTER(msginfo->msgnum));
+               ok = imap_set_message_flags(session, &numlist, flags_unset, FALSE);
+               if (ok != IMAP_SUCCESS) return;
        }
-
        msginfo->flags.perm_flags = newflags;
        
-       if (hashtable_process_tag != -1)
-               gtk_timeout_remove(hashtable_process_tag);
-               
-       hashtable_process_tag = gtk_timeout_add(100, process_hashtable, item);
-       
        return;
 }
 
@@ -4470,15 +4376,7 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
        IMAPSession *session;
        gchar *dir;
        MsgNumberList numlist;
-       hashtable_data *ht_data;
        
-       if (!flags_set_table) {
-               flags_set_table = g_hash_table_new(NULL, g_direct_equal);
-       }
-       if (!flags_unset_table) {
-               flags_unset_table = g_hash_table_new(NULL, g_direct_equal);
-       }
-
        g_return_val_if_fail(folder != NULL, -1);
        g_return_val_if_fail(FOLDER_CLASS(folder) == &imap_class, -1);
        g_return_val_if_fail(item != NULL, -1);
@@ -4486,37 +4384,35 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
        session = imap_session_get(folder);
        if (!session) return -1;
 
-       if (hashtable_process_tag != -1 && item != last_deferred_item
-       &&  last_deferred_item != NULL) {
-               debug_print("forcing flush for %s (!= %s)\n",
-                               last_deferred_item->path,
-                               item->path);
-               gtk_timeout_remove(hashtable_process_tag);
-               process_hashtable(last_deferred_item);
-               hashtable_process_tag = -1;
-       }
-       last_deferred_item = item;
-
-debug_print("-> removing messages\n");
        ok = imap_select(session, IMAP_FOLDER(folder), item->path,
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS)
                return ok;
 
-       ht_data = g_hash_table_lookup(flags_set_table, GINT_TO_POINTER(IMAP_FLAG_DELETED));
-       if (ht_data == NULL) {
-               ht_data = g_new0(hashtable_data, 1);
-               ht_data->session = session;
-               g_hash_table_insert(flags_set_table, GINT_TO_POINTER(IMAP_FLAG_DELETED), ht_data);
-       }
-       if (!g_slist_find(ht_data->msglist, GINT_TO_POINTER(uid)))
-               ht_data->msglist = g_slist_prepend(ht_data->msglist, 
-                               GINT_TO_POINTER(uid));
+       numlist.next = NULL;
+       numlist.data = GINT_TO_POINTER(uid);
        
-       if (hashtable_process_tag != -1)
-               gtk_timeout_remove(hashtable_process_tag);
-               
-       hashtable_process_tag = gtk_timeout_add(100, process_hashtable, item);
+       ok = imap_set_message_flags
+               (IMAP_SESSION(REMOTE_FOLDER(folder)->session),
+               &numlist, IMAP_FLAG_DELETED, TRUE);
+       if (ok != IMAP_SUCCESS) {
+               log_warning(_("can't set deleted flags: %d\n"), uid);
+               return ok;
+       }
+
+       if (!session->uidplus) {
+               ok = imap_cmd_expunge(session, NULL);
+       } else {
+               gchar *uidstr;
+
+               uidstr = g_strdup_printf("%u", uid);
+               ok = imap_cmd_expunge(session, uidstr);
+               g_free(uidstr);
+       }
+       if (ok != IMAP_SUCCESS) {
+               log_warning(_("can't expunge\n"));
+               return ok;
+       }
 
        IMAP_FOLDER_ITEM(item)->uid_list = g_slist_remove(
            IMAP_FOLDER_ITEM(item)->uid_list, numlist.data);