mirror of https://github.com/OCA/social.git
[8.0][FIX][mail_tracking] Use event recipient address to find partners and contacts to bounce (#133)
parent
e83b47a516
commit
849df3cefa
|
@ -195,11 +195,16 @@ class MailTrackingEmail(models.Model):
|
||||||
})
|
})
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _partners_email_bounced_set(self, reason):
|
def _partners_email_bounced_set(self, reason, event=None):
|
||||||
for tracking_email in self:
|
recipients = []
|
||||||
|
if event and event.recipient_address:
|
||||||
|
recipients.append(event.recipient_address)
|
||||||
|
else:
|
||||||
|
recipients = list(filter(None, self.mapped('recipient_address')))
|
||||||
|
for recipient in recipients:
|
||||||
self.env['res.partner'].search([
|
self.env['res.partner'].search([
|
||||||
('email', '=ilike', tracking_email.recipient_address)
|
('email', '=ilike', recipient)
|
||||||
]).email_bounced_set(tracking_email, reason)
|
]).email_bounced_set(self, reason, event=event)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def smtp_error(self, mail_server, smtp_server, exception):
|
def smtp_error(self, mail_server, smtp_server, exception):
|
||||||
|
@ -293,11 +298,14 @@ class MailTrackingEmail(models.Model):
|
||||||
if not other_ids:
|
if not other_ids:
|
||||||
vals = tracking_email._event_prepare(event_type, metadata)
|
vals = tracking_email._event_prepare(event_type, metadata)
|
||||||
if vals:
|
if vals:
|
||||||
event_ids += event_ids.sudo().create(vals)
|
events = event_ids.sudo().create(vals)
|
||||||
|
if event_type in {'hard_bounce', 'spam', 'reject'}:
|
||||||
|
for event in events:
|
||||||
|
self.sudo()._partners_email_bounced_set(
|
||||||
|
event_type, event=event)
|
||||||
|
event_ids += events
|
||||||
else:
|
else:
|
||||||
_logger.debug("Concurrent event '%s' discarded", event_type)
|
_logger.debug("Concurrent event '%s' discarded", event_type)
|
||||||
if event_type in {'hard_bounce', 'spam', 'reject'}:
|
|
||||||
self.sudo()._partners_email_bounced_set(event_type)
|
|
||||||
return event_ids
|
return event_ids
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -16,6 +17,9 @@ class MailTrackingEvent(models.Model):
|
||||||
_description = 'MailTracking event'
|
_description = 'MailTracking event'
|
||||||
|
|
||||||
recipient = fields.Char(string="Recipient", readonly=True)
|
recipient = fields.Char(string="Recipient", readonly=True)
|
||||||
|
recipient_address = fields.Char(
|
||||||
|
string='Recipient email address', readonly=True, store=True,
|
||||||
|
compute='_compute_recipient_address', index=True)
|
||||||
timestamp = fields.Float(
|
timestamp = fields.Float(
|
||||||
string='UTC timestamp', readonly=True,
|
string='UTC timestamp', readonly=True,
|
||||||
digits=dp.get_precision('MailTracking Timestamp'))
|
digits=dp.get_precision('MailTracking Timestamp'))
|
||||||
|
@ -51,6 +55,19 @@ class MailTrackingEvent(models.Model):
|
||||||
error_description = fields.Char(string='Error description', readonly=True)
|
error_description = fields.Char(string='Error description', readonly=True)
|
||||||
error_details = fields.Text(string='Error details', readonly=True)
|
error_details = fields.Text(string='Error details', readonly=True)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
@api.depends('recipient')
|
||||||
|
def _compute_recipient_address(self):
|
||||||
|
for email in self:
|
||||||
|
if email.recipient:
|
||||||
|
matches = re.search(r'<(.*@.*)>', email.recipient)
|
||||||
|
if matches:
|
||||||
|
email.recipient_address = matches.group(1).lower()
|
||||||
|
else:
|
||||||
|
email.recipient_address = email.recipient.lower()
|
||||||
|
else:
|
||||||
|
email.recipient_address = False
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('time')
|
@api.depends('time')
|
||||||
def _compute_date(self):
|
def _compute_date(self):
|
||||||
|
|
|
@ -36,7 +36,7 @@ class ResPartner(models.Model):
|
||||||
partner.tracking_emails_count = count
|
partner.tracking_emails_count = count
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def email_bounced_set(self, tracking_email, reason):
|
def email_bounced_set(self, tracking_emails, reason, event=None):
|
||||||
"""Inherit this method to make any other actions to partners"""
|
"""Inherit this method to make any other actions to partners"""
|
||||||
partners = self.filtered(lambda r: not r.email_bounced)
|
partners = self.filtered(lambda r: not r.email_bounced)
|
||||||
return partners.write({'email_bounced': True})
|
return partners.write({'email_bounced': True})
|
||||||
|
|
|
@ -21,8 +21,9 @@ class MailMassMailingContact(models.Model):
|
||||||
email_score_from_email(contact.email)
|
email_score_from_email(contact.email)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def email_bounced_set(self, tracking_email, reason):
|
def email_bounced_set(self, tracking_emails, reason, event=None):
|
||||||
return self.write({'email_bounced': True})
|
contacts = self.filtered(lambda r: not r.email_bounced)
|
||||||
|
return contacts.write({'email_bounced': True})
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|
|
@ -32,11 +32,16 @@ class MailTrackingEmail(models.Model):
|
||||||
return tracking
|
return tracking
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _contacts_email_bounced_set(self, reason):
|
def _contacts_email_bounced_set(self, reason, event=None):
|
||||||
for tracking_email in self:
|
recipients = []
|
||||||
|
if event and event.recipient_address:
|
||||||
|
recipients.append(event.recipient_address)
|
||||||
|
else:
|
||||||
|
recipients = list(filter(None, self.mapped('recipient_address')))
|
||||||
|
for recipient in recipients:
|
||||||
self.env['mail.mass_mailing.contact'].search([
|
self.env['mail.mass_mailing.contact'].search([
|
||||||
('email', '=ilike', tracking_email.recipient_address)
|
('email', '=ilike', recipient)
|
||||||
]).email_bounced_set(tracking_email, reason)
|
]).email_bounced_set(self, reason, event=event)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def smtp_error(self, mail_server, smtp_server, exception):
|
def smtp_error(self, mail_server, smtp_server, exception):
|
||||||
|
|
Loading…
Reference in New Issue