From fa080b8d92944a1692a44e982292ffde8066950a Mon Sep 17 00:00:00 2001 From: Konstantinos Natsakis <5933427+knatsakis@users.noreply.github.com> Date: Mon, 8 Feb 2021 23:40:32 +0200 Subject: [PATCH] BUG: Right format for username using remoteusereval Similarly to 7a4285370f338a6653e8bb1a8fb99e3703683b6f, 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> --- offlineimap/repository/IMAP.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index b732243..e90d30c 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -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