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.

29 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright - 2013-2018 Therp BV <https://therp.nl>.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from .email_exact import EmailExact
  5. class EmailDomain(EmailExact):
  6. """Search objects by domain name of email address.
  7. Beware of match_first here, this is most likely to get it wrong (gmail).
  8. """
  9. name = 'Domain of email address'
  10. def search_matches(self, folder, mail_message, mail_message_org):
  11. """Returns recordset of matching objects."""
  12. matches = super(EmailDomain, self).search_matches(
  13. folder, mail_message, mail_message_org)
  14. if not matches:
  15. object_model = folder.env[folder.model_id.model]
  16. domains = []
  17. for addr in self._get_mailaddresses(folder, mail_message):
  18. domains.append(addr.split('@')[-1])
  19. matches = object_model.search(
  20. self._get_mailaddress_search_domain(
  21. folder, mail_message,
  22. operator='like',
  23. values=['%@' + domain for domain in set(domains)]),
  24. order=folder.model_order)
  25. return matches