diff options
| author | Thibault Delavallée <tde@openerp.com> | 2016-08-24 13:38:33 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2016-09-01 13:25:26 +0200 |
| commit | 4f9105a4ef40bccd3b27a6a10cc612636a6499f7 (patch) | |
| tree | 0a99325749e508873a80ac9b3376a960aa0a3425 /addons | |
| parent | 0bedc14c124ef20a1d11b4c5c5fdc746bad02f14 (diff) | |
[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.
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mail/__init__.py | 1 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread.py | 9 | ||||
| -rw-r--r-- | addons/mail/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_gateway.py | 36 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_model.py | 17 |
5 files changed, 64 insertions, 0 deletions
diff --git a/addons/mail/__init__.py b/addons/mail/__init__.py index 175383c6644..72546813981 100644 --- a/addons/mail/__init__.py +++ b/addons/mail/__init__.py @@ -3,3 +3,4 @@ import models import wizard import controllers +import tests.test_mail_model diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 0e94aee9992..0cbf06cb152 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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) diff --git a/addons/mail/security/ir.model.access.csv b/addons/mail/security/ir.model.access.csv index 59a37569bfe..e869287d2f4 100644 --- a/addons/mail/security/ir.model.access.csv +++ b/addons/mail/security/ir.model.access.csv @@ -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
\ No newline at end of file diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 5720dab2459..3ce8c531f7c 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -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', @@ -534,6 +542,34 @@ class TestMailgateway(TestMail): 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 """ self.assertRaises(ValueError, diff --git a/addons/mail/tests/test_mail_model.py b/addons/mail/tests/test_mail_model.py new file mode 100644 index 00000000000..bde1231870d --- /dev/null +++ b/addons/mail/tests/test_mail_model.py @@ -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') |
