require usernames and passwords to be UTF-8 encoded

- Learn to support UTF-8 characters where it was not supported for usernames and
  passwords (but for netrc).
- Fix the types in the code for both py2 and py3: we now expect unicode for
  usernames and passwords.

Unicode (UTF-8) is required only for variables with non-ASCII characters.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht
2016-06-16 19:51:41 +02:00
parent 092264c8e7
commit 08e17de7e2
3 changed files with 40 additions and 22 deletions

View File

@ -154,6 +154,7 @@ class IMAPServer(object):
def __getpassword(self):
"""Returns the server password or None"""
if self.goodpassword != None: # use cached good one first
return self.goodpassword
@ -216,13 +217,15 @@ class IMAPServer(object):
authc = self.username
passwd = self.__getpassword()
authz = ''
authz = b''
if self.user_identity != None:
authz = self.user_identity
NULL = u'\x00'
retval = NULL.join((authz, authc, passwd)).encode('utf-8')
logsafe_retval = NULL.join((authz, authc, "(passwd hidden for log)")).encode('utf-8')
self.ui.debug('imap', '__plainhandler: returning %s' % logsafe_retval)
# At this point all authz, authc and passwd are expected bytes encoded
# in UTF-8.
NULL = b'\x00'
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)
return retval