Skip to content

Commit d87ec6a

Browse files
author
Sebastian Wagner
committed
BUG: smtp output: add Content-Disposition header for attachments
fixes display of the attachment in mail clients fixes #2018
1 parent 3b13865 commit d87ec6a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CHANGELOG
4141
#### Outputs
4242
- `intelmq.bots.outputs.mcafee.output_esm_ip`: Fix access to parameters, the bot wrongly used `self.parameters` (by Sebastian Wagner).
4343
- `intelmq.bots.outputs.misp.output_api`: Fix access to parameters, the bot wrongly used `self.parameters` (by Sebastian Wagner).
44+
- `intelmq.bots.outputs.smtp.output`: Add `Content-Disposition`-header to the attachment, fixing the display in Mail Clients as actual attachment (PR#2052 by Sebastian Wagner, fixes #2018).
4445

4546
### Documentation
4647
- Various formatting fixes (by Sebastian Wagner).

intelmq/bots/outputs/smtp/output.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def process(self):
7070
if self.text is not None:
7171
msg.attach(MIMEText(self.text.format(ev=event)))
7272
if self.fieldnames:
73-
msg.attach(MIMEText(attachment, 'csv'))
73+
mime_attachment = MIMEText(attachment, 'csv')
74+
mime_attachment.add_header("Content-Disposition", "attachment", filename="events.csv")
75+
msg.attach(mime_attachment)
7476
msg['Subject'] = self.subject.format(ev=event)
7577
msg['From'] = self.mail_from.format(ev=event)
7678
msg['To'] = self.mail_to.format(ev=event)

intelmq/tests/bots/outputs/smtp/test_output.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def test_event(self):
5151
''')
5252
self.assertEqual({'from_addr': 'myself', 'to_addrs': ['you', 'yourself']},
5353
SENT_MESSAGE[1])
54+
# https://github.com/certtools/intelmq/issues/2018
55+
self.assertIn(('Content-Disposition', 'attachment; filename="events.csv"'),
56+
SENT_MESSAGE[0].get_payload()[1]._headers)
5457

5558
def test_multiple_recipients_event(self):
5659
"""

0 commit comments

Comments
 (0)