add get_email_local_part(), get_email_domain_part() to email_utils

This commit is contained in:
Son NK 2019-12-30 18:18:10 +01:00
parent cae43fa0dd
commit b9908a16b2
3 changed files with 33 additions and 1 deletions

View File

@ -161,6 +161,22 @@ def get_email_part(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):
if msg["DKIM-Signature"]:
LOG.d("Remove DKIM-Signature %s", msg["DKIM-Signature"])

View File

@ -698,3 +698,6 @@ class CustomDomain(db.Model, ModelMixin):
def nb_alias(self):
return GenEmail.filter_by(custom_domain_id=self.id).count()
def __repr__(self):
return f"<Custom Domain {self.domain}>"

View File

@ -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():
@ -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("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"