From 39b657194a985f77578bed6d45a11f8d0ed26985 Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Wed, 15 Mar 2017 22:39:41 +0100 Subject: [PATCH] XOAUTH2: don't try this authentication method when not configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checking if we have to run this authentication method once it's already passed to imaplib2 is too late. Make the checks at correct time, before we try the authentication method. IOW, before we call imapobj.authenticate('XOAUTH2', self.__xoauth2handler) Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/442 Tested-by: Klemens Schölhorn Signed-off-by: Nicolas Sebrecht --- offlineimap/imapserver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 82693c6..d93dbbd 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -221,10 +221,6 @@ class IMAPServer(object): return retval def __xoauth2handler(self, response): - if self.oauth2_refresh_token is None \ - and self.oauth2_access_token is None: - return None - if self.oauth2_access_token is None: if self.oauth2_request_url is None: raise OfflineImapError("No remote oauth2_request_url for " @@ -353,6 +349,10 @@ class IMAPServer(object): return True def __authn_xoauth2(self, imapobj): + if self.oauth2_refresh_token is None \ + and self.oauth2_access_token is None: + return False + imapobj.authenticate('XOAUTH2', self.__xoauth2handler) return True