add List-Unsubscribe header to block quickly an alias
This commit is contained in:
parent
45cef7a4ef
commit
cb14277bc7
|
@ -38,7 +38,7 @@ from smtplib import SMTP
|
||||||
|
|
||||||
from aiosmtpd.controller import Controller
|
from aiosmtpd.controller import Controller
|
||||||
|
|
||||||
from app.config import EMAIL_DOMAIN, POSTFIX_SERVER
|
from app.config import EMAIL_DOMAIN, POSTFIX_SERVER, URL
|
||||||
from app.email_utils import notify_admin
|
from app.email_utils import notify_admin
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
|
@ -158,8 +158,11 @@ class MailHandler:
|
||||||
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)
|
||||||
|
|
||||||
original_subject = msg["Subject"]
|
# add List-Unsubscribe header
|
||||||
|
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||||
|
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
||||||
|
|
||||||
|
original_subject = msg["Subject"]
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"Forward mail from %s to %s, subject %s, mail_options %s, rcpt_options %s ",
|
"Forward mail from %s to %s, subject %s, mail_options %s, rcpt_options %s ",
|
||||||
website_email,
|
website_email,
|
||||||
|
@ -195,6 +198,10 @@ class MailHandler:
|
||||||
msg.replace_header("From", alias)
|
msg.replace_header("From", alias)
|
||||||
msg.replace_header("To", forward_email.website_email)
|
msg.replace_header("To", forward_email.website_email)
|
||||||
|
|
||||||
|
# add List-Unsubscribe header
|
||||||
|
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{forward_email.gen_email_id}"
|
||||||
|
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
||||||
|
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"send email from %s to %s, mail_options:%s,rcpt_options:%s",
|
"send email from %s to %s, mail_options:%s,rcpt_options:%s",
|
||||||
alias,
|
alias,
|
||||||
|
@ -217,6 +224,14 @@ class MailHandler:
|
||||||
return "250 Message accepted for delivery"
|
return "250 Message accepted for delivery"
|
||||||
|
|
||||||
|
|
||||||
|
def add_or_replace_header(msg: EmailMessage, header: str, value: str):
|
||||||
|
try:
|
||||||
|
msg.add_header(header, value)
|
||||||
|
except ValueError:
|
||||||
|
# the header exists already
|
||||||
|
msg.replace_header(header, value)
|
||||||
|
|
||||||
|
|
||||||
def get_email_name(email_from):
|
def get_email_name(email_from):
|
||||||
"""parse email from header and return the name part
|
"""parse email from header and return the name part
|
||||||
First Last <ab@cd.com> -> First Last
|
First Last <ab@cd.com> -> First Last
|
||||||
|
|
Loading…
Reference in New Issue