You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bo...@apache.org on 2017/01/07 17:01:31 UTC
incubator-airflow git commit: [AIRFLOW-665] Fix email attachments
Repository: incubator-airflow
Updated Branches:
refs/heads/master a6b148149 -> 9a7801d4e
[AIRFLOW-665] Fix email attachments
Content-Disposition must be set separately on
the MIMEApplication. Passing it to the
constructor just puts it in the Content-Type header.
Closes #1916 from dgies/master
Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/9a7801d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/9a7801d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/9a7801d4
Branch: refs/heads/master
Commit: 9a7801d4ee792372a717e9b1da6daceecb9c3d68
Parents: a6b1481
Author: Daniel Gies <dg...@pandora.com>
Authored: Sat Jan 7 18:00:36 2017 +0100
Committer: Bolke de Bruin <bo...@xs4all.nl>
Committed: Sat Jan 7 18:00:57 2017 +0100
----------------------------------------------------------------------
airflow/utils/email.py | 7 ++++---
tests/core.py | 4 ++++
2 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/9a7801d4/airflow/utils/email.py
----------------------------------------------------------------------
diff --git a/airflow/utils/email.py b/airflow/utils/email.py
index f55fe10..ab3b244 100644
--- a/airflow/utils/email.py
+++ b/airflow/utils/email.py
@@ -76,11 +76,12 @@ def send_email_smtp(to, subject, html_content, files=None, dryrun=False, cc=None
for fname in files or []:
basename = os.path.basename(fname)
with open(fname, "rb") as f:
- msg.attach(MIMEApplication(
+ part = MIMEApplication(
f.read(),
- Content_Disposition='attachment; filename="%s"' % basename,
Name=basename
- ))
+ )
+ part['Content-Disposition'] = 'attachment; filename="%s"' % basename
+ msg.attach(part)
send_MIME_email(SMTP_MAIL_FROM, recipients, msg, dryrun)
http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/9a7801d4/tests/core.py
----------------------------------------------------------------------
diff --git a/tests/core.py b/tests/core.py
index da6f597..bcc7840 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -2053,6 +2053,8 @@ class EmailSmtpTest(unittest.TestCase):
assert msg['Subject'] == 'subject'
assert msg['From'] == configuration.get('smtp', 'SMTP_MAIL_FROM')
assert len(msg.get_payload()) == 2
+ assert msg.get_payload()[-1].get(u'Content-Disposition') == \
+ u'attachment; filename="' + os.path.basename(attachment.name) + '"'
mimeapp = MIMEApplication('attachment')
assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
@@ -2070,6 +2072,8 @@ class EmailSmtpTest(unittest.TestCase):
assert msg['Subject'] == 'subject'
assert msg['From'] == configuration.get('smtp', 'SMTP_MAIL_FROM')
assert len(msg.get_payload()) == 2
+ assert msg.get_payload()[-1].get(u'Content-Disposition') == \
+ u'attachment; filename="' + os.path.basename(attachment.name) + '"'
mimeapp = MIMEApplication('attachment')
assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()