@@ -1689,6 +1689,40 @@ def test_utils_quote_unquote(self):
16891689 filename = 'foo\\ wacky"name' )
16901690 eq (msg .get_filename (), 'foo\\ wacky"name' )
16911691
1692+ def test_get_body_encoding_with_bogus_charset (self ):
1693+ charset = Charset ('not a charset' )
1694+ self .assertEqual (charset .get_body_encoding (), 'base64' )
1695+
1696+ def test_get_body_encoding_with_uppercase_charset (self ):
1697+ eq = self .assertEqual
1698+ msg = Message ()
1699+ msg ['Content-Type' ] = 'text/plain; charset=UTF-8'
1700+ eq (msg ['content-type' ], 'text/plain; charset=UTF-8' )
1701+ charsets = msg .get_charsets ()
1702+ eq (len (charsets ), 1 )
1703+ eq (charsets [0 ], 'utf-8' )
1704+ charset = Charset (charsets [0 ])
1705+ eq (charset .get_body_encoding (), 'base64' )
1706+ msg .set_payload ('hello world' , charset = charset )
1707+ eq (msg .get_payload (), 'hello world' )
1708+ eq (msg ['content-transfer-encoding' ], 'base64' )
1709+ # Try another one
1710+ msg = Message ()
1711+ msg ['Content-Type' ] = 'text/plain; charset="US-ASCII"'
1712+ charsets = msg .get_charsets ()
1713+ eq (len (charsets ), 1 )
1714+ eq (charsets [0 ], 'us-ascii' )
1715+ charset = Charset (charsets [0 ])
1716+ eq (charset .get_body_encoding (), Encoders .encode_7or8bit )
1717+ msg .set_payload ('hello world' , charset = charset )
1718+ eq (msg .get_payload (), 'hello world' )
1719+ eq (msg ['content-transfer-encoding' ], '7bit' )
1720+
1721+ def test_charsets_case_insensitive (self ):
1722+ lc = Charset ('us-ascii' )
1723+ uc = Charset ('US-ASCII' )
1724+ self .assertEqual (lc .get_body_encoding (), uc .get_body_encoding ())
1725+
16921726
16931727
16941728# Test the iterator/generators
0 commit comments