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.

26 lines
1.1 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo import models, api, tools
  4. class MailThread(models.AbstractModel):
  5. _inherit = 'mail.thread'
  6. @api.model
  7. def message_route_process(self, message, message_dict, routes):
  8. rcpt_tos = ','.join([
  9. tools.decode_message_header(message, 'Delivered-To'),
  10. tools.decode_message_header(message, 'To'),
  11. tools.decode_message_header(message, 'Cc'),
  12. tools.decode_message_header(message, 'Resent-To'),
  13. tools.decode_message_header(message, 'Resent-Cc')])
  14. rcpt_tos_websiteparts = [e.split('@')[1].lower() for e in tools.email_split(rcpt_tos)]
  15. website = self.env['website'].sudo().search([
  16. ('domain', 'in', rcpt_tos_websiteparts)
  17. ])
  18. if website:
  19. self = self.with_context(website_id=website[0].id)
  20. return super(MailThread, self).message_route_process(
  21. message, message_dict, routes
  22. )