[Python-checkins] python/dist/src/Lib/email Message.py, 1.32.10.6, 1.32.10.7 __init__.py, 1.29.10.2, 1.29.10.3

bwarsaw at users.sourceforge.net bwarsaw at users.sourceforge.net
Fri Apr 29 14:12:04 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31703

Modified Files:
      Tag: release23-maint
	Message.py __init__.py 
Log Message:
get_filename(), get_content_charset(): It's possible that the charset named in
an RFC 2231-style header could be bogus or unknown to Python.  In that case,
we return the the text part of the parameter undecoded.  However, in
get_content_charset(), if that is not ascii, then it is an illegal charset and
so we return failobj.

Test cases and a version bump are included.

Committing this to the Python 2.3 branch because I need to generate an email
2.5.6 release that contains these patches.  I will port these fixes to Python
2.4 and 2.5 for email 3.x.



Index: Message.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Message.py,v
retrieving revision 1.32.10.6
retrieving revision 1.32.10.7
diff -u -d -r1.32.10.6 -r1.32.10.7
--- Message.py	6 Nov 2004 00:14:05 -0000	1.32.10.6
+++ Message.py	29 Apr 2005 12:12:01 -0000	1.32.10.7
@@ -1,8 +1,7 @@
-# Copyright (C) 2001,2002 Python Software Foundation
-# Author: barry at zope.com (Barry Warsaw)
+# Copyright (C) 2001-2005 Python Software Foundation
+# Author: barry at python.org (Barry Warsaw)
 
-"""Basic message object for the email package object model.
-"""
+"""Basic message object for the email package object model."""
 
 import re
 import uu
@@ -728,7 +727,13 @@
         if isinstance(filename, TupleType):
             # It's an RFC 2231 encoded parameter
             newvalue = _unquotevalue(filename)
-            return unicode(newvalue[2], newvalue[0] or 'us-ascii')
+            try:
+                return unicode(newvalue[2], newvalue[0] or 'us-ascii')
+            # LookupError can get raised if the charset isn't known to Python.
+            # UnicodeError can get raised if the encoded text contains a
+            # character not in the charset.
+            except (LookupError, UnicodeError):
+                return newvalue[2]
         else:
             newvalue = _unquotevalue(filename.strip())
             return newvalue
@@ -815,7 +820,18 @@
         if isinstance(charset, TupleType):
             # RFC 2231 encoded, so decode it, and it better end up as ascii.
             pcharset = charset[0] or 'us-ascii'
-            charset = unicode(charset[2], pcharset).encode('us-ascii')
+            try:
+                charset = unicode(charset[2], pcharset).encode('us-ascii')
+            # LookupError can get raised if the charset isn't known to Python.
+            # UnicodeError can get raised if the encoded text contains a
+            # character not in the charset.
+            except (LookupError, UnicodeError):
+                charset = charset[2]
+        # charset characters should be in us-ascii range
+        try:
+            charset = unicode(charset, 'us-ascii').encode('us-ascii')
+        except UnicodeError:
+            return failobj
         # RFC 2046, $4.1.2 says charsets are not case sensitive
         return charset.lower()
 

Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/__init__.py,v
retrieving revision 1.29.10.2
retrieving revision 1.29.10.3
diff -u -d -r1.29.10.2 -r1.29.10.3
--- __init__.py	13 May 2004 22:53:25 -0000	1.29.10.2
+++ __init__.py	29 Apr 2005 12:12:02 -0000	1.29.10.3
@@ -1,10 +1,10 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2005 Python Software Foundation
 # Author: barry at python.org (Barry Warsaw)
 
 """A package for parsing, handling, and generating email messages.
 """
 
-__version__ = '2.5.5'
+__version__ = '2.5.6'
 
 __all__ = [
     'base64MIME',



More information about the Python-checkins mailing list