Subject: bug#54158: 28.0.91; duplicate mail downloads in Gnus (IMAP)

From: Eric Abrahamsen <[email-masked]>
Date: Thu, 10 Mar 2022 11:38:32 -0800

Roland Winkler <[email-masked]> writes:

> On Fri, Feb 25 2022, Eric Abrahamsen wrote:
>> I went down a bit of a rabbit hole here, and my best guess is that
>> commit daa4e0120 (which is in emacs-28 but not emacs-27) might have
>> resulted in a bug in the dynamic binding of your imap mail-source
>> definition data.
>
> ...First I thought "let me revert this patch and see what happens", but
> that's not a meaningful step.
>
>> Something to try would be to edebug `mail-source-fetch-imap' and make
>> sure that the dynamic variables `dontexpunge' and `fetchflag' are what
>> you'd expect them to be, ie nil and "\Deleted". And watch what happens
>> for both "INBOX" and "JUNK EMAIL"
>
> The values of these variables are always what you said they should be,
> nil and "\Deleted".
>
>> (why are you fetching your junk mail, anyway?)
>
> It's the usual problem that the folder "JUNK EMAIL" contains messages
> that should not be there.  And I haven't figured out how the server
> identifies mail as spam, nor whether it would allow me to fine-tune
> this.  I find it easier to do all this on the client side.
>
>> To be honest I don't see why `imap-mailbox-close' would expunge mail
>> anyway: its docstring says it does, but no expunge command is given.
>> There's a `imap-mailbox-expunge' function, but nothing ever calls it.
>> Anyway, that part of the code hasn't changed since emacs-27, so
>> <shrug>.
>
> I looked at this code.  Unfortunately, the wrappers it uses make it very
> difficult to understand what it is doing, also because I do not know
> either what it needs to do to get things right.
>
>> If something funny is happening with the values of fetchflag or
>> dontexpunge, we can drag in Stefan M, who changed `mail-source-bind'.
>
> Following your suggestions of monitoring the variables `dontexpunge' and
> `fetchflag', I do not see anything unusual in mail-source-fetch-imap.

My intuitive shots-in-the-dark are pretty much always wrong :(

> My understanding is that IMAP servers permit to expunge individual
> messages while keeping others, though I do not want to use this feature
> (I want to expunge everything after fetching it).  However, I do not see
> where mail-source-fetch-imap would implement such fine control.  But my
> problem of multiple downloads exists only for *some*, but not all
> messages.  So it seems to me we may be looking at the wrong part of the
> code altogether.  But that's only a wild guess of someone who does not
> know much about all of this.

I don't know that much, either. I'll set up a local IMAP account and do
some testing with this, but it will take me a week or so to get to it.
Can you tell me what IMAP server you're talking to here?