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.

28 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):
  11. """Returns recordset of matching objects."""
  12. matches = super(EmailDomain, self).search_matches(folder, mail_message)
  13. if not matches:
  14. object_model = folder.env[folder.model_id.model]
  15. domains = []
  16. for addr in self._get_mailaddresses(folder, mail_message):
  17. domains.append(addr.split('@')[-1])
  18. matches = object_model.search(
  19. self._get_mailaddress_search_domain(
  20. folder, mail_message,
  21. operator='like',
  22. values=['%@' + domain for domain in set(domains)]),
  23. order=folder.model_order)
  24. return matches