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)
def test_attach_text(): mail = encoding.MailBase() mail.attach_text("This is some text.", 'text/plain') msg = encoding.to_message(mail) assert_equal(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_equal(len(msg.get_payload()), 2) assert encoding.to_string(mail)
def cleanse(inbox, outbox): """ Uses Salmon mail cleansing and canonicalization system to take an input Maildir (or mbox) and replicate the email over into another Maildir. It's used mostly for testing and cleaning. """ error_count = 0 try: inbox = mailbox.mbox(inbox) except IOError: inbox = mailbox.Maildir(inbox, factory=None) outbox = mailbox.Maildir(outbox) for msg in inbox: try: mail = encoding.from_message(msg) outbox.add(encoding.to_string(mail)) except encoding.EncodingError as exc: click.echo("ERROR: %s" % exc) error_count += 1 outbox.close() inbox.close() if error_count > 0: raise SalmonCommandError("TOTAL ERRORS: %s" % error_count) else: click.echo("Completed without errors")
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_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 mail_to_you_is_bouncing(message): reason = message.bounce.error_for_humans() msg = view.respond(locals(), 'mail/you_bounced.msg', From='*****@*****.**', To=message.bounce.original['to'], Subject="Email to you is bouncing.") if message.bounce.report: for report in message.bounce.report: msg.attach('bounce_report.msg', content_type='text/plain', data=encoding.to_string(report), disposition='attachment') if message.bounce.notification: msg.attach('notification_report.msg', content_type='text/plain', data=encoding.to_string(message.bounce.notification), disposition='attachment') return msg
def command(input, output): error_count = 0 try: inbox = mailbox.mbox(input) except IOError: inbox = mailbox.Maildir(input, factory=None) outbox = mailbox.Maildir(output) for msg in inbox: try: mail = encoding.from_message(msg) outbox.add(encoding.to_string(mail)) except encoding.EncodingError, exc: print "ERROR: ", exc error_count += 1
def command(input, output): error_count = 0 try: inbox = mailbox.mbox(input) except IOError: inbox = mailbox.Maildir(input, factory=None) outbox = mailbox.Maildir(output) for msg in inbox: try: mail = encoding.from_message(msg) outbox.add(encoding.to_string(mail)) except encoding.EncodingError as exc: print("ERROR: %s" % exc) error_count += 1 outbox.close() inbox.close() print("TOTAL ERRORS: %s" % error_count)
def cleanse_command(input=None, output=None): """ Uses Salmon mail cleansing and canonicalization system to take an input maildir (or mbox) and replicate the email over into another maildir. It's used mostly for testing and cleaning. """ error_count = 0 try: inbox = mailbox.mbox(input) except IOError: inbox = mailbox.Maildir(input, factory=None) outbox = mailbox.Maildir(output) for msg in inbox: try: mail = encoding.from_message(msg) outbox.add(encoding.to_string(mail)) except encoding.EncodingError, exc: print "ERROR: ", exc error_count += 1
def __str__(self): """ Converts this to a string usable for storage into a queue or transmission. """ return encoding.to_string(self.Email)
def __str__(self): """ Converts this to a string usable for storage into a queue or transmission. """ return encoding.to_string(self.base)