From 7586699165b0cb41ae771de3bd8093b2e738599d Mon Sep 17 00:00:00 2001 From: David Date: Fri, 22 Dec 2017 19:23:40 +0100 Subject: [PATCH 1/2] [10.0][FIX] mail_tracking_mailgun: Avoid key dict errors --- mail_tracking_mailgun/__manifest__.py | 2 +- mail_tracking_mailgun/models/mail_tracking_email.py | 6 ++++-- mail_tracking_mailgun/models/res_partner.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mail_tracking_mailgun/__manifest__.py b/mail_tracking_mailgun/__manifest__.py index 9fe931e0..f271654f 100644 --- a/mail_tracking_mailgun/__manifest__.py +++ b/mail_tracking_mailgun/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Mail tracking for Mailgun", "summary": "Mail tracking and Mailgun webhooks integration", - "version": "10.0.1.1.0", + "version": "10.0.1.1.1", "category": "Social Network", "website": "https://odoo-community.org/", "author": "Tecnativa, " diff --git a/mail_tracking_mailgun/models/mail_tracking_email.py b/mail_tracking_mailgun/models/mail_tracking_email.py index 2364762b..b017d4e9 100644 --- a/mail_tracking_mailgun/models/mail_tracking_email.py +++ b/mail_tracking_mailgun/models/mail_tracking_email.py @@ -9,7 +9,7 @@ import json import requests from datetime import datetime from odoo import _, api, fields, models -from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError import logging _logger = logging.getLogger(__name__) @@ -221,6 +221,8 @@ class MailTrackingEmail(models.Model): """ api_key, api_url, domain, validation_key = self._mailgun_values() for tracking in self: + if not tracking.mail_message_id: + raise UserError(_('There is no tracked message!')) message_id = tracking.mail_message_id.message_id.replace( "<", "").replace(">", "") res = requests.get( @@ -242,7 +244,7 @@ class MailTrackingEmail(models.Model): if not self.env['mail.tracking.event'].search( [('mailgun_id', '=', item["id"])]): mapped_event_type = self._mailgun_event_type_mapping.get( - item["event"]) or False + item["event"], item["event"]) metadata = self._mailgun_metadata( mapped_event_type, item, {}) tracking.event_create(mapped_event_type, metadata) diff --git a/mail_tracking_mailgun/models/res_partner.py b/mail_tracking_mailgun/models/res_partner.py index 9657647c..651b5cd7 100644 --- a/mail_tracking_mailgun/models/res_partner.py +++ b/mail_tracking_mailgun/models/res_partner.py @@ -8,8 +8,8 @@ import requests import json -from openerp import _, api, models -from openerp.exceptions import UserError +from odoo import _, api, models +from odoo.exceptions import UserError class ResPartner(models.Model): @@ -30,7 +30,7 @@ class ResPartner(models.Model): body = _('Email has been bounced: %s\n' 'Reason: %s\n' 'Event: %s') % (partner.email, reason, - event['Message-Id'] or '') + event.get('Message-Id', _('unknown'))) partner.message_post(body=body) @api.multi From a39b3fa92f8719555dade0ec6aba6b403479f04b Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 15 Jan 2018 13:00:28 +0000 Subject: [PATCH 2/2] [FIX] mail_tracking_mailgun: Avoid errors without event When this method is called without an event (a.k.a. `event=None`), this method produces the following error: ``` Traceback (most recent call last): File "/opt/odoo/auto/addons/mail/models/mail_mail.py", line 278, in send res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id) File "/opt/odoo/auto/addons/mail_tracking/models/ir_mail_server.py", line 88, in send_email tracking_email.smtp_error(self, smtp_server_used, e) File "/opt/odoo/auto/addons/mail_tracking/models/mail_tracking_email.py", line 213, in smtp_error self.sudo()._partners_email_bounced_set('error') File "/opt/odoo/auto/addons/mail_tracking/models/mail_tracking_email.py", line 203, in _partners_email_bounced_set ]).email_bounced_set(self, reason, event=event) File "/opt/odoo/auto/addons/mail_tracking_mailgun/models/res_partner.py", line 22, in email_bounced_set self._email_bounced_set(reason, event) File "/opt/odoo/auto/addons/mail_tracking_mailgun/models/res_partner.py", line 33, in _email_bounced_set event['Message-Id'] or '') TypeError: 'NoneType' object has no attribute '__getitem__' ``` So, we now assume we do not always have an event. --- mail_tracking_mailgun/models/res_partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mail_tracking_mailgun/models/res_partner.py b/mail_tracking_mailgun/models/res_partner.py index 651b5cd7..9644e918 100644 --- a/mail_tracking_mailgun/models/res_partner.py +++ b/mail_tracking_mailgun/models/res_partner.py @@ -30,7 +30,8 @@ class ResPartner(models.Model): body = _('Email has been bounced: %s\n' 'Reason: %s\n' 'Event: %s') % (partner.email, reason, - event.get('Message-Id', _('unknown'))) + event and event.get('Message-Id', + _('unknown'))) partner.message_post(body=body) @api.multi