FIX] mail: ignore parent message for forwarded private messages.

This commit is contained in:
Christophe Simonis 2015-07-24 17:56:30 +02:00
parent 71b0a4cb6c
commit 799fff6897
2 changed files with 35 additions and 0 deletions

View File

@ -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:

View File

@ -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 = '<THIS.IS.A.FW.MESSAGE.%d@bert.fr>' % (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)