From: Barry Warsaw Date: Tue, 17 Jan 2006 04:34:54 +0000 (+0000) Subject: SF bug #1403349 solution for email 2.5; some MUAs use the 'file' parameter X-Git-Tag: v2.3.6c1~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e71930f410922cc2a730cba91db1a78a500b8cf;p=thirdparty%2FPython%2Fcpython.git SF bug #1403349 solution for email 2.5; some MUAs use the 'file' parameter name in the Content-Distribution header, so Message.get_filename() should fall back to using that. Will port both to email 3.0 and Python 2.5 trunk. Also, bump the email package version to 2.5.7 for eventual release. Of course, add a test case too. XXX Need to update the documentation. --- diff --git a/Lib/email/Message.py b/Lib/email/Message.py index 13963301b85b..10c2921ea0a2 100644 --- a/Lib/email/Message.py +++ b/Lib/email/Message.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2005 Python Software Foundation +# Copyright (C) 2001-2006 Python Software Foundation # Author: barry@python.org (Barry Warsaw) """Basic message object for the email package object model.""" @@ -718,10 +718,15 @@ 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 = [] filename = self.get_param('filename', missing, 'content-disposition') + if filename is missing: + # Some MUAs use a different parameter name + filename = self.get_param('name', missing, 'content-disposition') if filename is missing: return failobj if isinstance(filename, TupleType): diff --git a/Lib/email/__init__.py b/Lib/email/__init__.py index bc829c25cbca..6bd14870cb42 100644 --- a/Lib/email/__init__.py +++ b/Lib/email/__init__.py @@ -1,10 +1,9 @@ -# Copyright (C) 2001-2005 Python Software Foundation +# Copyright (C) 2001-2006 Python Software Foundation # Author: barry@python.org (Barry Warsaw) -"""A package for parsing, handling, and generating email messages. -""" +"""A package for parsing, handling, and generating email messages.""" -__version__ = '2.5.6' +__version__ = '2.5.7' __all__ = [ 'base64MIME', diff --git a/Lib/email/test/data/msg_41.txt b/Lib/email/test/data/msg_41.txt new file mode 100644 index 000000000000..ae462a61be65 --- /dev/null +++ b/Lib/email/test/data/msg_41.txt @@ -0,0 +1,35 @@ +Return-Path: +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-- + diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index ad16eab91bb2..91cd31494233 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2005 Python Software Foundation +# Copyright (C) 2001-2006 Python Software Foundation # email package unit tests import os @@ -158,6 +158,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_41.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')