[FIX] mail, mass_mailing: remove implicit dependency on mass_mailing
Fix to commit: a1d6064dcc
Which erroneously put a mass_mailing method in mail,
as mail.mail.statistics is defined in mass_mailing.
Since it does not depend on the records, it been extracted from the
loop.
opw 1890461
closes odoo/odoo#27431
This commit is contained in:
@@ -32,7 +32,6 @@ from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
BLACKLIST_MAX_BOUNCED_LIMIT = 5
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
@@ -1471,14 +1470,6 @@ class MailThread(models.AbstractModel):
|
||||
Mail Returned to Sender) is received for an existing thread. The default
|
||||
behavior is to check is an integer ``message_bounce`` column exists.
|
||||
If it is the case, its content is incremented.
|
||||
In addition, an auto blacklist rule check if the email can be blacklisted
|
||||
to avoid sending mails indefinitely to this email address.
|
||||
This rule checks if the email bounced too much. If this is the case,
|
||||
the email address is added to the blacklist in order to avoid continuing
|
||||
to send mass_mail to that email address. If it bounced too much times
|
||||
in the last month and the bounced are at least separated by one week,
|
||||
to avoid blacklist someone because of a temporary mail server error,
|
||||
then the email is considered as invalid and is blacklisted.
|
||||
|
||||
:param mail_id: ID of the sent email that bounced. It may not exist anymore
|
||||
but it could be usefull if the information was kept. This is
|
||||
@@ -1488,14 +1479,6 @@ class MailThread(models.AbstractModel):
|
||||
if 'message_bounce' in self._fields:
|
||||
for record in self:
|
||||
record.message_bounce = record.message_bounce + 1
|
||||
three_months_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(weeks=13))
|
||||
stats = self.env['mail.mail.statistics']\
|
||||
.search(['&', ('bounced', '>', three_months_ago), ('email','=ilike',email)])\
|
||||
.mapped('bounced')
|
||||
if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT:
|
||||
if max(stats) > min(stats) + datetime.timedelta(weeks=1):
|
||||
blacklist_rec = self.env['mail.blacklist'].sudo()._add(email)
|
||||
blacklist_rec._message_log('This email has been automatically blacklisted because of too much bounced.')
|
||||
|
||||
def _message_extract_payload_postprocess(self, message, body, attachments):
|
||||
""" Perform some cleaning / postprocess in the body and attachments
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
import logging
|
||||
import re
|
||||
import datetime
|
||||
|
||||
from odoo import api, models, tools
|
||||
from odoo import api, models, tools, fields
|
||||
from odoo.tools import decode_smtp_header, decode_message_header
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
BLACKLIST_MAX_BOUNCED_LIMIT = 5
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
@@ -49,4 +51,26 @@ class MailThread(models.AbstractModel):
|
||||
default_mass_mailing_name=False,
|
||||
default_mass_mailing_id=False,
|
||||
)
|
||||
return super(MailThread, no_massmail).message_post_with_template(template_id, **kwargs)
|
||||
return super(MailThread, no_massmail).message_post_with_template(template_id, **kwargs)
|
||||
|
||||
@api.multi
|
||||
def message_receive_bounce(self, email, partner, mail_id=None):
|
||||
"""In addition, an auto blacklist rule check if the email can be blacklisted
|
||||
to avoid sending mails indefinitely to this email address.
|
||||
This rule checks if the email bounced too much. If this is the case,
|
||||
the email address is added to the blacklist in order to avoid continuing
|
||||
to send mass_mail to that email address. If it bounced too much times
|
||||
in the last month and the bounced are at least separated by one week,
|
||||
to avoid blacklist someone because of a temporary mail server error,
|
||||
then the email is considered as invalid and is blacklisted."""
|
||||
super(MailThread, self).message_receive_bounce(email, partner, mail_id=None)
|
||||
|
||||
three_months_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(weeks=13))
|
||||
stats = self.env['mail.mail.statistics'] \
|
||||
.search(['&', ('bounced', '>', three_months_ago), ('email', '=ilike', email)]) \
|
||||
.mapped('bounced')
|
||||
if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT:
|
||||
if max(stats) > min(stats) + datetime.timedelta(weeks=1):
|
||||
blacklist_rec = self.env['mail.blacklist'].sudo()._add(email)
|
||||
blacklist_rec._message_log(
|
||||
'This email has been automatically blacklisted because of too much bounced.')
|
||||
|
||||
Reference in New Issue
Block a user