From 92fe83ecf8b4e64a42185bc056ba3c865df753cb Mon Sep 17 00:00:00 2001 From: David Beguin Date: Fri, 12 Oct 2018 15:33:15 +0000 Subject: [IMP] mail, mass_mailing : reset bounce on mail reception 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 The number of message bounce is incremented each time the email bounce on a specific email address. To have a correct information, we should reset to zero this counter if we receive a mail from this address. Indeed, if we receive an email from an email address, this email is active and the message bounce number (if > 0) is not relevant anymore. Only models inheriting form blacklist are impacted by this improvement in order to limit a bit side effect. Also, add a check in autoblacklist rule. No need to check the stats if message_bounce is < 5. This commit introduces * ``_routing_reset_bounce`` routing method managing the bounce reset; * ``_message_reset_bounce`` model method that resets bounce counter in blacklist enabled models; LINKS Related to task ID : 1893155 Linked to PR #33340 --- addons/mass_mailing/models/mail_thread.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/mass_mailing/models/mail_thread.py') diff --git a/addons/mass_mailing/models/mail_thread.py b/addons/mass_mailing/models/mail_thread.py index 09c6ba53626..93f657da3cf 100644 --- a/addons/mass_mailing/models/mail_thread.py +++ b/addons/mass_mailing/models/mail_thread.py @@ -50,13 +50,14 @@ class MailThread(models.AbstractModel): bounced_email = message_dict['bounced_email'] bounced_msg_id = message_dict['bounced_msg_id'] + bounced_partner = message_dict['bounced_partner'] if bounced_msg_id: self.env['mailing.trace'].set_bounced(mail_message_ids=[bounced_msg_id]) if bounced_email: three_months_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(weeks=13)) stats = self.env['mailing.trace'].search(['&', ('bounced', '>', three_months_ago), ('email', '=ilike', bounced_email)]).mapped('bounced') - if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT: + if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT and (not bounced_partner or bounced_partner.message_bounce >= BLACKLIST_MAX_BOUNCED_LIMIT): if max(stats) > min(stats) + datetime.timedelta(weeks=1): blacklist_rec = self.env['mail.blacklist'].sudo()._add(bounced_email) blacklist_rec._message_log( -- cgit v1.2.3