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

From: Roland Winkler <[email-masked]>
Date: Sat, 19 Mar 2022 22:50:44 -0500

On Sun, Mar 20 2022, Andrew Cohen wrote:
>>I am surprised that `mail-source-fetch-imap' in Gnus from Emacs 27.2
>>and from Emacs 28.0.91 are essentially the same (from all I can tell).
>>So I am wondering why `mail-source-fetch-imap' in Gnus from Emacs 27.2
>>was behaving as expected; but the bug showed up only in Emacs 28.  Can
>>this be in subtle ways related to the fact that mail-source.el in Emacs
>>27 used dynamic binding, whereas in Emacs 28 it uses lexical binding,
>>as speculated previously by Eric?
>
> This is indeed a mystery. If you are excited about getting to the bottom
> of it you could try enabling the log with emacs-27 and post the result
> of your scenario. The problem was the variable 'remove was accumulating
> UIDs from prior iterations of the loop. 

I am perplexed: Certainly, I struggled for the longest time to identify
a reproducible recipe for this bug till I learned about the variable
imap-log (see my earlier posts in this thread).  Indeed, with this
recipe the bug does show up both with Emacs 28.0.91 and Emacs 27.2.  So
I need to take back what I said before that this bug is a regression.

Reading the code of `mail-source-fetch-imap' more carefully, I agree
with you: it would be a mystery if the code had ever worked as intended.

A possible explanation from my side is: while I started using Gnus about
mid of last year when I had Emacs 27.2, I added a second IMAP folder to
my `mail-sources' configuration more recently, possibly around the time
when I switched from 27.2 to 28.0.91.  Then I got fooled by this bug
because I didn't know its actual cause.  While I went back temporarily
from 28.0.91 to 27.2 to see whether this changed anything, I may have
done that for too short an amount of time to run into the particular
situation that triggers this bug.  Oh well.

Thanks to everyone who has helped to find the cause of this bug!