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.

34 lines
1.3 KiB

  1. # Copyright 2018,2020 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License MIT (https://opensource.org/licenses/MIT).
  3. # License OPL-1 (https://www.odoo.com/documentation/user/13.0/legal/licenses/licenses.html#odoo-apps) for derivative work.
  4. from odoo import api, models, tools
  5. class MailThread(models.AbstractModel):
  6. _inherit = "mail.thread"
  7. @api.model
  8. def _message_route_process(self, message, message_dict, routes):
  9. rcpt_tos = ",".join(
  10. [
  11. tools.decode_message_header(message, "Delivered-To"),
  12. tools.decode_message_header(message, "To"),
  13. tools.decode_message_header(message, "Cc"),
  14. tools.decode_message_header(message, "Resent-To"),
  15. tools.decode_message_header(message, "Resent-Cc"),
  16. ]
  17. )
  18. rcpt_tos_websiteparts = [
  19. e.split("@")[1].lower() for e in tools.email_split(rcpt_tos)
  20. ]
  21. website = (
  22. self.env["website"].sudo().search([("domain", "in", rcpt_tos_websiteparts)])
  23. )
  24. company = website.mapped("company_id")
  25. new_self = self.with_context(
  26. allowed_website_ids=website.ids, allowed_company_ids=company.ids
  27. )
  28. return super(MailThread, new_self)._message_route_process(
  29. message, message_dict, routes
  30. )