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

James Henstridge james at jamesh.id.au
Mon Mar 16 08:00:51 GMT 2009

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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug-338261.patch
Type: text/x-diff
Size: 5182 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090316/85bfe675/attachment.bin 

More information about the bazaar mailing list