Ported 42075 from release23-maint branch.
authorBarry Warsaw <barry@python.org>
Tue, 17 Jan 2006 04:49:07 +0000 (04:49 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 17 Jan 2006 04:49:07 +0000 (04:49 +0000)
SF bug #1403349 solution for email 3.0; some MUAs use the 'file' parameter
name in the Content-Distribution header, so Message.get_filename() should fall
back to using that.  Will port to the Python 2.5 trunk.

Also, bump the email package version to 3.0.1 for eventual release.  Of
course, add a test case too.

XXX Need to update the documentation.

Lib/email/Message.py
Lib/email/__init__.py
Lib/email/test/data/msg_44.txt [new file with mode: 0644]
Lib/email/test/test_email.py

index b466f396d92a03ae380e62a6371447cf425c59b9..88fd78617fd2d91c71156b916107e1790f0db00b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2006 Python Software Foundation
 # Author: Barry Warsaw
 # Contact: email-sig@python.org
 
@@ -701,10 +701,14 @@ class Message:
         """Return the filename associated with the payload if present.
 
         The filename is extracted from the Content-Disposition header's
-        `filename' parameter, and it is unquoted.
+        `filename' parameter, and it is unquoted.  If that header is missing
+        the `filename' parameter, this method falls back to looking for the
+        `name' parameter.
         """
         missing = object()
         filename = self.get_param('filename', missing, 'content-disposition')
+        if filename is missing:
+            filename = self.get_param('name', missing, 'content-disposition')
         if filename is missing:
             return failobj
         return Utils.collapse_rfc2231_value(filename).strip()
index e622b3f99582d7431e62e79b4df3d89f2cfe33ce..e5c0e2e9d582f28a2212231a2e7a828fd59def79 100644 (file)
@@ -1,10 +1,10 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2006 Python Software Foundation
 # Author: Barry Warsaw
 # Contact: email-sig@python.org
 
 """A package for parsing, handling, and generating email messages."""
 
-__version__ = '3.0+'
+__version__ = '3.0.1'
 
 __all__ = [
     'base64MIME',
diff --git a/Lib/email/test/data/msg_44.txt b/Lib/email/test/data/msg_44.txt
new file mode 100644 (file)
index 0000000..ae462a6
--- /dev/null
@@ -0,0 +1,35 @@
+Return-Path: <barry@python.org>
+Delivered-To: barry@python.org
+Received: by mail.python.org (Postfix, from userid 889)
+       id C2BF0D37C6; Tue, 11 Sep 2001 00:05:05 -0400 (EDT)
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="h90VIIIKmx"
+Content-Transfer-Encoding: 7bit
+Message-ID: <15261.36209.358846.118674@anthem.python.org>
+From: barry@python.org (Barry A. Warsaw)
+To: barry@python.org
+Subject: a simple multipart
+Date: Tue, 11 Sep 2001 00:05:05 -0400
+X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
+X-Attribution: BAW
+X-Oblique-Strategy: Make a door into a window
+
+
+--h90VIIIKmx
+Content-Type: text/plain
+Content-Disposition: inline; name="msg.txt"
+Content-Transfer-Encoding: 7bit
+
+a simple kind of mirror
+to reflect upon our own
+
+--h90VIIIKmx
+Content-Type: text/plain
+Content-Disposition: inline; name="msg.txt"
+Content-Transfer-Encoding: 7bit
+
+a simple kind of mirror
+to reflect upon our own
+
+--h90VIIIKmx--
+
index 2f184fd56111600bf3e466fe65fe4b6e4164a6d8..c78e2fd4a5cba63bf06b882fe9cdfee1d98ec87d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2006 Python Software Foundation
 # Contact: email-sig@python.org
 # email package unit tests
 
@@ -147,6 +147,13 @@ class TestMessageAPI(TestEmailBase):
         subpart = msg.get_payload(1)
         eq(subpart.get_filename(), 'dingusfish.gif')
 
+    def test_get_filename_with_name_parameter(self):
+        eq = self.assertEqual
+
+        msg = self._msgobj('msg_44.txt')
+        filenames = [p.get_filename() for p in msg.get_payload()]
+        eq(filenames, ['msg.txt', 'msg.txt'])
+
     def test_get_boundary(self):
         eq = self.assertEqual
         msg = self._msgobj('msg_07.txt')