mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 15:23:27 +08:00
Create alias on the fly if it belongs to a directory
This commit is contained in:
parent
cdae3c5309
commit
9377e2a0ed
1 changed files with 39 additions and 13 deletions
|
@ -50,7 +50,7 @@ from app.email_utils import (
|
|||
)
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import GenEmail, ForwardEmail, ForwardEmailLog, CustomDomain
|
||||
from app.models import GenEmail, ForwardEmail, ForwardEmailLog, CustomDomain, Directory
|
||||
from app.utils import random_string
|
||||
from server import create_app
|
||||
|
||||
|
@ -112,11 +112,36 @@ class MailHandler:
|
|||
if not gen_email:
|
||||
LOG.d("alias %s not exist")
|
||||
|
||||
# try to see if alias could be created on-the-fly
|
||||
on_the_fly = False
|
||||
|
||||
# check if alias belongs to a directory. In this case alias has one of the 2 formats:
|
||||
# directory/anything@EMAIL_DOMAIN or directory+anything@EMAIL_DOMAIN
|
||||
if alias.endswith(EMAIL_DOMAIN):
|
||||
if "+" in alias or "/" in alias:
|
||||
if "+" in alias:
|
||||
directory_name = alias[alias.find("+")]
|
||||
else:
|
||||
directory_name = alias[alias.find("/")]
|
||||
|
||||
directory = Directory.get_by(name=directory_name)
|
||||
if directory:
|
||||
LOG.d("create alias %s for directory %s", alias, directory)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
user_id=directory.user_id,
|
||||
directory_id=directory.id,
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
# check if alias is custom-domain alias and if the custom-domain has catch-all enabled
|
||||
alias_domain = get_email_domain_part(alias)
|
||||
custom_domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain and custom_domain.catch_all:
|
||||
LOG.d("create alias %s for domain %s", alias, custom_domain)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
|
@ -125,7 +150,8 @@ class MailHandler:
|
|||
automatic_creation=True,
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
|
||||
if not on_the_fly:
|
||||
return "510 Email not exist"
|
||||
|
||||
user_email = gen_email.user.email
|
||||
|
|
Loading…
Reference in a new issue