XOAUTH2: use one "public" attribute everywhere for self.oauth2_request_url

Improve documentation.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2016-07-28 18:35:33 +02:00
parent be285e522d
commit b4e33eeac4
3 changed files with 20 additions and 15 deletions

View File

@ -801,7 +801,7 @@ remoteuser = username
# limitations, if GSSAPI is set, it will be tried first, no matter where it was # limitations, if GSSAPI is set, it will be tried first, no matter where it was
# specified in the list. # specified in the list.
# #
#auth_mechanisms = GSSAPI, CRAM-MD5, XOAUTH2, PLAIN, LOGIN #auth_mechanisms = GSSAPI, XOAUTH2, CRAM-MD5, PLAIN, LOGIN
# This option stands in the [Repository RemoteExample] section. # This option stands in the [Repository RemoteExample] section.
@ -812,7 +812,9 @@ remoteuser = username
# with type = IMAP for compatible servers. # with type = IMAP for compatible servers.
# #
# Mandatory parameters are "oauth2_client_id", "oauth2_client_secret" and # Mandatory parameters are "oauth2_client_id", "oauth2_client_secret" and
# either "oauth2_refresh_token" or "oauth2_access_token". # either "oauth2_refresh_token" or "oauth2_access_token". XOAUTH2 mechanism
# won't be tried if both oauth2_refresh_token and oauth2_access_token are not
# set.
# #
# See below to learn how to get those. # See below to learn how to get those.
# #

View File

@ -47,7 +47,7 @@ class GmailRepository(IMAPRepository):
try: try:
return super(GmailRepository, self).gethost() return super(GmailRepository, self).gethost()
except OfflineImapError: except OfflineImapError:
# nothing was configured, cache and return hardcoded one # Nothing was configured, cache and return hardcoded one.
self._host = GmailRepository.HOSTNAME self._host = GmailRepository.HOSTNAME
return self._host return self._host
@ -60,10 +60,10 @@ class GmailRepository(IMAPRepository):
url = super(GmailRepository, self).getoauth2_request_url() url = super(GmailRepository, self).getoauth2_request_url()
if url is None: if url is None:
# Nothing was configured, cache and return hardcoded one. # Nothing was configured, cache and return hardcoded one.
self._oauth2_request_url = GmailRepository.OAUTH2_URL self.setoauth2_request_url(GmailRepository.OAUTH2_URL)
else: else:
self._oauth2_request_url = url self.setoauth2_request_url(url)
return self._oauth2_request_url return self.oauth2_request_url
def getport(self): def getport(self):
return GmailRepository.PORT return GmailRepository.PORT
@ -82,8 +82,8 @@ class GmailRepository(IMAPRepository):
return folder.Gmail.GmailFolder return folder.Gmail.GmailFolder
def gettrashfolder(self, foldername): def gettrashfolder(self, foldername):
#: Where deleted mail should be moved # Where deleted mail should be moved
return self.getconf('trashfolder','[Gmail]/Trash') return self.getconf('trashfolder', '[Gmail]/Trash')
def getspamfolder(self): def getspamfolder(self):
#: Gmail also deletes messages upon EXPUNGE in the Spam folder #: Gmail also deletes messages upon EXPUNGE in the Spam folder

View File

@ -36,11 +36,11 @@ class IMAPRepository(BaseRepository):
BaseRepository.__init__(self, reposname, account) BaseRepository.__init__(self, reposname, account)
# self.ui is being set by the BaseRepository # self.ui is being set by the BaseRepository
self._host = None self._host = None
self._oauth2_request_url = None # Must be set before calling imapserver.IMAPServer(self)
self.oauth2_request_url = None
self.imapserver = imapserver.IMAPServer(self) self.imapserver = imapserver.IMAPServer(self)
self.folders = None self.folders = None
self.copy_ignore_eval = None self.copy_ignore_eval = None
self.oauth2_request_url = None
# Keep alive. # Keep alive.
self.kaevent = None self.kaevent = None
self.kathread = None self.kathread = None
@ -295,12 +295,15 @@ class IMAPRepository(BaseRepository):
value = self.getconf('cert_fingerprint', "") value = self.getconf('cert_fingerprint', "")
return [f.strip().lower() for f in value.split(',') if f] return [f.strip().lower() for f in value.split(',') if f]
def getoauth2_request_url(self): def setoauth2_request_url(self, url):
if self._oauth2_request_url: # Use cached value if possible. self.oauth2_request_url = url
return self._oauth2_request_url
self.oauth2_request_url = self.getconf('oauth2_request_url', None) def getoauth2_request_url(self):
return self._oauth2_request_url if self.oauth2_request_url is not None: # Use cached value if possible.
return self.oauth2_request_url
self.setoauth2_request_url(self.getconf('oauth2_request_url', None))
return self.oauth2_request_url
def getoauth2_refresh_token(self): def getoauth2_refresh_token(self):
refresh_token = self.getconf('oauth2_refresh_token', None) refresh_token = self.getconf('oauth2_refresh_token', None)