[MERGE][bzr-email] Implement mail sending using smtplib

John Arbash Meinel john at arbash-meinel.com
Thu Jan 25 23:38:15 GMT 2007


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

Recently, I decided to start using 'bzr-email' to send my commits to the
bazaar-commits mailing list. However, when I started using it, I found
that I didn't have 'mail' installed, and certainly not configured.

So I started down the trek of implementing mail sending using python,
rather than spawning a process.

The first thing I did was merge Jelmer's fix which allows
'public_branch' to be used in the outgoing email.

Then I implemented an SMTPConnection class, which has a little bit of
knowledge about what configuration parameters bzrlib should use to
define an SMTP connection (smtp_server, smtp_username, smtp_password).

That part was easy. The tricky part was to make everything support
Unicode. And support it in a way that wouldn't confuse my SMTP server,
and would look nice in Thunderbird.

So I took a merry jaunt into the details of python's "email" module, as
well as comparing messages sent by python to messages sent by
Thunderbird. After way too long (probably 2 days work), I know have a
class rather capable of sending nicely formatted Unicode emails.

(For example, when a header needs Unicode you generally do something like:

To: =?utf-8?q?Erik_B=C3=A5gfors?= <erik at bagfors.com>


That splits it up into 2 parts, a utf-8 "real name", and an ascii-only
email address. By default python's email.Header() wraps the whole thing
in =?utf-8?...?=:

To: =?utf-8?q?Erik_B=C3=A5gfors_=3Cerik=40bagfors=2Ecom=3E?=

But that makes my SMTP server (postfix) freak out and think that the To
line should actually be:
To:
=?utf-8?q?Erik_B=C3=A5gfors_=3Cerik=40bagfors=2Ecom=3E?=@arbash-meinel.com

Obviously there is no user by that name in my domain.

Anyway, so I did the tricks to split things up properly.

I also worked out the tricks for sending a utf-8 text section, as well
as being able to send an 8-bit exact text (for attaching a diff). So now
instead of sending a mixed-text email (the commit log portion is
definitely utf-8, while the diff portion could be in any encoding), it
now sends a Multipart one. I'm also careful to set "Content-Disposition:
inline;", so most mail programs should be able to display the diff right
away.

Overall, I'm quite pleased with the result. I'm not 100% happy with the
name (SMTPConnection). But I think this is something that should be
moved into bzrlib itself. That way both 'pqm-submit' and 'email' can use it.

I also found out that python's built-in 'email' classes are not quite
complete enough to easily decode one of these (there doesn't seem to be
an easy way to get the charset of the final decode 8-bit text without
parsing Content-Type yourself.).

So I'd like to get this merged into the bzr-email plugin, and possibly
have smtplib upgraded to being the default, rather than having 'mail' be
the default.

John
=:->

PS> In this process, I also found that 'prodigy.net' will happily encode
your 8-bit email as a Quoted Printable message. I haven't figured out
why they feel the need to. It didn't seem to break my gpg signature,
though, so maybe it doesn't matter.

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

iD8DBQFFuT9nJdeBCYSNAAMRAuysAJ4nevNSD/OrRd2BDYslvR9MOQUdQwCdFIBO
gBehNDpmIJf0MnNPlIWg0rM=
=yihu
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: email_use_smtplib.patch
Type: text/x-patch
Size: 185054 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070125/0fc8243f/attachment-0001.bin 


More information about the bazaar mailing list