From 5297e41e66adad55282fc738a23357dcffbbebb0 Mon Sep 17 00:00:00 2001
From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Date: Sat, 20 Feb 2021 00:03:36 +0000
Subject: [PATCH] BUG: Right format for password from Curses

Reading the password from Curses Blinkenlights returns a bytes objects
instead an utf-8 string.

This patch will decode if bytes is provided.

Closes: #49

BUG: Exception with debug logs

When ui is set to 'Curses Blinkenlights' and debug logs are enabled,
we get an exception with 'embedded null character'.

Remove the NULL from the log, keeping the log message same as before.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---

Upstream PR: https://github.com/OfflineIMAP/offlineimap3/pull/54

 offlineimap/imapserver.py | 4 ++--
 offlineimap/ui/Curses.py  | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index bd377f7..be557e6 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -215,8 +215,8 @@ class IMAPServer:
             authz = self.user_identity
 
         retval = NULL.join((authz, authc, passwd))
-        logsafe_retval = NULL.join((authz, authc, '(passwd hidden for log)'))
-        self.ui.debug('imap', '__plainhandler: returning %s' % logsafe_retval)
+        self.ui.debug('imap', '__plainhandler: returning %s %s '
+                      '(passwd hidden for log)' % (authz, authc))
         return retval
 
     def __xoauth2handler(self, response):
diff --git a/offlineimap/ui/Curses.py b/offlineimap/ui/Curses.py
index 03f4d26..dfad308 100644
--- a/offlineimap/ui/Curses.py
+++ b/offlineimap/ui/Curses.py
@@ -583,6 +583,10 @@ class Blinkenlights(UIBase, CursesUtil):
         finally:
             self.unlock()
             self.inputhandler.input_release()
+
+        # We need a str password
+        if isinstance(password, bytes):
+            return password.decode(encoding='utf-8')
         return password
 
     def setupwindows(self, resize=False):
-- 
2.30.0

