Skip to content

Commit 4e71930

Browse files
committed
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.
1 parent b6d857a commit 4e71930

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

Lib/email/Message.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2001-2005 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
# Author: barry@python.org (Barry Warsaw)
33

44
"""Basic message object for the email package object model."""
@@ -718,10 +718,15 @@ def get_filename(self, failobj=None):
718718
"""Return the filename associated with the payload if present.
719719
720720
The filename is extracted from the Content-Disposition header's
721-
`filename' parameter, and it is unquoted.
721+
`filename' parameter, and it is unquoted. If that header is missing
722+
the `filename' parameter, this method falls back to looking for the
723+
`name' parameter.
722724
"""
723725
missing = []
724726
filename = self.get_param('filename', missing, 'content-disposition')
727+
if filename is missing:
728+
# Some MUAs use a different parameter name
729+
filename = self.get_param('name', missing, 'content-disposition')
725730
if filename is missing:
726731
return failobj
727732
if isinstance(filename, TupleType):

Lib/email/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Copyright (C) 2001-2005 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
# Author: barry@python.org (Barry Warsaw)
33

4-
"""A package for parsing, handling, and generating email messages.
5-
"""
4+
"""A package for parsing, handling, and generating email messages."""
65

7-
__version__ = '2.5.6'
6+
__version__ = '2.5.7'
87

98
__all__ = [
109
'base64MIME',

Lib/email/test/data/msg_41.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Return-Path: <barry@python.org>
2+
Delivered-To: barry@python.org
3+
Received: by mail.python.org (Postfix, from userid 889)
4+
id C2BF0D37C6; Tue, 11 Sep 2001 00:05:05 -0400 (EDT)
5+
MIME-Version: 1.0
6+
Content-Type: multipart/mixed; boundary="h90VIIIKmx"
7+
Content-Transfer-Encoding: 7bit
8+
Message-ID: <15261.36209.358846.118674@anthem.python.org>
9+
From: barry@python.org (Barry A. Warsaw)
10+
To: barry@python.org
11+
Subject: a simple multipart
12+
Date: Tue, 11 Sep 2001 00:05:05 -0400
13+
X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
14+
X-Attribution: BAW
15+
X-Oblique-Strategy: Make a door into a window
16+
17+
18+
--h90VIIIKmx
19+
Content-Type: text/plain
20+
Content-Disposition: inline; name="msg.txt"
21+
Content-Transfer-Encoding: 7bit
22+
23+
a simple kind of mirror
24+
to reflect upon our own
25+
26+
--h90VIIIKmx
27+
Content-Type: text/plain
28+
Content-Disposition: inline; name="msg.txt"
29+
Content-Transfer-Encoding: 7bit
30+
31+
a simple kind of mirror
32+
to reflect upon our own
33+
34+
--h90VIIIKmx--
35+

Lib/email/test/test_email.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2001-2005 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
# email package unit tests
33

44
import os
@@ -158,6 +158,13 @@ def test_get_filename(self):
158158
subpart = msg.get_payload(1)
159159
eq(subpart.get_filename(), 'dingusfish.gif')
160160

161+
def test_get_filename_with_name_parameter(self):
162+
eq = self.assertEqual
163+
164+
msg = self._msgobj('msg_41.txt')
165+
filenames = [p.get_filename() for p in msg.get_payload()]
166+
eq(filenames, ['msg.txt', 'msg.txt'])
167+
161168
def test_get_boundary(self):
162169
eq = self.assertEqual
163170
msg = self._msgobj('msg_07.txt')

0 commit comments

Comments
 (0)