[PATCH] convert SMTP user name and password to byte strings (bug 338261)

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Mar 24 08:43:51 GMT 2009


>>>>> "James" == James Henstridge <james at jamesh.id.au> writes:

<snip/>

    James> === modified file 'bzrlib/smtp_connection.py'
    James> --- bzrlib/smtp_connection.py	2007-10-23 07:15:13 +0000
    James> +++ bzrlib/smtp_connection.py	2009-03-24 07:29:23 +0000
    James> @@ -111,6 +111,15 @@
    James>              self._smtp_password = auth.get_password(
    James>                  'smtp', self._smtp_server, self._smtp_username)
 
    James> +        # smtplib requires that the username and password be byte
    James> +        # strings.  The CRAM-MD5 spec doesn't give any guidance on
    James> +        # encodings, but the SASL PLAIN says UTF-8, so that's what
    James> +        # we'll use.
    James> +        if isinstance(self._smtp_username, unicode):
    James> +            self._smtp_username = self._smtp_username.encode('utf-8')
    James> +        if isinstance(self._smtp_password, unicode):
    James> +            self._smtp_password = self._smtp_password.encode('utf-8')
    James> +
    James>          self._connection.login(self._smtp_username, self._smtp_password)

I think you can use osutils.safe_utf8() here (that will guarantee
that one can't use invalid utf8 strings), other than that:

BB:tweak
 
 Vincent



More information about the bazaar mailing list