[FIX] mass_mailing: bounced statistics
A mass mailing can be considered both as bounced and opened. This can occur with some email providers, such as Gmail. Indeed, Gmail sends out-of-office replies to the `Return-Path` address, which is also used for bounced emails. Therefore, it is not possible to determine accurately if a message sent to to the `Return-Path` is a genuine bounced email, or an out-of-office reply. However, if the recipient opens the email, it is possible to determine that the bounce was counted incorrectly. In this case, we empty the `bounced` field. Similarly, we only write on the `bounced` filed if the `opened` field is empty. This could occur if the recipient opens the email before the out-of-office reply is received. As a bonus, we also make sure to avoid updating the status if no route was found. No route means that the email was bounced, so no reason to set it as opened. opw-1869957
This commit is contained in:
committed by
Nicolas Martinelli
parent
e1ff6ce3d9
commit
ea4502ceab
@@ -35,7 +35,7 @@ class MailThread(models.AbstractModel):
|
||||
""" Override to update the parent mail statistics. The parent is found
|
||||
by using the References header of the incoming message and looking for
|
||||
matching message_id in mail.mail.statistics. """
|
||||
if message.get('References'):
|
||||
if message.get('References') and routes:
|
||||
message_ids = [x.strip() for x in decode_smtp_header(message['References']).split()]
|
||||
self.env['mail.mail.statistics'].set_opened(mail_message_ids=message_ids)
|
||||
self.env['mail.mail.statistics'].set_replied(mail_message_ids=message_ids)
|
||||
|
||||
@@ -106,7 +106,7 @@ class MailMailStats(models.Model):
|
||||
|
||||
def set_opened(self, mail_mail_ids=None, mail_message_ids=None):
|
||||
statistics = self._get_records(mail_mail_ids, mail_message_ids, [('opened', '=', False)])
|
||||
statistics.write({'opened': fields.Datetime.now()})
|
||||
statistics.write({'opened': fields.Datetime.now(), 'bounced': False})
|
||||
return statistics
|
||||
|
||||
def set_clicked(self, mail_mail_ids=None, mail_message_ids=None):
|
||||
@@ -120,6 +120,7 @@ class MailMailStats(models.Model):
|
||||
return statistics
|
||||
|
||||
def set_bounced(self, mail_mail_ids=None, mail_message_ids=None):
|
||||
statistics = self._get_records(mail_mail_ids, mail_message_ids, [('bounced', '=', False)])
|
||||
statistics = self._get_records(
|
||||
mail_mail_ids, mail_message_ids, [('bounced', '=', False), ('opened', '=', False)])
|
||||
statistics.write({'bounced': fields.Datetime.now()})
|
||||
return statistics
|
||||
|
||||
Reference in New Issue
Block a user