mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 07:43:54 +08:00
refactor: create generate_reply_email()
This commit is contained in:
parent
f10d18c020
commit
fee69d9546
1 changed files with 14 additions and 8 deletions
|
@ -226,14 +226,7 @@ def get_or_create_contact(website_from_header: str, alias: Alias) -> Contact:
|
||||||
website_from_header,
|
website_from_header,
|
||||||
)
|
)
|
||||||
|
|
||||||
# generate a reply_email, make sure it is unique
|
reply_email = generate_reply_email()
|
||||||
# not use while loop to avoid infinite loop
|
|
||||||
reply_email = f"reply+{random_string(30)}@{EMAIL_DOMAIN}"
|
|
||||||
for _ in range(1000):
|
|
||||||
if not Contact.get_by(reply_email=reply_email):
|
|
||||||
# found!
|
|
||||||
break
|
|
||||||
reply_email = f"reply+{random_string(30)}@{EMAIL_DOMAIN}"
|
|
||||||
|
|
||||||
contact = Contact.create(
|
contact = Contact.create(
|
||||||
user_id=alias.user_id,
|
user_id=alias.user_id,
|
||||||
|
@ -247,6 +240,19 @@ def get_or_create_contact(website_from_header: str, alias: Alias) -> Contact:
|
||||||
return contact
|
return contact
|
||||||
|
|
||||||
|
|
||||||
|
def generate_reply_email():
|
||||||
|
# generate a reply_email, make sure it is unique
|
||||||
|
# not use while loop to avoid infinite loop
|
||||||
|
reply_email = f"reply+{random_string(30)}@{EMAIL_DOMAIN}"
|
||||||
|
for _ in range(1000):
|
||||||
|
if not Contact.get_by(reply_email=reply_email):
|
||||||
|
# found!
|
||||||
|
break
|
||||||
|
reply_email = f"reply+{random_string(30)}@{EMAIL_DOMAIN}"
|
||||||
|
|
||||||
|
return reply_email
|
||||||
|
|
||||||
|
|
||||||
def should_append_alias(msg: Message, address: str):
|
def should_append_alias(msg: Message, address: str):
|
||||||
"""whether an alias should be appened to TO header in message"""
|
"""whether an alias should be appened to TO header in message"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue