[IMP] mail: handle forwarded emails in mailgateway
If the 'To' of an incoming email is an alias on another model we now consider this emails as a forward to a new alias. A use case for this is an email on a task that should be considered as an issue and forwarded to another alias.
This commit is contained in:
@@ -3,3 +3,4 @@
|
||||
import models
|
||||
import wizard
|
||||
import controllers
|
||||
import tests.test_mail_model
|
||||
|
||||
@@ -1060,6 +1060,15 @@ class MailThread(models.AbstractModel):
|
||||
return []
|
||||
|
||||
# 1. message is a reply to an existing message (exact match of message_id or compat-mode)
|
||||
if reply_model and reply_thread_id:
|
||||
other_alias = Alias.search([
|
||||
'&',
|
||||
('alias_name', '!=', False),
|
||||
('alias_name', '=', email_to_localpart)
|
||||
])
|
||||
if other_alias and other_alias.alias_model_id.model != reply_model:
|
||||
reply_match = False
|
||||
|
||||
if reply_match:
|
||||
compat_mode = False
|
||||
msg_references = tools.mail_header_msgid_re.findall(thread_references)
|
||||
|
||||
@@ -33,3 +33,4 @@ access_mail_template,mail.template,model_mail_template,base.group_user,1,1,1,0
|
||||
access_mail_template_system,mail.template_system,model_mail_template,base.group_system,1,1,1,1
|
||||
access_mail_shortcode,mail.shortcode,model_mail_shortcode,base.group_user,1,1,1,1
|
||||
access_mail_shortcode_portal,mail.shortcode.portal,model_mail_shortcode,base.group_portal,1,0,0,0
|
||||
access_mail_test_all,mail.test.all,model_mail_test,base.group_user,1,1,1,1
|
||||
|
@@ -298,6 +298,14 @@ class TestMailgateway(TestMail):
|
||||
'alias_model_id': self.mail_channel_model.id,
|
||||
'alias_contact': 'everyone'})
|
||||
|
||||
# test@.. will cause the creation of new mail.test
|
||||
self.mail_test_model = self.env['ir.model'].search([('model', '=', 'mail.test')], limit=1)
|
||||
self.alias_2 = self.env['mail.alias'].create({
|
||||
'alias_name': 'test',
|
||||
'alias_user_id': False,
|
||||
'alias_model_id': self.mail_test_model.id,
|
||||
'alias_contact': 'everyone'})
|
||||
|
||||
# Set a first message on public group to test update and hierarchy
|
||||
self.fake_email = self.env['mail.message'].create({
|
||||
'model': 'mail.channel',
|
||||
@@ -533,6 +541,34 @@ class TestMailgateway(TestMail):
|
||||
self.assertEqual(len(self.group_public.message_ids), 2, 'message_process: group should contain one new message')
|
||||
self.assertEqual(len(self.fake_email.child_ids), 1, 'message_process: new message should be children of the existing one')
|
||||
|
||||
@mute_logger('openerp.addons.mail.models.mail_thread', 'openerp.models')
|
||||
def test_message_process_references_forward(self):
|
||||
""" Incoming email using references but with alias forward should not go into references destination """
|
||||
res_test = self.format_and_process(
|
||||
MAIL_TEMPLATE, to='test@example.com',
|
||||
subject='My Dear Forward',
|
||||
extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % self.fake_email.message_id,
|
||||
msg_id='<1198923581.41972151344608186800.JavaMail.4@agrolait.com>',
|
||||
target_model='mail.test')
|
||||
|
||||
self.assertEqual(len(self.group_public.message_ids), 1, 'message_process: group should not contain new message')
|
||||
self.assertEqual(len(self.fake_email.child_ids), 0, 'message_process: original email should not contain childs')
|
||||
self.assertEqual(res_test.name, 'My Dear Forward')
|
||||
self.assertEqual(len(res_test.message_ids), 1)
|
||||
|
||||
@mute_logger('openerp.addons.mail.models.mail_thread', 'openerp.models')
|
||||
def test_message_process_references_forward_cc(self):
|
||||
""" Incoming email using references but with alias forward should not go into references destination """
|
||||
self.format_and_process(
|
||||
MAIL_TEMPLATE, to='erroneous@example.com', cc='test@example.com',
|
||||
subject='My Dear Forward',
|
||||
extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % self.fake_email.message_id,
|
||||
msg_id='<1198923581.41972151344608186800.JavaMail.4@agrolait.com>',
|
||||
target_model='mail.test')
|
||||
|
||||
self.assertEqual(len(self.group_public.message_ids), 2, 'message_process: group should contain one new message')
|
||||
self.assertEqual(len(self.fake_email.child_ids), 1, 'message_process: new message should be children of the existing one')
|
||||
|
||||
@mute_logger('openerp.addons.mail.models.mail_thread', 'openerp.models')
|
||||
def test_message_process_model_res_id(self):
|
||||
""" Incoming email with ref holding model / res_id but that does not match any message in the thread: must raise since OpenERP saas-3 """
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MailTest(models.Model):
|
||||
""" A mail.channel is a discussion group that may behave like a listener
|
||||
on documents. """
|
||||
_description = 'Test Mail Model'
|
||||
_name = 'mail.test'
|
||||
_mail_post_access = 'read'
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
name = fields.Char()
|
||||
alias_id = fields.Many2one(
|
||||
'mail.alias', 'Alias')
|
||||
Reference in New Issue
Block a user