|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 | + |
| 4 | +from odoo import tools |
| 5 | +from odoo.addons.base.tests import test_mail_examples |
| 6 | +from odoo.tests import tagged |
| 7 | +from odoo.tests.common import TransactionCase |
| 8 | + |
| 9 | + |
| 10 | +@tagged('mail_server') |
| 11 | +class TestIrMailServer(TransactionCase): |
| 12 | + |
| 13 | + def test_mail_body(self): |
| 14 | + bodies = [ |
| 15 | + 'content', |
| 16 | + '<p>content</p>', |
| 17 | + '<head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"></head><body><p>content</p></body>', |
| 18 | + test_mail_examples.MISC_HTML_SOURCE, |
| 19 | + test_mail_examples.QUOTE_THUNDERBIRD_HTML, |
| 20 | + ] |
| 21 | + expected_list = [ |
| 22 | + 'content', |
| 23 | + 'content', |
| 24 | + 'content', |
| 25 | + "test1\n\n**test2**\n\n_test3_\n\n_test4_\n\n~~test5~~\n\ntest6\n\n * test7\n * test8\n\n 1. test9\n 2. test10\n\n> test11\n\n> > test12\n>>\n\n>> \n>\n\n[google](http://google.com) [test link](javascript:alert\('malicious code'\))", |
| 26 | + 'On 01/05/2016 10:24 AM, Raoul Poilvache wrote: \n\n> **_Test reply. The suite._** \n>\n>\n> \n>\n>\n> \-- \n>\n>\n> Raoul Poilvache\n\nTop cool !!! \n \n\n \n \n -- \n Raoul Poilvache\n ', |
| 27 | + ] |
| 28 | + for body, expected in zip(bodies, expected_list): |
| 29 | + message = self.env['ir.mail_server'].build_email( |
| 30 | + |
| 31 | + |
| 32 | + body=body, |
| 33 | + subject='Subject', |
| 34 | + subtype='html', |
| 35 | + ) |
| 36 | + body_alternative = False |
| 37 | + for part in message.walk(): |
| 38 | + if part.get_content_maintype() == 'multipart': |
| 39 | + continue # skip container |
| 40 | + if part.get_content_type() == 'text/plain': |
| 41 | + if not part.get_payload(): |
| 42 | + continue |
| 43 | + body_alternative = tools.ustr(part.get_content()) |
| 44 | + # remove ending new lines as it just adds noise |
| 45 | + body_alternative = body_alternative.strip('\n') |
| 46 | + self.assertEqual(body_alternative, expected) |
0 commit comments