From 168d6d07ca86173bdde1f68c317d025821b03dfa Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 13 Jul 2017 18:05:36 +0200 Subject: [PATCH] porting fetchmail_notify_error_to_sender to 10.0 --- .../models/mail_thread.py | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/fetchmail_notify_error_to_sender/models/mail_thread.py b/fetchmail_notify_error_to_sender/models/mail_thread.py index bbe78b70d..d90a19086 100644 --- a/fetchmail_notify_error_to_sender/models/mail_thread.py +++ b/fetchmail_notify_error_to_sender/models/mail_thread.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2015 Lorenzo Battistini +# Copyright 2015-2017 Lorenzo Battistini # Copyright 2017 Eficent # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -10,44 +10,23 @@ class MailThread(models.AbstractModel): _inherit = 'mail.thread' @api.model - def message_route_verify( - self, message, message_dict, route, update_author=True, - assert_model=True, create_fallback=True, allow_private=False): - res = () + def message_route(self, message, message_dict, model=None, thread_id=None, + custom_values=None): try: - res = super(MailThread, self).message_route_verify( - message, message_dict, route, - update_author=update_author, assert_model=assert_model, - create_fallback=create_fallback, allow_private=allow_private) + res = super(MailThread, self).message_route( + message, message_dict, model=model, thread_id=thread_id, + custom_values=custom_values) except ValueError as ve: fetchmail_server_id = self.env.context.get('fetchmail_server_id') if not fetchmail_server_id: raise ve - fetchmail_server = self.pool['fetchmail.server'].browse( - fetchmail_server_id) + fetchmail_server = self.env['fetchmail.server'].with_context({ + 'sender_message': message, + 'route_exception': ve, + }).browse(fetchmail_server_id) if not fetchmail_server.error_notice_template_id: raise ve - self.env.context['sender_message'] = message - self.env.context['route_exception'] = ve - self.env['mail.template'].send_mail( - fetchmail_server.error_notice_template_id.id, + fetchmail_server.error_notice_template_id.send_mail( fetchmail_server.id) - self.env.context['error_notice_sent'] = True - return res - - @api.model - def message_route( - self, message, message_dict, model=None, thread_id=None, - custom_values=None): - res = [] - try: - res = super(MailThread, self).message_route( - message, message_dict, model=model, - thread_id=thread_id, custom_values=custom_values) - except ValueError as ve: - if self.env.context.get('error_notice_sent'): - # avoid raising exception and setting mail message UNSEEN - return [] - else: - raise ve + raise ve return res