diff options
| author | David Beguin <dbe@odoo.com> | 2019-01-04 10:46:40 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-08-09 14:30:55 +0000 |
| commit | f4524f03c32a27b1899562a71cad6f491bfe44ce (patch) | |
| tree | 0e306f48ec26b3da35968e054f9076a37aa7381a /addons/test_mass_mailing | |
| parent | 7b79045fab809679e17d774f9a510e07ac39aa0b (diff) | |
[REF] mail: move and improve bounce management in mail gateway
PURPOSE
Add some improvements in mail gateway: remove private discussion, improve
bounce management, allow resetting bounce counters, improve automatic set or
reset of blacklists and ease mass mailing inheritance.
SPECIFICATIONS
Purpose
* move bounce information detection in message parsing. It allows to have
this information available in various steps of routing instead of having
to manually re-compute them;
* handle bounce in specific methods allowing easy override;
* improve bounce management, notably when detecting a bounce not linked
to the bounce alias configuration;
* better integration with blacklist mechanism;
Specifications
* compute bounce information in ``_message_parse_extract_bounce``.It parses
bounce information and returns a dictionary allowing to update parsed email
values;
* remove override in mass_mailign that basically does what mail already
does;
* manage bounce in ``_routing_handle_bounce``;
* when detecting a bounce, correctly call the bounce management method on
all models inheriting from blacklist;
* correctly update bounce counter;
* bounced mailing traces and automatic blacklist in mass mailing should
be done in ``_routing_handle_bounce``;
* add some tests;
LINKS
Related to task 1893155
Linked to PR #33340
Diffstat (limited to 'addons/test_mass_mailing')
| -rw-r--r-- | addons/test_mass_mailing/tests/test_mail_auto_blacklist.py | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/addons/test_mass_mailing/tests/test_mail_auto_blacklist.py b/addons/test_mass_mailing/tests/test_mail_auto_blacklist.py index ff9bc5268c1..280bac1389b 100644 --- a/addons/test_mass_mailing/tests/test_mail_auto_blacklist.py +++ b/addons/test_mass_mailing/tests/test_mail_auto_blacklist.py @@ -1,8 +1,12 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests import common + import datetime +from odoo import tools +from odoo.tests import common + + class TestAutoBlacklist(common.TransactionCase): def test_mail_bounced_auto_blacklist(self): @@ -10,40 +14,29 @@ class TestAutoBlacklist(common.TransactionCase): mass_mailing = self.env['mailing.mailing'] mail_blacklist = self.env['mail.blacklist'] mail_statistics = self.env['mailing.trace'] - mail_thread = self.env['mail.thread'] # create mailing contact record self.mailing_contact_1 = mass_mailing_contacts.create({'name': 'test email 1', 'email': 'Test1@email.com'}) - # create bounced history - mail_statistics.create({ - 'model': 'mailing.contact', - 'res_id': self.mailing_contact_1.id, - 'bounced': datetime.datetime.now() - datetime.timedelta(weeks=2), - 'email': self.mailing_contact_1.email - }) - self.mailing_contact_1._message_receive_bounce(self.mailing_contact_1.email, self.mailing_contact_1) - mail_statistics.create({ - 'model': 'mailing.contact', - 'res_id': self.mailing_contact_1.id, - 'bounced': datetime.datetime.now() - datetime.timedelta(weeks=3), - 'email': self.mailing_contact_1.email - }) - self.mailing_contact_1._message_receive_bounce(self.mailing_contact_1.email, self.mailing_contact_1) - mail_statistics.create({ - 'model': 'mailing.contact', - 'res_id': self.mailing_contact_1.id, - 'bounced': datetime.datetime.now() - datetime.timedelta(weeks=4), - 'email': self.mailing_contact_1.email - }) - self.mailing_contact_1._message_receive_bounce(self.mailing_contact_1.email, self.mailing_contact_1) - mail_statistics.create({ - 'model': 'mailing.contact', - 'res_id': self.mailing_contact_1.id, - 'bounced': datetime.datetime.now() - datetime.timedelta(weeks=5), - 'email': self.mailing_contact_1.email - }) - self.mailing_contact_1._message_receive_bounce(self.mailing_contact_1.email, self.mailing_contact_1) + base_parsed_values = { + 'email_from': 'toto@yaourth.com', 'to': 'tata@yaourth.com', 'message_id': '<123.321@yaourth.com>', + 'bounced_partner': self.env['res.partner'].sudo(), 'bounced_message': self.env['mail.message'].sudo() + } + + # create bounced history of 4 statistics + for idx in range(4): + mail_statistics.create({ + 'model': 'mailing.contact', + 'res_id': self.mailing_contact_1.id, + 'bounced': datetime.datetime.now() - datetime.timedelta(weeks=idx+2), + 'email': self.mailing_contact_1.email, + 'message_id': '<123.00%s@iron.sky>' % idx, + }) + base_parsed_values.update({ + 'bounced_email': tools.email_normalize(self.mailing_contact_1.email), + 'bounced_msg_id': '<123.00%s@iron.sky>' % idx + }) + self.env['mail.thread']._routing_handle_bounce(False, base_parsed_values) # create mass mailing record self.mass_mailing = mass_mailing.create({ @@ -73,10 +66,15 @@ class TestAutoBlacklist(common.TransactionCase): 'model': 'mailing.contact', 'res_id': self.mailing_contact_1.id, 'bounced': datetime.datetime.now(), - 'email': self.mailing_contact_1.email + 'email': self.mailing_contact_1.email, + 'message_id': '<123.004@iron.sky>', + }) + base_parsed_values.update({ + 'bounced_email': tools.email_normalize(self.mailing_contact_1.email), + 'bounced_msg_id': '<123.004@iron.sky>' }) # call bounced - self.mailing_contact_1._message_receive_bounce(self.mailing_contact_1.email, self.mailing_contact_1) + self.env['mail.thread']._routing_handle_bounce(False, base_parsed_values) # check blacklist blacklist_record = mail_blacklist.search([('email', '=', self.mailing_contact_1.email)]) |
