[FIX] mail: unicode character in email cannot be parsed
Sending email to addresses containing unicode characters cannot be parsed by python and result in a UnicodeEncodeError. This PR catch that specific exception and output a meaningful error message. Decision has been taken to not trigger any error message client-side has it would have needed modifications on some sensitive low-level backend code. To reproduce: - Configure odoo so it uses an email server - Send an invoice to a partner whoose email address contains some unicode characters (exemple: æøåÇÀ@example.com) opw-1892409 closes odoo/odoo#27804
This commit is contained in:
@@ -358,6 +358,9 @@ class MailMail(models.Model):
|
||||
# /!\ can't use mail.state here, as mail.refresh() will cause an error
|
||||
# see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1
|
||||
mail._postprocess_sent_message(success_pids=success_pids, failure_type=failure_type)
|
||||
except UnicodeEncodeError as exc:
|
||||
_logger.exception('UnicodeEncodeError on text "%s" while processing mail ID %r.', exc.object, mail.id)
|
||||
raise MailDeliveryException(_("Mail Delivery Failed"), "Invalid text: %s" % exc.object)
|
||||
except MemoryError:
|
||||
# prevent catching transient MemoryErrors, bubble up to notify user or abort cron job
|
||||
# instead of marking the mail as failed
|
||||
|
||||
@@ -6,6 +6,7 @@ import itertools
|
||||
from odoo.addons.test_mail.tests import common as mail_common
|
||||
from odoo.tests import common
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
|
||||
|
||||
|
||||
class TestMail(common.SavepointCase, mail_common.MockEmails):
|
||||
@@ -43,3 +44,13 @@ class TestMail(common.SavepointCase, mail_common.MockEmails):
|
||||
self.email_to_list.extend(itertools.chain.from_iterable(sent_email['email_to'] for sent_email in self._mails if sent_email.get('email_to')))
|
||||
self.assertNotIn(u'Ernest Employee <e.e@example.com>', self.email_to_list)
|
||||
self.assertIn(u'test@example.com', self.email_to_list)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_mail_message_values_unicode(self):
|
||||
mail = self.env['mail.mail'].create({
|
||||
'body_html': '<p>Test</p>',
|
||||
'email_to': 'test.😊@example.com',
|
||||
'partner_ids': [(4, self.user_employee.partner_id.id)]
|
||||
})
|
||||
|
||||
self.assertRaises(MailDeliveryException, mail.send)
|
||||
|
||||
Reference in New Issue
Block a user