Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0f28ef

Browse files
committed
Ported 42075 from release23-maint branch.
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.
1 parent 989b69a commit a0f28ef

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

Lib/email/Message.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2001-2004 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
# Author: Barry Warsaw
33
44

@@ -701,10 +701,14 @@ def get_filename(self, failobj=None):
701701
"""Return the filename associated with the payload if present.
702702
703703
The filename is extracted from the Content-Disposition header's
704-
`filename' parameter, and it is unquoted.
704+
`filename' parameter, and it is unquoted. If that header is missing
705+
the `filename' parameter, this method falls back to looking for the
706+
`name' parameter.
705707
"""
706708
missing = object()
707709
filename = self.get_param('filename', missing, 'content-disposition')
710+
if filename is missing:
711+
filename = self.get_param('name', missing, 'content-disposition')
708712
if filename is missing:
709713
return failobj
710714
return Utils.collapse_rfc2231_value(filename).strip()

Lib/email/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Copyright (C) 2001-2004 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
# Author: Barry Warsaw
33
44

55
"""A package for parsing, handling, and generating email messages."""
66

7-
__version__ = '3.0+'
7+
__version__ = '3.0.1'
88

99
__all__ = [
1010
'base64MIME',

Lib/email/test/data/msg_44.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Return-Path: <[email protected]>
2+
Delivered-To: [email protected]
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: <[email protected]>
9+
From: [email protected] (Barry A. Warsaw)
10+
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-2004 Python Software Foundation
1+
# Copyright (C) 2001-2006 Python Software Foundation
22
33
# email package unit tests
44

@@ -147,6 +147,13 @@ def test_get_filename(self):
147147
subpart = msg.get_payload(1)
148148
eq(subpart.get_filename(), 'dingusfish.gif')
149149

150+
def test_get_filename_with_name_parameter(self):
151+
eq = self.assertEqual
152+
153+
msg = self._msgobj('msg_44.txt')
154+
filenames = [p.get_filename() for p in msg.get_payload()]
155+
eq(filenames, ['msg.txt', 'msg.txt'])
156+
150157
def test_get_boundary(self):
151158
eq = self.assertEqual
152159
msg = self._msgobj('msg_07.txt')

0 commit comments

Comments
 (0)