diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index 5aec91b00e7..eb8f5cc643a 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -20,6 +20,7 @@ from . import test_ir_attachment from . import test_ir_cron from . import test_ir_http from . import test_ir_filters +from . import test_ir_mail_server from . import test_ir_model from . import test_ir_sequence from . import test_ir_sequence_date_range @@ -51,4 +52,3 @@ from . import test_form_create from . import test_cloc from . import test_profiler from . import test_pdf -from . import test_ir_mail_server diff --git a/odoo/addons/base/tests/test_ir_mail_server.py b/odoo/addons/base/tests/test_ir_mail_server.py index 2b66984d550..65d51f09c8f 100644 --- a/odoo/addons/base/tests/test_ir_mail_server.py +++ b/odoo/addons/base/tests/test_ir_mail_server.py @@ -3,10 +3,15 @@ from unittest.mock import patch +from odoo import tools +from odoo.addons.base.tests import test_mail_examples from odoo.addons.base.tests.common import MockSmtplibCase +from odoo.tests import tagged from odoo.tests.common import TransactionCase from odoo.tools import mute_logger + +@tagged('mail_server') class TestIrMailServer(TransactionCase, MockSmtplibCase): def setUp(self): @@ -48,6 +53,41 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase): for email, from_filter in tests: self.assertFalse(match_from_filter(email, from_filter)) + def test_mail_body(self): + bodies = [ + 'content', + '
content
', + 'content
', + test_mail_examples.MISC_HTML_SOURCE, + test_mail_examples.QUOTE_THUNDERBIRD_HTML, + ] + expected_list = [ + 'content', + 'content', + 'content', + "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'\))", + '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 ', + ] + for body, expected in zip(bodies, expected_list): + message = self.env['ir.mail_server'].build_email( + 'john.doe@from.example.com', + 'destinataire@to.example.com', + body=body, + subject='Subject', + subtype='html', + ) + body_alternative = False + for part in message.walk(): + if part.get_content_maintype() == 'multipart': + continue # skip container + if part.get_content_type() == 'text/plain': + if not part.get_payload(): + continue + body_alternative = tools.ustr(part.get_content()) + # remove ending new lines as it just adds noise + body_alternative = body_alternative.strip('\n') + self.assertEqual(body_alternative, expected) + @mute_logger('odoo.models.unlink') def test_mail_server_priorities(self): """Test if we choose the right mail server to send an email.