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.

53 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 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 openerp import api, models
  6. class MailThread(models.AbstractModel):
  7. _inherit = 'mail.thread'
  8. @api.model
  9. def message_route_verify(
  10. self, message, message_dict, route, update_author=True,
  11. assert_model=True, create_fallback=True, allow_private=False):
  12. res = ()
  13. try:
  14. res = super(MailThread, self).message_route_verify(
  15. message, message_dict, route,
  16. update_author=update_author, assert_model=assert_model,
  17. create_fallback=create_fallback, allow_private=allow_private)
  18. except ValueError as ve:
  19. fetchmail_server_id = self.env.context.get('fetchmail_server_id')
  20. if not fetchmail_server_id:
  21. raise ve
  22. fetchmail_server = self.pool['fetchmail.server'].browse(
  23. fetchmail_server_id)
  24. if not fetchmail_server.error_notice_template_id:
  25. raise ve
  26. self.env.context['sender_message'] = message
  27. self.env.context['route_exception'] = ve
  28. self.env['mail.template'].send_mail(
  29. fetchmail_server.error_notice_template_id.id,
  30. fetchmail_server.id)
  31. self.env.context['error_notice_sent'] = True
  32. return res
  33. @api.model
  34. def message_route(
  35. self, message, message_dict, model=None, thread_id=None,
  36. custom_values=None):
  37. res = []
  38. try:
  39. res = super(MailThread, self).message_route(
  40. message, message_dict, model=model,
  41. thread_id=thread_id, custom_values=custom_values)
  42. except ValueError as ve:
  43. if self.env.context.get('error_notice_sent'):
  44. # avoid raising exception and setting mail message UNSEEN
  45. return []
  46. else:
  47. raise ve
  48. return res