Hello ${ctx.get('sender_message').get('from')},
we got a problem with your email: ${ctx.get('sender_message').get('subject')}
diff --git a/fetchmail_notify_error_to_sender/models/fetchmail.py b/fetchmail_notify_error_to_sender/models/fetchmail.py index 2becf8f2e..25658df99 100644 --- a/fetchmail_notify_error_to_sender/models/fetchmail.py +++ b/fetchmail_notify_error_to_sender/models/fetchmail.py @@ -7,9 +7,11 @@ from odoo import fields, models class FetchmailServer(models.Model): - _inherit = 'fetchmail.server' + _inherit = "fetchmail.server" error_notice_template_id = fields.Many2one( - 'mail.template', string="Error notice template", + "mail.template", + string="Error notice template", help="Set here the template to use to send notice to sender when " - "errors occur while fetching email") + "errors occur while fetching email", + ) diff --git a/fetchmail_notify_error_to_sender/models/mail_thread.py b/fetchmail_notify_error_to_sender/models/mail_thread.py index 1ab797fc2..0320145d3 100644 --- a/fetchmail_notify_error_to_sender/models/mail_thread.py +++ b/fetchmail_notify_error_to_sender/models/mail_thread.py @@ -7,26 +7,31 @@ from odoo import api, models class MailThread(models.AbstractModel): - _inherit = 'mail.thread' + _inherit = "mail.thread" @api.model - def message_route(self, message, message_dict, model=None, thread_id=None, - custom_values=None): + def message_route( + self, message, message_dict, model=None, thread_id=None, custom_values=None + ): try: res = super(MailThread, self).message_route( - message, message_dict, model=model, thread_id=thread_id, - custom_values=custom_values) + 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') + fetchmail_server_id = self.env.context.get("fetchmail_server_id") if not fetchmail_server_id: raise ve - fetchmail_server = self.env['fetchmail.server'].with_context({ - 'sender_message': message, - 'route_exception': ve, - }).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 - fetchmail_server.error_notice_template_id.send_mail( - fetchmail_server.id) + fetchmail_server.error_notice_template_id.send_mail(fetchmail_server.id) raise ve return res diff --git a/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py b/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py index 47f58b412..d89fd0157 100644 --- a/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py +++ b/fetchmail_notify_error_to_sender/tests/test_fetchmail_notify_error_to_sender.py @@ -1,38 +1,47 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import socket +from email.utils import formataddr + +from odoo.tools import mute_logger + from odoo.addons.test_mail.data.test_mail_data import MAIL_TEMPLATE from odoo.addons.test_mail.tests.test_mail_gateway import TestMailgateway -from odoo.tools import mute_logger -from email.utils import formataddr class TestFetchmailNotifyErrorToSender(TestMailgateway): - def setUp(self): super(TestFetchmailNotifyErrorToSender, self).setUp() - self.fetchmail_server = self.env['fetchmail.server'].create({ - 'name': 'Test Fetchmail Server', - 'type': 'imap', - 'error_notice_template_id': self.env.ref('%s.%s' % ( - 'fetchmail_notify_error_to_sender', - 'email_template_error_notice', - )).id - }) + self.fetchmail_server = self.env["fetchmail.server"].create( + { + "name": "Test Fetchmail Server", + "type": "imap", + "error_notice_template_id": self.env.ref( + "%s.%s" + % ( + "fetchmail_notify_error_to_sender", + "email_template_error_notice", + ) + ).id, + } + ) def format_and_process_with_context( - self, template, to_email='groups@example.com, other@gmail.com', - subject='Frogs', extra='', - email_from='Sylvie Lelitre