Projet

Général

Profil

0001-emails-force-linebreaks-in-email-footer-17131.patch

Frédéric Péters, 05 juillet 2017 13:33

Télécharger (3,59 ko)

Voir les différences:

Subject: [PATCH] emails: force linebreaks in email footer (#17131)

 tests/test_misc.py   | 18 ++++++++++++++++++
 tests/utilities.py   |  1 +
 wcs/qommon/emails.py |  8 +++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)
tests/test_misc.py
20 20
from wcs.qommon import evalutils
21 21
from wcs.qommon.http_request import HTTPRequest
22 22
from wcs.qommon.backoffice.listing import pagination_links
23
from wcs.qommon.emails import email as send_email, docutils
23 24

  
24 25
from utilities import get_app, create_temporary_pub, clean_temporary_pub
25 26

  
......
278 279
            '1', '…', '8', '9', '10', '11', '12', '13', '14', '…', '50', '(101-110/500)', 'Per page: ', '10', '20', '50', '100']
279 280
    assert get_texts(pagination_links(100, 20, 500)) == [
280 281
            '1', '…', '3', '4', '5', '6', '7', '8', '9', '…', '25', '(101-120/500)', 'Per page: ', '10', '20', '50', '100']
282

  
283
def test_email_signature_plain(emails):
284
    pub = create_temporary_pub()
285
    pub.cfg['emails'] = {'footer': 'Footer\nText'}
286
    send_email('test', mail_body='Hello', email_rcpt='test@localhost', want_html=False)
287
    assert not emails.emails['test']['msg'].is_multipart()
288
    assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()
289

  
290
@pytest.mark.skipif('docutils is None')
291
def test_email_signature_rst(emails):
292
    pub = create_temporary_pub()
293
    pub.cfg['emails'] = {'footer': 'Footer\nText'}
294
    send_email('test', mail_body='Hello', email_rcpt='test@localhost')
295
    assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
296
    assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
297
    assert 'Footer\nText' in emails.emails['test']['msg'].get_payload()[0].get_payload()
298
    assert '>Footer</div>' in emails.emails['test']['msg'].get_payload()[1].get_payload()
tests/utilities.py
193 193
                        'from': msg_from,
194 194
                        'to': email.header.decode_header(msg['To'])[0][0],
195 195
                        'payload': payload,
196
                        'msg': msg,
196 197
                        }
197 198
                self.emails[subject]['email_rcpt'] = rcpts
198 199

  
wcs/qommon/emails.py
113 113
    if want_html:
114 114
        try:
115 115
            if footer:
116
                rst_mail_body = mail_body + '\n\n--------\n\n' + footer
116
                rst_footer = footer
117
                if not rst_footer.startswith('|') and '\n' in rst_footer:
118
                    # unless the footer text is already formatted like a block
119
                    # of lines, add pipes to give it appropriate multilines
120
                    # formatting.
121
                    rst_footer = '\n'.join(['| ' + x for x in rst_footer.splitlines()])
122
                rst_mail_body = mail_body + '\n\n--------\n\n' + rst_footer
117 123
            else:
118 124
                rst_mail_body = mail_body
119 125
            htmlmail, pub = docutils.core.publish_programmatically(
120
-