Subject: bug#30022: gnus nnimap-sequence vs yahoo hang

From: Kevin Ryde <[email-masked]>
Date: Mon, 08 Jan 2018 17:01:40 +1100

With the gnus included in recent debian packaged i386 emacs 25.2, in the
Group buffer, an M-g to get count of messages of a foreign imap group at
imap.mail.yahoo.com hangs.  If C-g to stop then a second M-g succeeds.

Sticking in some protocol trace showed

    out >> 1 CAPABILITY
    out >> 1 LOGIN "username" "password"

    in  << 1 OK CAPABILITY completed
    out >> 2 SELECT "mailboxname"
    
    in  << 1 OK LOGIN completed
    hang ...

I suspect nnimap.el interprets "1 OK CAPABILITY" response as being login
completion, and issues the SELECT.  Could that be right?

I don't know if a server is supposed to allow pipelined SELECT before
login completes.  It seems recent imap.mail.yahoo.com doesn't like it.
I see nnimap-login uses nnimap-command so I take it the intention in
gnus is not to attempt such a thing anyway, but wait for login success.

I get some joy from the diff below setting nnimap-sequence so it starts
"2 LOGIN".  The first M-g then succeeds for me as hoped.

I think the reason a second M-g on the group succeeds is that
nnimap-sequence is left incremented after the first attempt, so it goes
"3 LOGIN" or whatever bigger number.

I have this on a rather lagged connection, if that might make a
difference.  I see the login taking a noticeable second or so, but don't
know if that's by the server or the connection.

-------------------
Gnus v5.13
GNU Emacs 25.2.1 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2017-09-12, modified by Debian

>From 6acf5ee48665e2b0addc66bb329fc21df27ddd3b Mon Sep 17 00:00:00 2001
From: Kevin Ryde <[email-masked]>
Date: Mon, 8 Jan 2018 12:29:07 +1100
Subject: [PATCH] nnimap-sequence initial value 1 so first command is "2 LOGIN"
 which is different tag than "1 CAPABILITY" in open-network-stream.

Previous initial value 0 giving "1 LOGIN" was reckoned completed by
the 1 CAPABILITY response, causing SELECT to be sent pipelined, which
imap.mail.yahoo.com circa 2017 did not like (ignores, apparently,
causing gnus hang, with a gnus foreign imap group at least).
---
 lisp/gnus/nnimap.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 05251ed..eeaa10d 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -1855,7 +1855,9 @@ nnimap-find-connection
 	(setq nnimap-connection-alist (delq entry nnimap-connection-alist))
 	nil))))
 
-(defvar nnimap-sequence 0)
+;; nnimap-sequence is pre-incremented so first tag is "2" which is after
+;; "1 CAPABILITY" of :capability-command
+(defvar nnimap-sequence 1)
 
 (defun nnimap-send-command (&rest args)
   (setf (nnimap-last-command-time nnimap-object) (current-time))
-- 
2.15.1