mail_validation.py 888 B

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import logging
  4. from odoo import tools
  5. _logger = logging.getLogger(__name__)
  6. _flanker_lib_warning = False
  7. try:
  8. from flanker.addresslib import address
  9. # Avoid warning each time a mx server is not reachable by flanker
  10. logging.getLogger("flanker.addresslib.validate").setLevel(logging.ERROR)
  11. def mail_validate(email):
  12. return bool(address.validate_address(email))
  13. except ImportError:
  14. def mail_validate(email):
  15. global _flanker_lib_warning
  16. if not _flanker_lib_warning:
  17. _flanker_lib_warning = True
  18. _logger.info("The `flanker` Python module is not installed,"
  19. "so email validation fallback to email_normalize. Use 'pip install flanker' to install it")
  20. return tools.email_normalize(email)