Subject: Re: bug#78240: 30.1; xoauth2 authentication fails in gnus imap mail fetching

From: Robert Pluim <[email-masked]>
Date: Wed, 06 Aug 2025 09:56:38 +0200

>>>>> On Tue, 05 Aug 2025 11:01:25 -0700, Xiyue Deng <[email-masked]> said:

    Xiyue> Hi Robert,
    Xiyue> Robert Pluim <[email-masked]> writes:

    >>>>>>> On Sun, 04 May 2025 16:43:28 -0700, Xiyue Deng <[email-masked]> said:
    >> 
    >> 
    Xiyue> I have only tested using Gnus with nnimap (see documentation at [1] or
    Xiyue> [2]) where you want to add `(nnimap-authenticator xoauth2)' to your
    Xiyue> `nnimap' settings.  I haven't tested with `mail-sources', which seems to
    Xiyue> work differently compared to nnimap, and hence the implementation may be
    Xiyue> missing.  I probably need to understand how `mail-sources' works and
    Xiyue> extend the plugin accordingly, which could take a while.
    >> 
    >> Hi Xiyue,
    >> 
    >> I implemented auth-source lookup for imap.el (patch below). Would
    >> there be any chance to see if you could extend your package to support
    >> xoauth2 for imap.el?
    >> 
    >> It should be enough to add xoauth2 to `imap-authenticators', and
    >> `imap-xoauth2-auth-p' and `imap-xoauth2-auth' to
    >> `imap-authenticator-alist' (and their implementations, of course).
    >> 

    Xiyue> Thanks for implementing this!  As I haven't used imap.el I cannot test
    Xiyue> this right now.  I'll try to find some time to set up such an account
    Xiyue> and report back.  Hopefully this won't take too long.

If you have an existing nnimap server using xoauth2, then testing
against it with imap.el is easy:

(progn
  (require 'imap)
  (let ((i-buf (imap-open "imap.gmail.com" 993 'tls)))
    (imap-authenticate nil nil i-buf)
    (imap-mailbox-lsub "*" nil nil i-buf)))

If xoauth2 support is working, then that should auto-detect it and use
your xoauth2 credentials from .authinfo

If it doesnʼt work, then customize `imap-log' to t before loading
imap.el, and there will be an "*imap-log*" buffer containing a session
trace.

Robert
--