Skip to content

Commit

Permalink
BUG: smtp output: add Content-Disposition header for attachments
Browse files Browse the repository at this point in the history
fixes display of the attachment in mail clients

fixes #2018
  • Loading branch information
Sebastian Wagner committed Aug 18, 2021
1 parent b116139 commit 622ad51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CHANGELOG
#### Outputs
- `intelmq.bots.outputs.mcafee.output_esm_ip`: Fix access to parameters, the bot wrongly used `self.parameters` (by Sebastian Wagner).
- `intelmq.bots.outputs.misp.output_api`: Fix access to parameters, the bot wrongly used `self.parameters` (by Sebastian Wagner).
- `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).

### Documentation
- Various formatting fixes (by Sebastian Wagner).
Expand Down
4 changes: 3 additions & 1 deletion intelmq/bots/outputs/smtp/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def process(self):
if self.text is not None:
msg.attach(MIMEText(self.text.format(ev=event)))
if self.fieldnames:
msg.attach(MIMEText(attachment, 'csv'))
mime_attachment = MIMEText(attachment, 'csv')
mime_attachment.add_header("Content-Disposition", "attachment", filename="events.csv")
msg.attach(mime_attachment)
msg['Subject'] = self.subject.format(ev=event)
msg['From'] = self.mail_from.format(ev=event)
msg['To'] = self.mail_to.format(ev=event)
Expand Down
3 changes: 3 additions & 0 deletions intelmq/tests/bots/outputs/smtp/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def test_event(self):
''')
self.assertEqual({'from_addr': 'myself', 'to_addrs': ['you', 'yourself']},
SENT_MESSAGE[1])
# https://github.com/certtools/intelmq/issues/2018
self.assertIn(('Content-Disposition', 'attachment; filename="events.csv"'),
SENT_MESSAGE[0].get_payload()[1]._headers)

def test_multiple_recipients_event(self):
"""
Expand Down

0 comments on commit 622ad51

Please sign in to comment.