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 <sudipm.mukherjee@gmail.com>
This commit is contained in:
Sudip Mukherjee 2021-02-10 21:56:07 +00:00
parent 00d395b746
commit 96793820de

View File

@ -590,7 +590,20 @@ class IMAPRepository(BaseRepository):
encoding='utf-8') encoding='utf-8')
password = file_desc.readline().strip() password = file_desc.readline().strip()
file_desc.close() 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. # 4. Read password from ~/.netrc.
try: try:
netrcentry = netrc.netrc().authenticators(self.gethost()) netrcentry = netrc.netrc().authenticators(self.gethost())