def __init__(self, To=None, From=None, Subject=None, Body=None, Html=None): self.Body = Body self.Html = Html self.base = encoding.MailBase([('To', To), ('From', From), ('Subject', Subject)]) self.multipart = self.Body and self.Html self.attachments = []
def test_MailBase(): the_subject = u'p\xf6stal' m = encoding.MailBase() m['To'] = "testing@localhost" m['Subject'] = the_subject assert m['To'] == "testing@localhost" assert m['TO'] == m['To'] assert m['to'] == m['To'] assert m['Subject'] == the_subject assert m['subject'] == m['Subject'] assert m['sUbjeCt'] == m['Subject'] msg = encoding.to_message(m) m2 = encoding.from_message(msg) assert_equal(len(m), len(m2)) for k in m: assert m[k] == m2[k], "%s: %r != %r" % (k, m[k], m2[k]) for k in m.keys(): assert k in m del m[k] assert not k in m
def test_odd_content_type_with_charset(): mail = encoding.MailBase() mail.body = u"p\xf6stal".encode('utf-8') mail.content_encoding['Content-Type'] = ('application/plain', {'charset': 'utf-8'}) msg = encoding.to_string(mail) assert msg
def test_attach_file(): mail = encoding.MailBase() png = open("tests/lamson.png").read() mail.attach_file("lamson.png", png, "image/png", "attachment") msg = encoding.to_message(mail) payload = msg.get_payload(0) assert payload.get_payload(decode=True) == png assert payload.get_filename() == "lamson.png", payload.get_filename()
def test_attach_text(): mail = encoding.MailBase() mail.attach_text("This is some text.", 'text/plain') msg = encoding.to_message(mail) assert msg.get_payload(0).get_payload() == "This is some text." assert encoding.to_string(mail) mail.attach_text("<html><body><p>Hi there.</p></body></html>", "text/html") msg = encoding.to_message(mail) assert len(msg.get_payload()) == 2 assert encoding.to_string(mail)