Skip to content

Commit 97dfad7

Browse files
committed
#21079: is_attachment now looks only at the value, ignoring parameters.
1 parent 9833fcb commit 97dfad7

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Lib/email/message.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,7 @@ def __init__(self, policy=None):
941941
@property
942942
def is_attachment(self):
943943
c_d = self.get('content-disposition')
944-
if c_d is None:
945-
return False
946-
return c_d.lower() == 'attachment'
944+
return False if c_d is None else c_d.content_disposition == 'attachment'
947945

948946
def _find_body(self, part, preferencelist):
949947
if part.is_attachment:

Lib/test/test_email/test_message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ def test_is_attachment(self):
729729
self.assertTrue(m.is_attachment)
730730
m.replace_header('Content-Disposition', 'AtTachMent')
731731
self.assertTrue(m.is_attachment)
732-
732+
m.set_param('filename', 'abc.png', 'Content-Disposition')
733+
self.assertTrue(m.is_attachment)
733734

734735

735736
class TestEmailMessage(TestEmailMessageBase, TestEmailBase):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Core and Builtins
3232
Library
3333
-------
3434

35+
- Issue #21079: Fix email.message.EmailMessage.is_attachment to return the
36+
correct result when the header has parameters as well as a value.
37+
3538
- Issue #22247: Add NNTPError to nntplib.__all__.
3639

3740
- Issue #4180: The warnings registries are now reset when the filters

0 commit comments

Comments
 (0)