[RFC] An EmailMessage class for bzrlib

Aaron Bentley aaron.bentley at utoronto.ca
Wed Jun 20 14:20:39 BST 2007


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

Adeodato Simó wrote:

>   * all EmailMessages are a MIME multipart message; this should no be a
>     problem, as per the answers I received on the list about it.

You were asking about merge directives.  There is a place where plain
messages are expected: PQM merge requests.  We'd need to get input from
Robert Collins about whether anything other than plain messages are
supported by PQM.

The PQM plugin currently handles creating and sending an email, but I
think it would be really nice if we could strip that functionality out
of it, and use library functionality instead.

> +class EmailMessage(MIMEMultipart.MIMEMultipart, object):
> +    """A MIME Multipart email message."""

Why are you deriving from object?

> +        try:
> +            self['Subject'] = Header.Header(unicode(subject))
> +        except UnicodeDecodeError:
> +            raise NonAsciiString(subject)

You are relying on the platform's default encoding being ascii.  It
might be 'iso-8859-1', for example, and if it is, no bytestring will
cause a UnicodeDecodeError.

Instead of assuming the encoding is 'ascii', and therefore, that decode
failures are caused by non-ascii strings, explicitly encode it as ascii.

pygtk, to give an example, forces the default encoding to 'utf-8'.  So
the default encoding may not be the user's or programmer's choice.

> +    def add_text_attachment(self, body, filename=None):
> +        """Add a text attachment to the message.
> +
> +        :param body: A text to attach. Can be an unicode string, and it'll be
> +            sent as utf-8, or a byte string, and it'll be sent as 8-bit.

It seems surprising to support bytestrings here.  If these are text
attachments, shouldn't bytestrings come with an encoding?

I guess I'd still like to see a one-shot email command, like

EmailMessage.send(config, to, from, subject, body, attach=None,
                  attach_filename=None)

Yes, it simplifies, but I think it handles 90% of the use cases.

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

iD8DBQFGeSmn0F+nu1YWqI0RAtYvAJ917O/6zVYQ8IQLXAmJb/Wa1OzyXwCeMtaT
UeuY/5C/Icd/V7D0gXWcBeg=
=3M9x
-----END PGP SIGNATURE-----



More information about the bazaar mailing list