# HG changeset patch # User Thomas De Schampheleire # Date 1518085382 -3600 # Node ID c6a063723eb2b67a8e32a83a5aa8895826448e3d # Parent e12c4a3ce99623db52fa0698f758708196e40983 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. diff -r e12c4a3ce996 -r c6a063723eb2 kallithea/lib/celerylib/tasks.py --- 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. diff -r e12c4a3ce996 -r c6a063723eb2 kallithea/tests/other/test_mail.py --- 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 = []