diff --git a/offlineimap.conf b/offlineimap.conf index 9d003cb..b57b182 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -829,6 +829,10 @@ remoteuser = username # #oauth2_client_id = YOUR_CLIENT_ID #oauth2_client_secret = YOUR_CLIENT_SECRET +# +# The return values must be bytes. +#oauth2_client_id_eval = get_client_id("accountname") +#oauth2_client_secret_eval = get_client_secret("accountname") # Specify the refresh token to use for the connection to the mail server. # Here's an example of a way to get a refresh token: @@ -853,6 +857,10 @@ remoteuser = username #oauth2_access_token = ACCESS_TOKEN #oauth2_request_url = https://accounts.google.com/o/oauth2/token #oauth2_refresh_token = REFRESH_TOKEN +# +# The return values must be bytes. +#oauth2_access_token_eval = get_access_token("accountname") +#oauth2_refresh_token_eval = get_refresh_token("accountname") ########## Passwords diff --git a/offlineimap/CustomConfig.py b/offlineimap/CustomConfig.py index b5d58e8..b528e70 100644 --- a/offlineimap/CustomConfig.py +++ b/offlineimap/CustomConfig.py @@ -16,8 +16,8 @@ import os import re -import six from sys import exc_info +import six try: from ConfigParser import SafeConfigParser, Error diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index bd06983..e61f53d 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -301,16 +301,32 @@ class IMAPRepository(BaseRepository): return self._oauth2_request_url def getoauth2_refresh_token(self): - return self.getconf('oauth2_refresh_token', None) + refresh_token = self.getconf('oauth2_refresh_token', None) + if refresh_token is None: + refresh_token = self.localeval.eval( + self.getconf('oauth2_refresh_token_eval', "lambda: None")) + return refresh_token def getoauth2_access_token(self): - return self.getconf('oauth2_access_token', None) + access_token = self.getconf('oauth2_access_token', None) + if access_token is None: + access_token = self.localeval.eval( + self.getconf('oauth2_access_token_eval', "lambda: None")) + return access_token def getoauth2_client_id(self): - return self.getconf('oauth2_client_id', None) + client_id = self.getconf('oauth2_client_id', None) + if client_id is None: + client_id = self.localeval.eval( + self.getconf('oauth2_client_id_eval', "lambda: None")) + return client_id def getoauth2_client_secret(self): - return self.getconf('oauth2_client_secret', None) + client_secret = self.getconf('oauth2_client_secret', None) + if client_secret is None: + client_secret = self.localeval.eval( + self.getconf('oauth2_client_secret_eval', "lambda: None")) + return client_secret def getpreauthtunnel(self): return self.getconf('preauthtunnel', None) @@ -325,8 +341,7 @@ class IMAPRepository(BaseRepository): return self.getconfboolean('decodefoldernames', False) def getidlefolders(self): - localeval = self.localeval - return localeval.eval(self.getconf('idlefolders', '[]')) + return self.localeval.eval(self.getconf('idlefolders', '[]')) def getmaxconnections(self): num1 = len(self.getidlefolders())