Fix bug #2991, "POP3 sessions duplicated" on race conditions. Patch by
authorColin Leroy <colin@colino.net>
Sat, 28 Dec 2013 17:31:22 +0000 (18:31 +0100)
committerColin Leroy <colin@colino.net>
Sat, 28 Dec 2013 17:31:22 +0000 (18:31 +0100)
Paul Rolland.

src/folder.c
src/folder.h
src/inc.c
src/mbox.c
src/pop.c
src/prefs_account.c
src/prefs_account.h

index 676c7a9..4c7a045 100644 (file)
@@ -4260,13 +4260,16 @@ static gchar * folder_item_get_tree_identifier(FolderItem * item)
 #define TEMP_FOLDER "TEMP_FOLDER"
 #define PROCESSING_FOLDER_ITEM "processing"    
 
-static FolderItem *processing_folder_item;
-
-static void folder_create_processing_folder(void)
+static FolderItem *folder_create_processing_folder(int account_id)
 {
        Folder *processing_folder;
+       FolderItem *processing_folder_item;
        gchar      *tmpname;
 
+       gchar *processing_folder_item_name = NULL;
+
+        processing_folder_item_name = g_strdup_printf("%s-%d", PROCESSING_FOLDER_ITEM, account_id);
+
        if ((processing_folder = folder_find_from_name(TEMP_FOLDER, mh_get_class())) == NULL) {
                gchar *tmppath;
 
@@ -4285,35 +4288,37 @@ static void folder_create_processing_folder(void)
            this.  */
        if (!is_relative_filename(LOCAL_FOLDER(processing_folder)->rootpath))
                tmpname = g_strconcat(LOCAL_FOLDER(processing_folder)->rootpath,
-                                     G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
+                                     G_DIR_SEPARATOR_S, 
+                                     processing_folder_item_name,
                                      NULL);
        else
                tmpname = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
                                      LOCAL_FOLDER(processing_folder)->rootpath,
-                                     G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
+                                     G_DIR_SEPARATOR_S, 
+                                     processing_folder_item_name,
                                      NULL);
 
        if (!is_dir_exist(tmpname)) {
                debug_print("*TMP* creating %s\n", tmpname);
                processing_folder_item = processing_folder->klass->create_folder(processing_folder,
                                                                                 processing_folder->node->data,
-                                                                                PROCESSING_FOLDER_ITEM);
+                                                                                processing_folder_item_name);
        } else {
                debug_print("*TMP* already created\n");
-               processing_folder_item = folder_item_new(processing_folder, PROCESSING_FOLDER_ITEM, PROCESSING_FOLDER_ITEM);
+               processing_folder_item = folder_item_new(processing_folder, processing_folder_item_name, processing_folder_item_name);
                g_assert(processing_folder_item);
                folder_item_append(processing_folder->node->data, processing_folder_item);
        }
+       g_free(processing_folder_item_name);
        g_assert(processing_folder_item != NULL);
        g_free(tmpname);
+
+       return(processing_folder_item);
 }
 
-FolderItem *folder_get_default_processing(void)
+FolderItem *folder_get_default_processing(int account_id)
 {
-       if (!processing_folder_item) {
-               folder_create_processing_folder();
-       }
-       return processing_folder_item;
+       return folder_create_processing_folder(account_id);
 }
 
 /* folder_persist_prefs_new() - return hash table with persistent
index 44f69bb..191dcd8 100644 (file)
@@ -895,7 +895,7 @@ FolderItem *folder_get_default_queue        (void);
 FolderItem *folder_get_default_queue_for_class(FolderType type);
 FolderItem *folder_get_default_trash   (void);
 FolderItem *folder_get_default_trash_for_class(FolderType type);
-FolderItem *folder_get_default_processing (void);
+FolderItem *folder_get_default_processing (int account_id);
 void folder_set_missing_folders                (void);
 void folder_unref_account_all          (PrefsAccount   *account);
 
index 254e52e..c8c68ac 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -288,6 +288,8 @@ gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account)
 
        if (inc_lock_count) return 0;
 
+       if (account->receive_in_progress) return 0;
+
        if (prefs_common.work_offline && 
            !inc_offline_should_override(TRUE,
                _("Claws Mail needs network access in order "
@@ -367,9 +369,11 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
                PrefsAccount *account = list->data;
 
                if (account->recv_at_getall) {
-                       session = inc_session_new(account);
-                       if (session)
-                               queue_list = g_list_append(queue_list, session);
+                       if (!(account->receive_in_progress)) {
+                               session = inc_session_new(account);
+                               if (session)
+                                       queue_list = g_list_append(queue_list, session);
+                       }
                }
        }
 
@@ -695,7 +699,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                        inbox = folder_get_default_inbox();
 
                /* get list of messages in processing */
-               processing = folder_get_default_processing();
+               processing = folder_get_default_processing(pop3_session->ac_prefs->account_id);
                folder_item_scan(processing);
                msglist = folder_item_get_msg_list(processing);
 
@@ -1128,7 +1132,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        }
 
        /* CLAWS: claws uses a global .processing folder for the filtering. */
-       dropfolder = folder_get_default_processing();
+       dropfolder = folder_get_default_processing(session->ac_prefs->account_id);
 
        /* add msg file to drop folder */
        if ((msgnum = folder_item_add_msg(
index 7ad328c..04f5108 100644 (file)
@@ -128,7 +128,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
        folder_item_update_freeze();
 
        if (apply_filter)
-               dropfolder = folder_get_default_processing();
+               dropfolder = folder_get_default_processing(account->account_id);
        else
                dropfolder = dest;
        
index c2f1d4b..a9a0472 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -519,6 +519,8 @@ Session *pop3_session_new(PrefsAccount *account)
 
        cm_return_val_if_fail(account != NULL, NULL);
 
+       account->receive_in_progress = TRUE;
+
        session = g_new0(Pop3Session, 1);
 
        session_init(SESSION(session), account, FALSE);
@@ -567,6 +569,8 @@ static void pop3_session_destroy(Session *session)
        g_free(pop3_session->user);
        g_free(pop3_session->pass);
        g_free(pop3_session->error_msg);
+
+       pop3_session->ac_prefs->receive_in_progress = FALSE;
 }
 
 static void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
index 7990a31..43295c0 100644 (file)
@@ -3505,6 +3505,8 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
                privacy_prefs = NULL;
        }
 
+       ac_prefs->receive_in_progress = FALSE;
+
        prefs_custom_header_read_config(ac_prefs);
 }
 
index 2ff9207..40b9301 100644 (file)
@@ -105,6 +105,8 @@ struct _PrefsAccount
 
        gint imap_auth_type;
 
+       gboolean receive_in_progress;
+
        /* Send */
        gboolean gen_msgid;
        gboolean gen_xmailer;