mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 08:13:16 +08:00
Use validate_email in get_email_local_part and get_email_domain_part
This commit is contained in:
parent
2b84168d68
commit
a6c874e914
1 changed files with 10 additions and 4 deletions
|
@ -19,7 +19,7 @@ from typing import Tuple, List, Optional, Union
|
||||||
import arrow
|
import arrow
|
||||||
import dkim
|
import dkim
|
||||||
import spf
|
import spf
|
||||||
from email_validator import validate_email, EmailNotValidError
|
from email_validator import validate_email, EmailNotValidError, ValidatedEmail
|
||||||
from flanker.addresslib import address
|
from flanker.addresslib import address
|
||||||
from flanker.addresslib.address import EmailAddress
|
from flanker.addresslib.address import EmailAddress
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
@ -379,8 +379,12 @@ def get_email_local_part(address) -> str:
|
||||||
"""
|
"""
|
||||||
Get the local part from email
|
Get the local part from email
|
||||||
ab@cd.com -> ab
|
ab@cd.com -> ab
|
||||||
|
Convert the local part to lowercase
|
||||||
"""
|
"""
|
||||||
return address[: address.find("@")]
|
r: ValidatedEmail = validate_email(
|
||||||
|
address, check_deliverability=False, allow_smtputf8=False
|
||||||
|
)
|
||||||
|
return r.local_part.lower()
|
||||||
|
|
||||||
|
|
||||||
def get_email_domain_part(address):
|
def get_email_domain_part(address):
|
||||||
|
@ -388,8 +392,10 @@ def get_email_domain_part(address):
|
||||||
Get the domain part from email
|
Get the domain part from email
|
||||||
ab@cd.com -> cd.com
|
ab@cd.com -> cd.com
|
||||||
"""
|
"""
|
||||||
address = sanitize_email(address)
|
r: ValidatedEmail = validate_email(
|
||||||
return address[address.find("@") + 1 :]
|
address, check_deliverability=False, allow_smtputf8=False
|
||||||
|
)
|
||||||
|
return r.domain
|
||||||
|
|
||||||
|
|
||||||
# headers used to DKIM sign in order of preference
|
# headers used to DKIM sign in order of preference
|
||||||
|
|
Loading…
Reference in a new issue