mirror of
https://github.com/simple-login/app.git
synced 2024-09-27 20:31:30 +02:00
small refactor: add should_add_dkim_signature
This commit is contained in:
parent
e79522b638
commit
1fcf166c00
@ -37,7 +37,7 @@ from app.config import (
|
||||
from app.dns_utils import get_mx_domains
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import Mailbox, User, SentAlert, CustomDomain
|
||||
from app.models import Mailbox, User, SentAlert, CustomDomain, PublicDomain
|
||||
|
||||
|
||||
def render(template_name, **kwargs) -> str:
|
||||
@ -627,3 +627,14 @@ def to_bytes(msg: Message):
|
||||
except UnicodeEncodeError:
|
||||
LOG.warning("as_bytes fails with SMTP policy, try SMTPUTF8 policy")
|
||||
return msg.as_bytes(policy=email.policy.SMTPUTF8)
|
||||
|
||||
|
||||
def should_add_dkim_signature(domain: str) -> bool:
|
||||
if PublicDomain.get_by(domain=domain):
|
||||
return True
|
||||
|
||||
custom_domain: CustomDomain = CustomDomain.get_by(domain=domain)
|
||||
if custom_domain.dkim_verified:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -98,6 +98,7 @@ from app.email_utils import (
|
||||
get_header_from_bounce,
|
||||
send_email_at_most_times,
|
||||
is_valid_alias_address_domain,
|
||||
should_add_dkim_signature,
|
||||
)
|
||||
from app.extensions import db
|
||||
from app.greylisting import greylisting_needed
|
||||
@ -874,12 +875,7 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str):
|
||||
else:
|
||||
msg = replace_str_in_msg(msg, reply_email, contact.website_email)
|
||||
|
||||
if alias_domain in ALIAS_DOMAINS or alias_domain in PREMIUM_ALIAS_DOMAINS:
|
||||
add_dkim_signature(msg, alias_domain)
|
||||
# add DKIM-Signature for custom-domain alias
|
||||
else:
|
||||
custom_domain: CustomDomain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain.dkim_verified:
|
||||
if should_add_dkim_signature(alias_domain):
|
||||
add_dkim_signature(msg, alias_domain)
|
||||
|
||||
# create PGP email if needed
|
||||
|
Loading…
Reference in New Issue
Block a user