From c21a7fa0a338478f822dcf9b6699a7087d66fcbe Mon Sep 17 00:00:00 2001 From: peeweep Date: Fri, 13 Aug 2021 23:02:45 +0000 Subject: [PATCH] BUG: Right format for host using remotehosteval Similarly to 7a428537, reading the host using remotehosteval returns a bytes objects instead an utf-8 string. This patch includes support for both string and bytes objects. --- offlineimap/repository/IMAP.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 6e0cdc4..ff0a3e2 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -141,7 +141,21 @@ class IMAPRepository(BaseRepository): if self.config.has_option(self.getsection(), 'remotehosteval'): host = self.getconf('remotehosteval') try: - host = self.localeval.eval(host) + l_host = self.localeval.eval(host) + + # We need a str host + if isinstance(l_host, bytes): + return l_host.decode(encoding='utf-8') + elif isinstance(l_host, str): + return l_host + + # If is not bytes or str, we have a problem + raise OfflineImapError("Could not get a right host format for" + " repository %s. Type found: %s. " + "Please, open a bug." % + (self.name, type(l_host)), + OfflineImapError.ERROR.FOLDER) + except Exception as exc: raise OfflineImapError( "remotehosteval option for repository "