add get_email_local_part(), get_email_domain_part() to email_utils
This commit is contained in:
parent
cae43fa0dd
commit
b9908a16b2
|
@ -161,6 +161,22 @@ def get_email_part(email_from):
|
||||||
return email_from
|
return email_from
|
||||||
|
|
||||||
|
|
||||||
|
def get_email_local_part(email):
|
||||||
|
"""
|
||||||
|
Get the local part from email
|
||||||
|
ab@cd.com -> ab
|
||||||
|
"""
|
||||||
|
return email[: email.find("@")]
|
||||||
|
|
||||||
|
|
||||||
|
def get_email_domain_part(email):
|
||||||
|
"""
|
||||||
|
Get the domain part from email
|
||||||
|
ab@cd.com -> cd.com
|
||||||
|
"""
|
||||||
|
return email[email.find("@") + 1 :]
|
||||||
|
|
||||||
|
|
||||||
def add_dkim_signature(msg: EmailMessage, email_domain: str):
|
def add_dkim_signature(msg: EmailMessage, email_domain: str):
|
||||||
if msg["DKIM-Signature"]:
|
if msg["DKIM-Signature"]:
|
||||||
LOG.d("Remove DKIM-Signature %s", msg["DKIM-Signature"])
|
LOG.d("Remove DKIM-Signature %s", msg["DKIM-Signature"])
|
||||||
|
|
|
@ -698,3 +698,6 @@ class CustomDomain(db.Model, ModelMixin):
|
||||||
|
|
||||||
def nb_alias(self):
|
def nb_alias(self):
|
||||||
return GenEmail.filter_by(custom_domain_id=self.id).count()
|
return GenEmail.filter_by(custom_domain_id=self.id).count()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Custom Domain {self.domain}>"
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
from app.email_utils import get_email_name, get_email_part
|
from app.email_utils import (
|
||||||
|
get_email_name,
|
||||||
|
get_email_part,
|
||||||
|
get_email_local_part,
|
||||||
|
get_email_domain_part,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_email_name():
|
def test_get_email_name():
|
||||||
|
@ -13,3 +18,11 @@ def test_get_email_part():
|
||||||
assert get_email_part("First Last<ab@cd.com>") == "ab@cd.com"
|
assert get_email_part("First Last<ab@cd.com>") == "ab@cd.com"
|
||||||
assert get_email_part(" First Last <ab@cd.com>") == "ab@cd.com"
|
assert get_email_part(" First Last <ab@cd.com>") == "ab@cd.com"
|
||||||
assert get_email_part("ab@cd.com") == "ab@cd.com"
|
assert get_email_part("ab@cd.com") == "ab@cd.com"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_email_local_part():
|
||||||
|
assert get_email_local_part("ab@cd.com") == "ab"
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_email_domain_part():
|
||||||
|
assert get_email_domain_part("ab@cd.com") == "cd.com"
|
||||||
|
|
Loading…
Reference in a new issue