From 96793820dec2d405b6c16efaa233f3ddf3da5e19 Mon Sep 17 00:00:00 2001 From: Sudip Mukherjee Date: Wed, 10 Feb 2021 21:56:07 +0000 Subject: [PATCH] BUG: Right format for password from remotepassfile Reading the password using remotepassfile returns a bytes objects instead an utf-8 string. This patch includes support strings and bytes objects. Closes: #40 Signed-off-by: Sudip Mukherjee --- offlineimap/repository/IMAP.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index b732243..56ebe74 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -590,7 +590,20 @@ class IMAPRepository(BaseRepository): encoding='utf-8') password = file_desc.readline().strip() file_desc.close() - return password.encode('UTF-8') + + # We need a str password + if isinstance(password, bytes): + return password.decode(encoding='utf-8') + elif isinstance(password, str): + return password + + # If is not bytes or str, we have a problem + raise OfflineImapError("Could not get a right password format for" + " repository %s. Type found: %s. " + "Please, open a bug." % + (self.name, type(password)), + OfflineImapError.ERROR.FOLDER) + # 4. Read password from ~/.netrc. try: netrcentry = netrc.netrc().authenticators(self.gethost())