From 799fff6897c1ba7ffd6d6966f0baccefe289c0f6 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 24 Jul 2015 17:56:30 +0200 Subject: [PATCH] FIX] mail: ignore parent message for forwarded private messages. --- addons/mail/mail_thread.py | 7 +++++++ addons/mail/tests/test_mail_gateway.py | 28 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 8270cb986cf..ecfdff68390 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -1006,6 +1006,8 @@ class mail_thread(osv.AbstractModel): (model, thread_id, custom_values, uid, None), update_author=True, assert_model=True, create_fallback=True, context=context) if route: + # parent is invalid for a compat-reply + message_dict.pop('parent_id', None) _logger.info( 'Routing mail from %s to %s with Message-Id %s: direct thread reply (compat-mode) to model: %s, thread_id: %s, custom_values: %s, uid: %s', email_from, email_to, message_id, model, thread_id, custom_values, uid) @@ -1032,6 +1034,9 @@ class mail_thread(osv.AbstractModel): elif route is False: return [] + # no route found for a matching reference (or reply), so parent is invalid + message_dict.pop('parent_id', None) + # 4. Look for a matching mail.alias entry # Delivered-To is a safe bet in most modern MTAs, but we have to fallback on To + Cc values # for all the odd MTAs out there, as there is no standard header for the envelope's `rcpt_to` value. @@ -1114,6 +1119,8 @@ class mail_thread(osv.AbstractModel): if thread_id and hasattr(model_pool, 'message_update'): model_pool.message_update(cr, user_id, [thread_id], message_dict, context=nosub_ctx) else: + # if a new thread is created, parent is irrelevant + message_dict.pop('parent_id', None) thread_id = model_pool.message_new(cr, user_id, message_dict, custom_values, context=nosub_ctx) else: if thread_id: diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index ba13b5ebacb..7f16c4f0f5f 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -736,3 +736,31 @@ class TestMailgateway(TestMail): 'message_post: private discussion: incorrect recipients when replying') self.assertEqual(set(msg_nids), set(test_nids), 'message_post: private discussion: incorrect notified recipients when replying') + + # Do bert forward it to an alias + mail_group_model_id = self.ir_model.search(cr, uid, [('model', '=', 'mail.group')])[0] + self.mail_alias.create(cr, uid, { + 'alias_name': 'groups', + 'alias_user_id': False, + 'alias_model_id': mail_group_model_id, + 'alias_parent_model_id': mail_group_model_id, + 'alias_parent_thread_id': self.group_pigs_id, + 'alias_contact': 'everyone'}) + + msg = self.mail_message.browse(cr, uid, msg1_id) + # forward it to a new thread AND an existing thread + for i, to in enumerate(['groups', 'group+pigs']): + fw_msg_id = '' % (i,) + fw_message = format(MAIL_TEMPLATE, to='%s@whatever.tld' % (to,), + subject='FW: Re: 1', + email_from='bert@bert.fr', + extra='References: %s' % msg.message_id, + msg_id=fw_msg_id) + self.mail_thread.message_process(cr, uid, None, fw_message) + + msg_ids = self.mail_message.search(cr, uid, [('message_id', '=', fw_msg_id)]) + self.assertEqual(len(msg_ids), 1) + msg_fw = self.mail_message.browse(cr, uid, msg_ids[0]) + + self.assertEqual(msg_fw.model, 'mail.group') + self.assertFalse(msg_fw.parent_id)