[MERGE] An EmailMessage class for bzrlib (v2)

Adeodato Simó dato at net.com.org.es
Mon Jul 9 20:12:11 BST 2007


* Aaron Bentley [Mon, 09 Jul 2007 14:47:38 -0400]:

> Adeodato Simó wrote:
> > Added. I changed the send_email() function in the test to return a
> > function instead, in order to test with different mime_subtypes. Please
> > let me know if that is okay.

> I found it surprising that send_mail took a subtype parameter.  I can
> see that it's convenient, though.

> It's basically surprising that send_email does verification.  Calling it
> send_and_verify would help, I think.

I changed it to verify_message_with_mime_type, thanks for pointing out.

> A common approach would be to move as much code as possible into a
> "mixin" superclass, and then use multiple inheritance,

Hm, I was already sending a new bundle with my proposed change
implemented when this email arrived. How attached are you to the mixin
option? My code basically does:

class EmailMessage(MIMEMultipart.MIMEMultipart):
    def __init__(self, from_address, to_address, subject, body=None):
        MIMEMultipart.MIMEMultipart.__init__(self)
        self._init_message(self, from_address, to_address, subject, body)

    @staticmethod
    def _init_message(msg, from_address, to_address, subject, body=None):

        [... code previously found in __init__ ... ]

        if body is not None:
            if isinstance(msg, EmailMessage):
                msg.add_inline_attachment(body)
            else:
                msg.set_payload(body, encoding)

    @staticmethod
    def send(...):
        if attachment is None:
            # MIMEMultipart not needed
            msg = Message.Message()
            EmailMessage._init_message(msg, ...)
        else:
            msg = EmailMessage(...)
            msg.add_inline_attachment(...)

> > However, along the lines of what Martin proposes, I think it'd be
> > feasible to have the staticmethod to act different whenever attachment
> > is None, creatting a plain email.Message instead of a bzrlib.EmailMessage.

> I think we'd want to retain the address encoding stuff when sending
> non-multipart messages.

As shown above, all that is retained.

Cheers,

-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
Capitalism is the extraordinary belief that the nastiest of men, for the
nastiest of reasons, will somehow work for the benefit of us all.
                -- John Maynard Keynes




More information about the bazaar mailing list