Upgrade methods from tools/email.py core
This commit is contained in:
parent
f3160efc38
commit
ced39b419d
2
series
2
series
|
@ -75,3 +75,5 @@ issue12349.diff # [marketing_email] Multiple mareting emails created at once hav
|
|||
product-cost-fifo-average.diff # [product_cost_fifo] [product_cost_history] [stock] Add product cost price to move
|
||||
|
||||
issue10650.diff # [account_dunning_email] [marketing_automation] [marketing_email] [notification_email] [trytond] Support RFC6530 on email formatting
|
||||
|
||||
tools-email.diff # [trytond] tools email
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
diff --git a/tryton/trytond/trytond/tools/email_.py b/tryton/trytond/trytond/tools/email_.py
|
||||
index f8141ec84d..061f01a17e 100644
|
||||
--- a/tryton/trytond/trytond/tools/email_.py
|
||||
+++ b/tryton/trytond/trytond/tools/email_.py
|
||||
@@ -2,6 +2,12 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from email.utils import parseaddr
|
||||
|
||||
+from trytond.pool import Pool
|
||||
+
|
||||
+__all__ = [
|
||||
+ 'set_from_header', 'validate_email', 'normalize_email',
|
||||
+ 'convert_ascii_email', 'EmailNotValidError']
|
||||
+
|
||||
|
||||
def _domainaddr(address):
|
||||
_, email = parseaddr(address)
|
||||
@@ -21,3 +27,49 @@ def set_from_header(message, sender, from_):
|
||||
message['Reply-To'] = from_
|
||||
else:
|
||||
message['From'] = from_
|
||||
+
|
||||
+
|
||||
+try:
|
||||
+ from email_validator import EmailNotValidError, caching_resolver
|
||||
+ from email_validator import validate_email as _validate_email
|
||||
+
|
||||
+ resolver = caching_resolver()
|
||||
+
|
||||
+ def validate_email(email):
|
||||
+ emailinfo = _validate_email(
|
||||
+ email, check_deliverability=True,
|
||||
+ dns_resolver=resolver,
|
||||
+ test_environment=Pool.test)
|
||||
+ return emailinfo.normalized
|
||||
+
|
||||
+ def normalize_email(email):
|
||||
+ try:
|
||||
+ emailinfo = _validate_email(
|
||||
+ email, check_deliverability=False,
|
||||
+ test_environment=Pool.test)
|
||||
+ return emailinfo.normalized
|
||||
+ except EmailNotValidError:
|
||||
+ return email
|
||||
+
|
||||
+ def convert_ascii_email(email):
|
||||
+ try:
|
||||
+ emailinfo = _validate_email(
|
||||
+ email, check_deliverability=False,
|
||||
+ test_environment=Pool.test)
|
||||
+ return emailinfo.ascii_email
|
||||
+ except EmailNotValidError:
|
||||
+ return email
|
||||
+
|
||||
+except ImportError:
|
||||
+
|
||||
+ def validate_email(email):
|
||||
+ return email
|
||||
+
|
||||
+ def normalize_email(email):
|
||||
+ return email
|
||||
+
|
||||
+ def convert_ascii_email(email):
|
||||
+ return email
|
||||
+
|
||||
+ class EmailNotValidError(Exception):
|
||||
+ pass
|
Loading…
Reference in New Issue