From 25a299dfc1c371d19b1700337ea378c16bf3f16b Mon Sep 17 00:00:00 2001 From: David Beguin Date: Tue, 17 Sep 2019 11:22:53 +0000 Subject: [PATCH] [FIX] tools, crm : remove Flanker for email validation Since it appears that email validation feature from Flanker v0.9.0 is completelly broken (the lib explodes when calling address.validate_address('some@address.xxx')), Flanker is then removed and email validation will be done only using the email_normalize method. Task ID: 2044539 PR #37413 --- addons/crm/models/crm_lead.py | 2 +- odoo/tools/mail.py | 35 ----------------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 3a2b7acdde4..e57d4a771f7 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -237,7 +237,7 @@ class Lead(models.Model): if lead.email_from: email_state = 'incorrect' for email in email_split(lead.email_from): - if tools.email_validate(email): + if tools.email_normalize(email): email_state = 'correct' break lead.email_state = email_state diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 50ccd6b0375..f9a5cfa67cf 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -20,31 +20,6 @@ from odoo.tools import misc _logger = logging.getLogger(__name__) -# Optional Flanker dependency for email validation. -_flanker_warning = False -try: - from flanker.addresslib import address - if hasattr(address, 'six'): - # Python 3 supported - def checkmail(mail): - return bool(address.validate_address(mail)) - else: - def checkmail(mail): - global _flanker_warning - if not _flanker_warning: - _logger.info("Flanker version 0.9 or greater required for Python 3 compatibility") - _flanker_warning = True - return True - -except ImportError: - _logger.info('The flanker Python module is not installed, so email validation with flanker is unavailable') - def checkmail(mail): - global _flanker_warning - if not _flanker_warning: - _logger.info('The flanker Python module is not installed, so email validation with flanker is unavailable') - _flanker_warning = True - return True - #---------------------------------------------------------- # HTML Sanitizer #---------------------------------------------------------- @@ -531,16 +506,6 @@ def email_normalize(text): return False return emails[0].lower() -def email_validate(email): - """ - Check is the email is valid using email normalization + optional Flanker module. - If Flanker is installed, it will check if email is valid (checking DNS and other stuff). - If Flanker is not installed, this method only normalizes the email - :param text: string containing the email to validate - :return: normalized email if mail is valid or False - """ - return email_normalize(email) if checkmail(email) else False - def email_escape_char(email_address): """ Escape problematic characters in the given email address string""" return email_address.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_')