You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015-2017 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
  3. # Copyright 2017 Eficent <http://www.eficent.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, models
  6. class MailThread(models.AbstractModel):
  7. _inherit = 'mail.thread'
  8. @api.model
  9. def message_route(self, message, message_dict, model=None, thread_id=None,
  10. custom_values=None):
  11. try:
  12. res = super(MailThread, self).message_route(
  13. message, message_dict, model=model, thread_id=thread_id,
  14. custom_values=custom_values)
  15. except ValueError as ve:
  16. fetchmail_server_id = self.env.context.get('fetchmail_server_id')
  17. if not fetchmail_server_id:
  18. raise ve
  19. fetchmail_server = self.env['fetchmail.server'].with_context({
  20. 'sender_message': message,
  21. 'route_exception': ve,
  22. }).browse(fetchmail_server_id)
  23. if not fetchmail_server.error_notice_template_id:
  24. raise ve
  25. fetchmail_server.error_notice_template_id.send_mail(
  26. fetchmail_server.id)
  27. raise ve
  28. return res