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.

31 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 api, models, 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. [
  10. tools.decode_message_header(message, "Delivered-To"),
  11. tools.decode_message_header(message, "To"),
  12. tools.decode_message_header(message, "Cc"),
  13. tools.decode_message_header(message, "Resent-To"),
  14. tools.decode_message_header(message, "Resent-Cc"),
  15. ]
  16. )
  17. rcpt_tos_websiteparts = [
  18. e.split("@")[1].lower() for e in tools.email_split(rcpt_tos)
  19. ]
  20. website = (
  21. self.env["website"].sudo().search([("domain", "in", rcpt_tos_websiteparts)])
  22. )
  23. if website:
  24. self = self.with_context(website_id=website[0].id)
  25. return super(MailThread, self).message_route_process(
  26. message, message_dict, routes
  27. )