'Attaches a file with the given filename and content. The filename can
be omitted and the mimetype is guessed, if not provided.
If the first parameter is a MIMEBase subclass it is inserted directly
into the resulting message attachments.'

def attach(self, filename=None, content=None, mimetype=None):

    if isinstance(filename, MIMEBase):
        assert (content == mimetype == None)
        self.attachments.append(filename)
    else:
        assert (content is not None)
        self.attachments.append((filename, content, mimetype))
