diff --git a/addons/test_mail/data/test_mail_data.py b/addons/test_mail/data/test_mail_data.py index 6e6626a16a4..20fc50d7223 100644 --- a/addons/test_mail/data/test_mail_data.py +++ b/addons/test_mail/data/test_mail_data.py @@ -1312,3 +1312,24 @@ JVBERi0xLjEKJcKlwrHDqwoKMSAwIG9iagogIDw8IC9UeXBlIC9DYXRhbG9nCiAgICAgL1BhZ2VzIDIg """ PDF_PARSED = b'''%PDF-1.1\n%\xc2\xa5\xc2\xb1\xc3\xab\n\n1 0 obj\n << /Type /Catalog\n /Pages 2 0 R\n >>\nendobj\n\n2 0 obj\n << /Type /Pages\n /Kids [3 0 R]\n /Count 1\n /MediaBox [0 0 300 144]\n >>\nendobj\n\n3 0 obj\n << /Type /Page\n /Parent 2 0 R\n /Resources\n << /Font\n << /F1\n << /Type /Font\n /Subtype /Type1\n /BaseFont /Times-Roman\n >>\n >>\n >>\n /Contents 4 0 R\n >>\nendobj\n\n4 0 obj\n << /Length 55 >>\nstream\n BT\n /F1 18 Tf\n 0 0 Td\n (Hello World) Tj\n ET\nendstream\nendobj\n\nxref\n0 5\n0000000000 65535 f \n0000000018 00000 n \n0000000077 00000 n \n0000000178 00000 n \n0000000457 00000 n \ntrailer\n << /Root 1 0 R\n /Size 5\n >>\nstartxref\n565\n%%EOF\n''' + +THAI_EMAIL_WINDOWS_874 = '''\ +From: Thai Customer +To: "Thai Odoo User" +Subject: =?windows-874?B?4MPX6M2n?= +Thread-Topic: =?windows-874?B?4MPX6M2n?= +Thread-Index: AQHahRQ4qiMBoXtK0U2XwaGg8w9Y9g== +X-MS-Exchange-MessageSentRepresentingType: 1 +Date: Tue, 2 Apr 2024 15:42:24 +0000 +Message-ID: +Content-Language: en-US +X-MS-Has-Attach: +X-MS-Exchange-Organization-SCL: -1 +X-MS-TNEF-Correlator: +X-MS-Exchange-Organization-RecordReviewCfmType: 0 +msip_labels: +Content-Type: text/plain; charset="windows-874" +Content-Transfer-Encoding: quoted-printable +MIME-Version: 1.0 + +=C3=E8=D2=A7=A1=D2=C2=''' diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index cad1fa9c1d7..9c09aa26afe 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -14,7 +14,7 @@ from odoo import exceptions from odoo.addons.mail.models.mail_thread import MailThread from odoo.addons.mail.tests.common import mail_new_test_user, MailCommon from odoo.addons.test_mail.data import test_mail_data -from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE +from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE, THAI_EMAIL_WINDOWS_874 from odoo.addons.test_mail.models.test_mail_models import MailTestGateway from odoo.sql_db import Cursor from odoo.tests import tagged, RecordCapturer @@ -1772,6 +1772,18 @@ class TestMailgateway(MailCommon): content ) + def test_message_windows_874(self): + # Email for Thai customers who use Microsoft email service. + # The charset is windows-874 which isn't natively supported by + # python, check that Odoo is still capable of decoding it. + # windows-874 is the Microsoft equivalent of cp874. + with self.mock_mail_gateway(), \ + RecordCapturer(self.env['mail.test.gateway'], []) as capture: + self.env['mail.thread'].message_process('mail.test.gateway', THAI_EMAIL_WINDOWS_874) + capture.records.ensure_one() + self.assertEqual(capture.records.name, 'เรื่อง') + self.assertEqual(str(capture.records.message_ids.body), '
ร่างกาย
\n') + # -------------------------------------------------- # Emails loop detection # -------------------------------------------------- diff --git a/odoo/__init__.py b/odoo/__init__.py index c83d80eeac9..2351005e484 100644 --- a/odoo/__init__.py +++ b/odoo/__init__.py @@ -86,6 +86,13 @@ try: except ImportError: pass # no fix required +# --------------------------------------------------------- +# some charset are known by Python under a different name +# --------------------------------------------------------- +import encodings.aliases # noqa: E402 + +encodings.aliases.aliases['874'] = 'cp874' +encodings.aliases.aliases['windows_874'] = 'cp874' #---------------------------------------------------------- # alias hebrew iso-8859-8-i and iso-8859-8-e on iso-8859-8