mirror of
https://github.com/simple-login/app.git
synced 2024-10-01 14:11:31 +02:00
append alias into the TO header if it's not present in To or CC
This commit is contained in:
parent
3b454b9a80
commit
a1bdd94ef1
@ -244,6 +244,17 @@ def get_or_create_forward_email(
|
|||||||
return forward_email
|
return forward_email
|
||||||
|
|
||||||
|
|
||||||
|
def should_append_alias(msg, alias):
|
||||||
|
"""whether an alias should be appened to TO header in message"""
|
||||||
|
|
||||||
|
if msg["To"] and alias in msg["To"]:
|
||||||
|
return False
|
||||||
|
if msg["Cc"] and alias in msg["Cc"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str:
|
def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str:
|
||||||
"""return *status_code message*"""
|
"""return *status_code message*"""
|
||||||
alias = rcpt_to.lower() # alias@SL
|
alias = rcpt_to.lower() # alias@SL
|
||||||
@ -281,6 +292,16 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> str:
|
|||||||
msg.replace_header("From", from_header)
|
msg.replace_header("From", from_header)
|
||||||
LOG.d("new from header:%s", from_header)
|
LOG.d("new from header:%s", from_header)
|
||||||
|
|
||||||
|
# append alias into the TO header if it's not present in To or CC
|
||||||
|
if should_append_alias(msg, alias):
|
||||||
|
LOG.d("append alias %s to TO header %s", alias, msg["To"])
|
||||||
|
if msg["To"]:
|
||||||
|
to_header = msg["To"] + "," + alias
|
||||||
|
else:
|
||||||
|
to_header = alias
|
||||||
|
|
||||||
|
msg.replace_header("To", to_header)
|
||||||
|
|
||||||
# add List-Unsubscribe header
|
# add List-Unsubscribe header
|
||||||
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||||
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
||||||
|
Loading…
Reference in New Issue
Block a user