class TestFromMangling(unittest.TestCase): def setUp(self): self.msg = Message() self.msg['From'] = '*****@*****.**' self.msg.add_payload("""\ From the desk of A.A.A.: Blah blah blah """) def test_mangled_from(self): s = StringIO() g = Generator(s, mangle_from_=1) g(self.msg) self.assertEqual( s.getvalue(), """\ From: [email protected] >From the desk of A.A.A.: Blah blah blah """) def test_dont_mangle_from(self): s = StringIO() g = Generator(s, mangle_from_=0) g(self.msg) self.assertEqual( s.getvalue(), """\ From: [email protected] From the desk of A.A.A.: Blah blah blah """)
class TestFromMangling(unittest.TestCase): def setUp(self): self.msg = Message() self.msg['From'] = '*****@*****.**' self.msg.add_payload("""\ From the desk of A.A.A.: Blah blah blah """) def test_mangled_from(self): s = StringIO() g = Generator(s, mangle_from_=1) g(self.msg) self.assertEqual(s.getvalue(), """\ From: [email protected] >From the desk of A.A.A.: Blah blah blah """) def test_dont_mangle_from(self): s = StringIO() g = Generator(s, mangle_from_=0) g(self.msg) self.assertEqual(s.getvalue(), """\ From: [email protected] From the desk of A.A.A.: Blah blah blah """)
def test_generate(self): # First craft the message to be encapsulated m = Message() m['Subject'] = 'An enclosed message' m.add_payload('Here is the body of the message.\n') r = MIMEMessage(m) r['Subject'] = 'The enclosing message' s = StringIO() g = Generator(s) g(r) self.assertEqual(s.getvalue(), """\ Content-Type: message/rfc822 MIME-Version: 1.0 Subject: The enclosing message Subject: An enclosed message Here is the body of the message. """)
def test_generate(self): # First craft the message to be encapsulated m = Message() m['Subject'] = 'An enclosed message' m.add_payload('Here is the body of the message.\n') r = MIMEMessage(m) r['Subject'] = 'The enclosing message' s = StringIO() g = Generator(s) g(r) self.assertEqual( s.getvalue(), """\ Content-Type: message/rfc822 MIME-Version: 1.0 Subject: The enclosing message Subject: An enclosed message Here is the body of the message. """)
def test_epilogue(self): fp = openfile('msg_21.txt') try: text = fp.read() finally: fp.close() msg = Message() msg['From'] = '*****@*****.**' msg['To'] = '*****@*****.**' msg['Subject'] = 'Test' msg.preamble = 'MIME message\n' msg.epilogue = 'End of MIME message\n' msg1 = MIMEText('One') msg2 = MIMEText('Two') msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY') msg.add_payload(msg1) msg.add_payload(msg2) sfp = StringIO() g = Generator(sfp) g(msg) self.assertEqual(sfp.getvalue(), text)
# Copyright (C) 2001 Python Software Foundation