Merge pull request #50 from knatsakis/knats-fix-remoteusereval

BUG: Right format for username using remoteusereval
This commit is contained in:
Rodolfo García Peñas (kix) 2021-02-18 18:37:57 +01:00 committed by GitHub
commit 18c6612587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -206,12 +206,23 @@ class IMAPRepository(BaseRepository):
Returns: Returns the remoteusereval or remoteuser or netrc user value.
"""
localeval = self.localeval
if self.config.has_option(self.getsection(), 'remoteusereval'):
user = self.getconf('remoteusereval')
if user is not None:
return localeval.eval(user).encode('UTF-8')
l_user = self.localeval.eval(user)
# We need a str username
if isinstance(l_user, bytes):
return l_user.decode(encoding='utf-8')
elif isinstance(l_user, str):
return l_user
# If is not bytes or str, we have a problem
raise OfflineImapError("Could not get a right username format for"
" repository %s. Type found: %s. "
"Please, open a bug." %
(self.name, type(l_user)),
OfflineImapError.ERROR.FOLDER)
if self.config.has_option(self.getsection(), 'remoteuser'):
# Assume the configuration file to be UTF-8 encoded so we must not