mirror of
https://github.com/simple-login/app.git
synced 2025-02-20 22:02:54 +08:00
move get_email_name, get_email_part to email_utils
This commit is contained in:
parent
88cef1b90d
commit
62e0ae27a0
3 changed files with 24 additions and 23 deletions
|
@ -134,3 +134,25 @@ def send_by_postfix(to_email, subject, plaintext, html):
|
|||
|
||||
def notify_admin(subject, html_content=""):
|
||||
send_by_postfix(ADMIN_EMAIL, subject, html_content, html_content)
|
||||
|
||||
|
||||
def get_email_name(email_from):
|
||||
"""parse email from header and return the name part
|
||||
First Last <ab@cd.com> -> First Last
|
||||
ab@cd.com -> ""
|
||||
"""
|
||||
if "<" in email_from:
|
||||
return email_from[: email_from.find("<")].strip()
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
def get_email_part(email_from):
|
||||
"""parse email from header and return the email part
|
||||
First Last <ab@cd.com> -> ab@cd.com
|
||||
ab@cd.com -> ""
|
||||
"""
|
||||
if "<" in email_from:
|
||||
return email_from[email_from.find("<") + 1 : email_from.find(">")].strip()
|
||||
|
||||
return email_from
|
||||
|
|
|
@ -39,6 +39,7 @@ from smtplib import SMTP
|
|||
from aiosmtpd.controller import Controller
|
||||
|
||||
from app.config import EMAIL_DOMAIN, POSTFIX_SERVER, URL
|
||||
from app.email_utils import get_email_name, get_email_part
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import GenEmail, ForwardEmail, ForwardEmailLog
|
||||
|
@ -257,28 +258,6 @@ def add_or_replace_header(msg: EmailMessage, header: str, value: str):
|
|||
msg.replace_header(header, value)
|
||||
|
||||
|
||||
def get_email_name(email_from):
|
||||
"""parse email from header and return the name part
|
||||
First Last <ab@cd.com> -> First Last
|
||||
ab@cd.com -> ""
|
||||
"""
|
||||
if "<" in email_from:
|
||||
return email_from[: email_from.find("<")].strip()
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
def get_email_part(email_from):
|
||||
"""parse email from header and return the email part
|
||||
First Last <ab@cd.com> -> ab@cd.com
|
||||
ab@cd.com -> ""
|
||||
"""
|
||||
if "<" in email_from:
|
||||
return email_from[email_from.find("<") + 1 : email_from.find(">")].strip()
|
||||
|
||||
return email_from
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
controller = Controller(MailHandler(), hostname="0.0.0.0", port=20381)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from email_handler import get_email_name, get_email_part
|
||||
from app.email_utils import get_email_name, get_email_part
|
||||
|
||||
|
||||
def test_get_email_name():
|
Loading…
Reference in a new issue