Mercurial > kallithea
changeset 7130:c6a063723eb2
email: fix fallback sending to multiple admins
If no recipients are set, emails are sent to all admins and the address
specified in the config file setting 'email_to'.
However, the existing code did not cater for the fact that multiple
addresses could be set there: the setting was treated as a single string and
passed along as-is.
Adapt the code to split the email_to contents on a comma, as this is the
separator expected by backlash.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Thu, 08 Feb 2018 11:23:02 +0100 |
parents | e12c4a3ce996 |
children | 33bd2aa757dd |
files | kallithea/lib/celerylib/tasks.py kallithea/tests/other/test_mail.py |
diffstat | 2 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/celerylib/tasks.py Fri Feb 09 20:19:14 2018 +0100 +++ b/kallithea/lib/celerylib/tasks.py Thu Feb 08 11:23:02 2018 +0100 @@ -265,7 +265,7 @@ recipients = [u.email for u in User.query() .filter(User.admin == True).all()] if email_config.get('email_to') is not None: - recipients += [email_config.get('email_to')] + recipients += email_config.get('email_to').split(',') # If there are still no recipients, there are no admins and no address # configured in email_to, so return.
--- a/kallithea/tests/other/test_mail.py Fri Feb 09 20:19:14 2018 +0100 +++ b/kallithea/tests/other/test_mail.py Thu Feb 08 11:23:02 2018 +0100 @@ -73,6 +73,30 @@ assert body in smtplib_mock.lastmsg assert html_body in smtplib_mock.lastmsg + def test_send_mail_no_recipients_multiple_email_to(self): + mailserver = 'smtp.mailserver.org' + recipients = [] + envelope_from = 'noreply@mailserver.org' + email_to = 'admin@mailserver.org,admin2@example.com' + subject = 'subject' + body = 'body' + html_body = 'html_body' + + config_mock = { + 'smtp_server': mailserver, + 'app_email_from': envelope_from, + 'email_to': email_to, + } + with mock.patch('kallithea.lib.celerylib.tasks.config', config_mock): + kallithea.lib.celerylib.tasks.send_email(recipients, subject, body, html_body) + + assert smtplib_mock.lastdest == set([TEST_USER_ADMIN_EMAIL] + email_to.split(',')) + assert smtplib_mock.lastsender == envelope_from + assert 'From: %s' % envelope_from in smtplib_mock.lastmsg + assert 'Subject: %s' % subject in smtplib_mock.lastmsg + assert body in smtplib_mock.lastmsg + assert html_body in smtplib_mock.lastmsg + def test_send_mail_no_recipients_no_email_to(self): mailserver = 'smtp.mailserver.org' recipients = []