Bug 2991 - POP3 problems: POP3 sessions duplicated, and filtering issues
Summary: POP3 problems: POP3 sessions duplicated, and filtering issues
Alias: None
Product: Claws Mail
Classification: Unclassified
Component: POP3 (show other bugs)
Version: 3.9.2
Hardware: PC Linux
: P3 normal
Assignee: users
: 2278 (view as bug list)
Depends on:
Reported: 2013-08-12 10:55 UTC by Paul Rolland
Modified: 2014-04-30 21:41 UTC (History)
2 users (show)

See Also:

Patch to add a per-account lock to prevent two simultaneous POP3 sessions on the same account (2.26 KB, application/octet-stream)
2013-08-12 10:55 UTC, Paul Rolland
no flags Details
Patch to fix POP3 and processing issues (6.47 KB, patch)
2013-08-12 10:57 UTC, Paul Rolland
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Rolland 2013-08-12 10:55:50 UTC
Created attachment 1294 [details]
Patch to add a per-account lock to prevent two simultaneous POP3 sessions on the same account

First, I have to say that they occur only while I'm in holidays: at that
time, my Internet access is an ultra slow GPRS access....

I'm using POP3, and I have several accounts configured. Each of them as a
default folder to drop emails. I also have filtering rules, some applying
to all the accounts, some only for specific accounts. Last, my "Default"
folder also has a processing rule to archive emails older than 32 days.

Problem #1:
  a) Claws is offline
  b) I connect to Internet using my GPRS modem. Due to the way I'm
     NetworkManager is not informed, and Claws is still offline.
  c) Turn Claws online,
  d) Receive messages for one account.
If the "Receive" operation I start manually last longer than this account
retrieve interval, and that this account is configured for automatic
retrieval, I end up with _two_ retrieve operations at the same time. I can
see by the "progress counters" at the bottom right of the Claws window
alternating their counts of messages, for example:
10/46 then 30/46 then 10/46 again, and so on.
When that happens, I kill Claws to avoid more mess...

Problem #2:
  a) Claws is online
  b) I start a "Receive all", still using my slow GPRS access. This first
     collect the emails from my professional account, and then it goes to a
     secondary account, which is subscribed to several mailing lists.
  c) While the retrieval on the secondary mailing list occurs, I reply to
     an email associated with the main account, and Send this email.
This "Send" action results in all the emails received so far for the
secondary account (POP still in progress) to be placed in the folder
associated with the main account (the one used for the Send). It may be
important to note that this account (used to Send) is also configured with
"Authenticate with POP before sending". Maybe the POP sessions are mixing
each other ?

After investigations, it seems that problem #1 can be easily reproduced:
 - claws mail is offline,
 - I turned it online,
 - I used the "Received mail from all accounts" and selected one account,
   to start a retrieve session on that account.
 - While it was running, I hit "F5" which is bound to
   Message > Receive > Get from all accounts

Nothing seems to be preventing two POP3 sessions for the same account to occur.
Adding a locking mechanism seems to be required.

Also, as nothing is also preventing simultaneous POP3 sessions on _different_ accounts, and because:
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();

then everytime it happens that two (or more) POP3 sessions happens at the same time, messages filtering is causing bad results.
This could easily be solved using a per-account processing folder.

Attach to this post is a first patch that adds a flag in the PrefsAccounts. This flag is used to "lock" the POP3 session, thus avoiding it to be duplicated, while still allowing several POP3 on various accounts to be executed.
Comment 1 Paul Rolland 2013-08-12 10:57:47 UTC
Created attachment 1295 [details]
Patch to fix POP3 and processing issues

This second patch contains the previous one plus a proposal to have per-account processing folder, based on the account_id.
Comment 2 Paul 2013-10-02 10:08:53 UTC
I'm still not able to reproduce the problem you describe.
Comment 3 Paul Rolland 2013-10-02 15:06:29 UTC
Hi Paul,

Thanks for the feedback. 
I'm going to try to setup a configuration/test case that will allow to reproduce that easily. I think that inserting some delays in the POP server is likely to help creating the problem.

Please allow me a few days to setup that config, and I'll send you all the details.

Comment 4 Colin Leroy 2013-12-28 18:23:58 UTC

I've been able to do so, using the Get Mail arrow to fetch mail from my first account, immediately followed by Shift-A which is "Get for all accounts".
Comment 5 users 2013-12-28 18:57:35 UTC
Changes related to this bug have been committed.
Please check latest Git and update the bug accordingly.
You can also get the patch from:

++ ChangeLog	2013-12-28 18:57:35.500904730 +0100
Merge: 766877a 6a4badf
Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 18:57:34 2013 +0100

    Merge branch 'master' of file:///home/git/claws

Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 18:31:22 2013 +0100

    Fix bug #2991, "POP3 sessions duplicated" on race conditions. Patch by
    Paul Rolland.

Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 18:15:31 2013 +0100

    Fix bug #3020, "Use theme doesn't change some icons until restart"

Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 18:10:26 2013 +0100

    Add Palmer Dabbelt to Authors

Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 18:08:38 2013 +0100

    Fix bug #3040, "Handle revoked GPG private keys". Patch by Palmer Dabbelt.

Author: Colin Leroy <colin@colino.net>
Date:   Sat Dec 28 17:40:12 2013 +0100

    Fix bug #3038, "Select A Folder incorrectly matches on number
    in parentheses". Match on FolderItem's name instead of displayed

Author: Colin Leroy <colin@colino.net>
Date:   Fri Dec 20 11:53:18 2013 +0100

    Add preference to allow disabling automatic drafting of encrypted
Comment 6 Colin Leroy 2013-12-28 19:00:43 UTC
Thanks for the patches :)
Comment 7 Colin Leroy 2014-04-30 21:41:56 UTC
*** Bug 2278 has been marked as a duplicate of this bug. ***