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.

75 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp.osv import osv
  21. class mail_thread(osv.AbstractModel):
  22. _inherit = 'mail.thread'
  23. def message_route_verify(
  24. self, cr, uid, message, message_dict, route, update_author=True,
  25. assert_model=True, create_fallback=True, allow_private=False,
  26. context=None
  27. ):
  28. res = ()
  29. if context is None:
  30. context = {}
  31. try:
  32. res = super(mail_thread, self).message_route_verify(
  33. cr, uid, message, message_dict, route,
  34. update_author=update_author, assert_model=assert_model,
  35. create_fallback=create_fallback, allow_private=allow_private,
  36. context=context)
  37. except ValueError as ve:
  38. fetchmail_server_id = context.get('fetchmail_server_id')
  39. if not fetchmail_server_id:
  40. raise ve
  41. fetchmail_server = self.pool['fetchmail.server'].browse(
  42. cr, uid, fetchmail_server_id, context)
  43. if not fetchmail_server.error_notice_template_id:
  44. raise ve
  45. context['sender_message'] = message
  46. context['route_exception'] = ve
  47. self.pool['email.template'].send_mail(
  48. cr, uid, fetchmail_server.error_notice_template_id.id,
  49. fetchmail_server.id, context=context)
  50. context['error_notice_sent'] = True
  51. return res
  52. def message_route(
  53. self, cr, uid, message, message_dict, model=None, thread_id=None,
  54. custom_values=None, context=None
  55. ):
  56. if context is None:
  57. context = {}
  58. res = []
  59. try:
  60. res = super(mail_thread, self).message_route(
  61. cr, uid, message, message_dict, model=model,
  62. thread_id=thread_id, custom_values=custom_values,
  63. context=context)
  64. except ValueError as ve:
  65. if context.get('error_notice_sent'):
  66. # avoid raising exception and setting mail message UNSEEN
  67. return []
  68. else:
  69. raise ve
  70. return res