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

John Arbash Meinel john at arbash-meinel.com
Mon Mar 16 15:25:50 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

James Henstridge wrote:
> The attached bundle changes SMTPConnection._authenticate() to convert
> unicode user names and passwords to byte strings before passing them
> to smtplib.  This fix is needed in order to talk to mail servers that
> expect you to authenticate via CRAM-MD5 with Python 2.6.  See bug
> 338261 for the relevant trace backs.
> 
> The hmac module from Python 2.5 and below tolerated unicode keys
> provided there were no code points out of the 0..255 range, but an
> optimisation in the 2.6 implementation causes problems.  As HMAC is a
> byte-oriented algorithm, it doesn't really make sense to pass unicode
> strings to this level, so I wouldn't consider this a Python bug.
> Also, the SMTP RFCs don't really say anything about character encoding
> for user names and passwords, so it isn't clear that the blame lies
> there either.
> 
> So the attached bundle converts the values to byte strings.  It uses
> ASCII encoding because I have no idea how non-ASCII values should be
> handled.  The previous code probably supported ISO 8859-1 encoded user
> names and passwords, but I can't see anything in the RFC to say this
> is correct so I don't know whether anyone would be relying on this in
> the wild.
> 
> James.
> 

BB:approve

I would probably encode via UTF-8, as that is the next-most-likely thing
after ASCII. I assume the issue is just that ConfigObj is returning
decoded strings (the config files are defined as being UTF-8). But
certainly the details depend on the server's config and how they encoded
their user-names.

This is still better even if only using 'ascii'

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkm+b34ACgkQJdeBCYSNAANx6gCghJTU/fTScDLPcnl2vEI3eF6w
eEIAoMs2TG74kd3pFoSokpTb1KKruGQy
=UijO
-----END PGP SIGNATURE-----



More information about the bazaar mailing list