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

James Henstridge james at jamesh.id.au
Mon Mar 16 23:17:23 GMT 2009

On Tue, Mar 17, 2009 at 12:25 AM, John Arbash Meinel
<john at arbash-meinel.com> wrote:
> 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.

So the old HMAC code that tolerated unicode looked like this:

    def _strxor(s1, s2):
        return "".join(map(lambda x, y: chr(ord(x) ^ ord(y)), s1, s2))
    self.outer.update(_strxor(key, opad))
    self.inner.update(_strxor(key, ipad))

The ord() and chr() calls basically mean that unicode values within
the 0..255 range will be accepted and treated as ISO-8859-1 byte
values.  So changing my patch to encode to UTF-8 is just as likely to
break existing setups as encoding to ASCII.

Without any guidance on how character encodings should be handled
here, I thought it safest to opt for the more conservative path.  If
someone complains, we'll have some more information about what mail
servers expect here.

> This is still better even if only using 'ascii'


More information about the bazaar mailing list