def test_add_header_multipart_alternative(): msg = email.message_from_string("""Content-Type: multipart/alternative; boundary="foo" Content-Transfer-Encoding: 7bit Test-Header: Test-Value --foo Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii bold --foo Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> </head> <body style="word-wrap: break-word;" class=""> <b class="">bold</b> </body> </html> """) new_msg = add_header(msg, "text header", "html header") assert "Test-Header: Test-Value" in new_msg.as_string() assert "<table" in new_msg.as_string() assert "</table>" in new_msg.as_string() assert "html header" in new_msg.as_string() assert "text header" in new_msg.as_string()
def test_add_header_plain_text(): msg = email.message_from_string( """Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Test-Header: Test-Value coucou """) new_msg = add_header(msg, "text header", "html header") assert "text header" in new_msg.as_string() assert "html header" not in new_msg.as_string()
def test_add_header_html(): msg = email.message_from_string( """Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Test-Header: Test-Value <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> </head> <body style="word-wrap: break-word;" class=""> <b class="">bold</b> </body> </html> """) new_msg = add_header(msg, "text header", "html header") assert "Test-Header: Test-Value" in new_msg.as_string() assert "<table" in new_msg.as_string() assert "</table>" in new_msg.as_string() assert "html header" in new_msg.as_string() assert "text header" not in new_msg.as_string()