def test_message_id(): def msgid(thing=None): return thing mailthon.headers.make_msgid = Mock(side_effect=msgid) assert tuple(message_id()) == ('Message-ID', None) assert tuple(message_id('string')) == ('Message-ID', 'string') assert tuple(message_id(idstring=1)) == ('Message-ID', 1)
def email(sender=None, receivers=(), cc=(), bcc=(), subject=None, content=None, encoding='utf8', attachments=()): """ Creates a Collection object with a HTML *content*, and *attachments*. :param content: HTML content. :param encoding: Encoding of the email. :param attachments: List of filenames to attach to the email. """ enclosure = [HTML(content, encoding)] enclosure.extend(Attachment(k) for k in attachments) return Collection(*enclosure, headers=[ headers.subject(subject), headers.sender(sender), headers.to(*receivers), headers.cc(*cc), headers.bcc(*bcc), headers.date(), headers.message_id(), ])
def email(sender=None, receivers=(), cc=(), bcc=(), subject=None, content=None, encoding='utf8', attachments=()): """ Creates an Envelope object with a HTML *content*. :param content: HTML content. :param encoding: Encoding of the email. :param attachments: List of filenames to attach to the email. """ html = [HTML(content, encoding)] files = [Attachment(k) for k in attachments] return Envelope( headers=[ headers.subject(subject), headers.sender(sender), headers.to(*receivers), headers.cc(*cc), headers.bcc(*bcc), headers.date(), headers.message_id(), ], enclosure=(html + files), )