Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle huge single message email notifications #288

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Bug fixes
* Add timestamp in single message emails
(`#284 <https://github.com/fedora-infra/fmn/pull/287>`_).

* Limit single message emails to 500K characters to ensure multi-MB emails
don't get stuck in the message queue
(`#288 <https://github.com/fedora-infra/fmn/pull/288>`_).

v2.0.2
======
Expand Down
6 changes: 6 additions & 0 deletions fmn/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ def email(message, recipient):
except Exception:
_log.exception('fedmsg.meta.msg2link failed to handle %r', message)

if len(content) >= 500000:
# This email is enormous, too large to be sent. This happens if fedmsg_meta
# did something silly in its msg2long_form implementation.
content = (u'This message was too large to be sent!\n'
u'The message ID was: {}\n\n').format(message['msg_id'])

# Since we do simple text email, adding the footer to the content
# before setting the payload.
footer = config.app_conf.get('fmn.email.footer', u'')
Expand Down
23 changes: 23 additions & 0 deletions fmn/tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ def test_email(self):
actual = formatters.email(self.message, self.recipient)
self.assertEqual(expected, actual)

@mock.patch('fmn.formatters.fedmsg.meta.msg2long_form', mock.Mock(return_value='a'*500000))
def test_email_too_big(self):
"""Assert huge single message emails are handled gracefully."""
expected = (
'Precedence: Bulk\n'
'Auto-Submitted: auto-generated\n'
'From: notifications@fedoraproject.org\n'
'To: jeremy@jcline.org\n'
'X-Fedmsg-Topic: org.fedoraproject.dev.fmn.filter.update\n'
'X-Fedmsg-Category: fmn\n'
'X-Fedmsg-Username: jcline\n'
'X-Fedmsg-Num-Packages: 0\n'
'Subject: jcline updated the rules on a fmn email filter\n'
'MIME-Version: 1.0\n'
'Content-Type: text/plain; charset="utf-8"\n'
'Content-Transfer-Encoding: base64\n\n'
'VGhpcyBtZXNzYWdlIHdhcyB0b28gbGFyZ2UgdG8gYmUgc2VudCEKVGhlIG1lc3NhZ2UgSUQgd2Fz\n'
'OiAyMDE3LTZhYTcxZDViLWZiZTQtNDllNy1hZmRkLWFmY2YwZDIyODAyYgoK\n'
)

actual = formatters.email(self.message, self.recipient)
self.assertEqual(expected, actual)

@mock.patch.dict('fmn.formatters.config.app_conf', {'fmn.email.subject_prefix': 'PREFIX: '})
def test_subject_prefix(self):
"""Assert the subject prefix is added if configured."""
Expand Down