BUG: Right format for username using remoteusereval

Similarly to 7a4285370f, reading the username
using remoteusereval returns a bytes objects instead an utf-8 string.

This patch includes support for both string and bytes objects.

Signed-off-by: Konstantinos Natsakis <5933427+knatsakis@users.noreply.github.com>
This commit is contained in:
Konstantinos Natsakis 2021-02-08 23:40:32 +02:00
parent 00d395b746
commit fa080b8d92
No known key found for this signature in database
GPG Key ID: 32AA571C06185176

View File

@ -206,12 +206,23 @@ class IMAPRepository(BaseRepository):
Returns: Returns the remoteusereval or remoteuser or netrc user value. Returns: Returns the remoteusereval or remoteuser or netrc user value.
""" """
localeval = self.localeval
if self.config.has_option(self.getsection(), 'remoteusereval'): if self.config.has_option(self.getsection(), 'remoteusereval'):
user = self.getconf('remoteusereval') user = self.getconf('remoteusereval')
if user is not None: 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'): if self.config.has_option(self.getsection(), 'remoteuser'):
# Assume the configuration file to be UTF-8 encoded so we must not # Assume the configuration file to be UTF-8 encoded so we must not