From 323dab7653d6caea5a593aaede3d0f69a6a983de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 14 Oct 2016 11:43:55 +0200 Subject: [PATCH] [REF] mail: remove compatibility for support of model-res_id message-id in mail gateway Old versions of Odoo did not correctly manage message_id of mail messages. Thread formation was based on information present in References and/or in In-Reply-To of replies to emails. Message-Ids could contain model and res_id of a record. Thread formation was done using this information. However commit 8253453d6439d97f272407f02eadafc99f0df796 fixed that behavior by correctly checking in existing mail_messages to find matching message-ids. Message found was set as parent and thread formation was correctly done without collision or possible issues with badly formatted Message-Ids. A compatibility mode was introduced at the same time to handle previous versions of Odoo. This commit removes this compatibility as it was done long enough to ensure compatibility is not required anymore. [TESTS] mail: tests updated, compat mode should raise in all cases now --- addons/mail/models/mail_thread.py | 18 ++---------------- addons/mail/tests/test_mail_gateway.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 599cec0493c..a733f2f329b 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1109,37 +1109,23 @@ class MailThread(models.AbstractModel): reply_match = False if reply_match: - compat_mode = False msg_references = tools.mail_header_msgid_re.findall(thread_references) mail_messages = MailMessage.sudo().search([('message_id', 'in', msg_references)], limit=1) - # message is a reply to an existing thread (6.1 compatibility) - # do not match forwarded emails from another OpenERP system (thread_id collision!) - if not mail_messages and local_hostname == reply_hostname and reply_thread_id and reply_model in self.env: - mail_messages = MailMessage.search([ - ('message_id', '=', False), - ('model', '=', reply_model), - ('res_id', '=', reply_thread_id)]) - compat_mode = True - if mail_messages: model, thread_id = mail_messages.model, mail_messages.res_id if not reply_private: # TDE note: not sure why private mode as no alias search, copying existing behavior dest_aliases = Alias.search([('alias_name', 'in', rcpt_tos_localparts)], limit=1) - # TDE Note: compat mode = without context key, why ? because route = self.message_route_verify( message, message_dict, (model, thread_id, custom_values, self._uid, dest_aliases), update_author=True, assert_model=reply_private, create_fallback=True, allow_private=reply_private, drop_alias=True) if route: - # TDE Note: compat mode: parent is invalid for a compat-reply - # message_dict.pop('parent_id', None) - # TDE note: add compat mode for compat mode in debug _logger.info( - 'Routing mail from %s to %s with Message-Id %s%s: direct reply to msg: model: %s, thread_id: %s, custom_values: %s, uid: %s', - email_from, email_to, message_id, compat_mode and ' (compat mode)' or '', model, thread_id, custom_values, self._uid) + 'Routing mail from %s to %s with Message-Id %s: direct reply to msg: model: %s, thread_id: %s, custom_values: %s, uid: %s', + email_from, email_to, message_id, model, thread_id, custom_values, self._uid) return [route] elif route is False: return [] diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 707e316bca5..b729a105b98 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -580,25 +580,29 @@ class TestMailgateway(TestMail): msg_id='<1198923581.41972151344608186802.JavaMail.diff1@agrolait.com>') # when 6.1 messages are present, compat mode is available + # Odoo 10 update: compat mode has been removed and should not work anymore self.fake_email.write({'message_id': False}) # Do: compat mode accepts partial-matching emails - frog_groups = self.format_and_process( + self.assertRaises( + ValueError, + self.format_and_process, MAIL_TEMPLATE, email_from='other5@gmail.com', msg_id='<1.2.JavaMail.new@agrolait.com>', to='noone@example.com>', subject='spam', extra='In-Reply-To: <12321321-openerp-%d-mail.channel@%s>' % (self.group_public.id, socket.gethostname())) # 3''. 6.1 compat mode should not work if hostname does not match! + # Odoo 10 update: compat mode has been removed and should not work anymore and does not depend from hostname self.assertRaises(ValueError, self.format_and_process, MAIL_TEMPLATE, email_from='other5@gmail.com', msg_id='<1.3.JavaMail.new@agrolait.com>', to='noone@example.com>', subject='spam', - extra='In-Reply-To: <12321321-openerp-%d-mail.channel@neighbor.com>' % frog_groups.id) + extra='In-Reply-To: <12321321-openerp-%d-mail.channel@neighbor.com>' % self.group_public.id) # Test created messages - self.assertEqual(len(self.group_public.message_ids), 2, 'message_process: group should contain 6 messages') - self.assertEqual(len(self.group_public.message_ids[0].child_ids), 0, 'message_process: msg1 should not have children') + self.assertEqual(len(self.group_public.message_ids), 1) + self.assertEqual(len(self.group_public.message_ids[0].child_ids), 0) @mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models') def test_message_process_duplicate(self):