emails: force linebreaks in email footer (#17131)

This commit is contained in:
Frédéric Péters 2017-06-23 09:33:35 +02:00
parent 91e1614352
commit 042fd9b28a
3 changed files with 26 additions and 1 deletions

View File

@ -20,6 +20,7 @@ from wcs.scripts import Script
from wcs.qommon import evalutils
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.backoffice.listing import pagination_links
from wcs.qommon.emails import email as send_email, docutils
from utilities import get_app, create_temporary_pub, clean_temporary_pub
@ -278,3 +279,20 @@ def test_pagination():
'1', '…', '8', '9', '10', '11', '12', '13', '14', '…', '50', '(101-110/500)', 'Per page: ', '10', '20', '50', '100']
assert get_texts(pagination_links(100, 20, 500)) == [
'1', '…', '3', '4', '5', '6', '7', '8', '9', '…', '25', '(101-120/500)', 'Per page: ', '10', '20', '50', '100']
def test_email_signature_plain(emails):
pub = create_temporary_pub()
pub.cfg['emails'] = {'footer': 'Footer\nText'}
send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
assert not emails.emails['test']['msg'].is_multipart()
assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()
@pytest.mark.skipif('docutils is None')
def test_email_signature_rst(emails):
pub = create_temporary_pub()
pub.cfg['emails'] = {'footer': 'Footer\nText'}
send_email('test', mail_body='Hello', email_rcpt='test@localhost')
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload()
assert '>Footer</div>' in emails.emails['test']['msg'].get_payload()[1].get_payload()

View File

@ -193,6 +193,7 @@ class EmailsMocking(object):
'from': msg_from,
'to': email.header.decode_header(msg['To'])[0][0],
'payload': payload,
'msg': msg,
}
self.emails[subject]['email_rcpt'] = rcpts

View File

@ -113,7 +113,13 @@ def email(subject, mail_body, email_rcpt, replyto = None, bcc = None,
if want_html:
try:
if footer:
rst_mail_body = mail_body + '\n\n--------\n\n' + footer
rst_footer = footer
if not rst_footer.startswith('|') and '\n' in rst_footer:
# unless the footer text is already formatted like a block
# of lines, add pipes to give it appropriate multilines
# formatting.
rst_footer = '\n'.join(['| ' + x for x in rst_footer.splitlines()])
rst_mail_body = mail_body + '\n\n--------\n\n' + rst_footer
else:
rst_mail_body = mail_body
htmlmail, pub = docutils.core.publish_programmatically(