[FIX] core: add support for windows-874 encoding
Outlook and similar Windows based systems use windows-874 for encoding Thai characters which is not natively known by Python. Simply aliasing the Windows encoding as cp874 adds support for this encoding. opw-3684161 closes odoo/odoo#161117 X-original-commit: 65d4c2507e762dc273a02a2e2215c49a5976568d Signed-off-by: Julien Castiaux (juc) <juc@odoo.com> Co-authored-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
committed by
Julien Castiaux
co-authored by
Julien Castiaux
parent
abd8736150
commit
a26d3b245d
@@ -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 <outlook_windows@outlook.com>
|
||||
To: "Thai Odoo User" <thai-user@odoo.com>
|
||||
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: <PH7P220MB158617DEAEC85ECA2A0D2CAFBC3E2@PH7P220MB1586.NAMP220.PROD.OUTLOOK.COM>
|
||||
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='''
|
||||
|
||||
@@ -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), '<pre>ร่างกาย</pre>\n')
|
||||
|
||||
# --------------------------------------------------
|
||||
# Emails loop detection
|
||||
# --------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user