Skip to content

Commit ee07cb1

Browse files
committed
get_content_charset(): RFC 2046 $4.1.2 says charsets are not case
sensitive. Coerce the argument to lower case.
1 parent 14fc464 commit ee07cb1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/email/Message.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,17 +760,19 @@ def set_boundary(self, boundary):
760760
def get_content_charset(self, failobj=None):
761761
"""Return the charset parameter of the Content-Type header.
762762
763-
If there is no Content-Type header, or if that header has no charset
764-
parameter, failobj is returned.
763+
The returned string is always coerced to lower case. If there is no
764+
Content-Type header, or if that header has no charset parameter,
765+
failobj is returned.
765766
"""
766767
missing = []
767768
charset = self.get_param('charset', missing)
768769
if charset is missing:
769770
return failobj
770771
if isinstance(charset, TupleType):
771772
# RFC 2231 encoded, so decode it, and it better end up as ascii.
772-
return unicode(charset[2], charset[0]).encode('us-ascii')
773-
return charset
773+
charset = unicode(charset[2], charset[0]).encode('us-ascii')
774+
# RFC 2046, $4.1.2 says charsets are not case sensitive
775+
return charset.lower()
774776

775777
def get_charsets(self, failobj=None):
776778
"""Return a list containing the charset(s) used in this message.

0 commit comments

Comments
 (0)