diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index d4adaff3382a4076c83a974d77d3b5298187662b..518a2f5edad772a9c19553573a9882e0cc8b14a0 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1343,7 +1343,9 @@ class MailThread(models.AbstractModel): if dsn_part and len(dsn_part.get_payload()) > 1: dsn = dsn_part.get_payload()[1] final_recipient_data = tools.decode_message_header(dsn, 'Final-Recipient') - bounced_email = tools.email_normalize(final_recipient_data.split(';', 1)[1].strip()) + # old servers may hold void or invalid Final-Recipient header + if final_recipient_data and ";" in final_recipient_data: + bounced_email = tools.email_normalize(final_recipient_data.split(';', 1)[1].strip()) if bounced_email: bounced_partner = self.env['res.partner'].sudo().search([('email_normalized', '=', bounced_email)]) diff --git a/addons/test_mail/data/test_mail_data.py b/addons/test_mail/data/test_mail_data.py index d6e388469308688a8d14b9c3cc586d541ba02944..9b7856732bf140b8b2e72e65366f4bd8f91eff4d 100644 --- a/addons/test_mail/data/test_mail_data.py +++ b/addons/test_mail/data/test_mail_data.py @@ -883,3 +883,53 @@ OyI+T2RvbzwvYT4uCjwvcD4KPC9kaXY+CiAgICAgICAg --92726A5F09.1555335666/mail2.test.ironsky-- """ + +MAIL_NO_FINAL_RECIPIENT = """\ +Return-Path: <bounce-md_9656353.6125275c.v1-f28f7746389e45f0bfbf9faefe9e0dc8@mandrillapp.com> +Delivered-To: catchall@xxxx.xxxx +Received: from in58.mail.ovh.net (unknown [10.101.4.58]) + by vr46.mail.ovh.net (Postfix) with ESMTP id 4GvFsq2QLYz1t0N7r + for <catchall@xxxx.xxxx>; Tue, 24 Aug 2021 17:07:43 +0000 (UTC) +Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=46.105.72.169; helo=40.mo36.mail-out.ovh.net; envelope-from=bounce-md_9656353.6125275c.v1-f28f7746389e45f0bfbf9faefe9e0dc8@mandrillapp.com; receiver=catchall@xxxx.xxxx +Authentication-Results: in58.mail.ovh.net; + dkim=pass (1024-bit key; unprotected) header.d=mandrillapp.com header.i=bounces-noreply@mandrillapp.com header.b="TDzUcdJs"; + dkim=pass (1024-bit key) header.d=mandrillapp.com header.i=@mandrillapp.com header.b="MyjddTY5"; + dkim-atps=neutral +Delivered-To: xxxx.xxxx-{email_to} +Authentication-Results: in62.mail.ovh.net; + dkim=pass (1024-bit key; unprotected) header.d=mandrillapp.com header.i=bounces-noreply@mandrillapp.com header.b="TDzUcdJs"; + dkim=pass (1024-bit key) header.d=mandrillapp.com header.i=@mandrillapp.com header.b="MyjddTY5"; + dkim-atps=neutral +From: MAILER-DAEMON <bounces-noreply@mandrillapp.com> +Subject: Undelivered Mail Returned to Sender +To: {email_to} +X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com +X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=9656353.f28f7746389e45f0bfbf9faefe9e0dc8 +X-Mandrill-User: md_9656353 +Feedback-ID: 9656353:9656353.20210824:md +Message-Id: <9656353.20210824170740.6125275cf21879.17950539@mail9.us4.mandrillapp.com> +Date: Tue, 24 Aug 2021 17:07:40 +0000 +MIME-Version: 1.0 +Content-Type: multipart/report; boundary="_av-UfLe6y6qxNo54-urtAxbJQ" + +--_av-UfLe6y6qxNo54-urtAxbJQ +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 7bit + + --- The following addresses had delivery problems --- + +<{email_from}> (5.7.1 <{email_from}>: Recipient address rejected: Access denied) + + +--_av-UfLe6y6qxNo54-urtAxbJQ +Content-Type: message/delivery-status +Content-Transfer-Encoding: 7bit + +Original-Recipient: <{email_from}> +Action: failed +Diagnostic-Code: smtp; 554 5.7.1 <{email_from}>: Recipient address rejected: Access denied +Remote-MTA: 10.245.192.40 + + + +--_av-UfLe6y6qxNo54-urtAxbJQ--""" diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index ea0ef7c62b25bc56356c6307b639478686bcc3bc..055c1eb3253e01b1bfdc1dbb11ee4f159c809413 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -55,6 +55,11 @@ class TestEmailParsing(TestMailCommon): res = self.env['mail.thread'].message_parse(self.from_string(test_mail_data.MAIL_MULTIPART_WEIRD_FILENAME)) self.assertEqual(res['attachments'][0][0], '62_@;,][)=.(ÇÀÉ.txt') + def test_message_parse_bugs(self): + """ Various corner cases or message parsing """ + # message without Final-Recipient + self.env['mail.thread'].message_parse(self.from_string(test_mail_data.MAIL_NO_FINAL_RECIPIENT)) + def test_message_parse_eml(self): # Test that the parsing of mail with embedded emails as eml(msg) which generates empty attachments, can be processed. mail = self.format(test_mail_data.MAIL_EML_ATTACHMENT, email_from='"Sylvie Lelitre" <test.sylvie.lelitre@agrolait.com>', to='generic@test.com')