'Override to udpate mass mailing statistics based on bounce emails'

@api.model
def message_route(self, message, message_dict, model=None, thread_id=None, custom_values=None):

    bounce_alias = self.env['ir.config_parameter'].get_param('mail.bounce.alias')
    email_to = decode_message_header(message, 'To')
    email_to_localpart = (tools.email_split(email_to) or [''])[0].split('@', 1)[0].lower()
    if (bounce_alias and (bounce_alias in email_to_localpart)):
        bounce_re = re.compile(('%s\\+(\\d+)-?([\\w.]+)?-?(\\d+)?' % re.escape(bounce_alias)), re.UNICODE)
        bounce_match = bounce_re.search(email_to)
        if bounce_match:
            bounced_mail_id = bounce_match.group(1)
            self.env['mail.mail.statistics'].set_bounced(mail_mail_ids=[bounced_mail_id])
    return super(MailThread, self).message_route(message, message_dict, model, thread_id, custom_values)
