Use send_email_with_rate_control when alerting user

This commit is contained in:
Son NK 2020-05-09 20:45:04 +02:00
parent d9f1fb9130
commit 7833d4609f
1 changed files with 19 additions and 5 deletions

View File

@ -56,6 +56,9 @@ from app.config import (
UNSUBSCRIBER, UNSUBSCRIBER,
LOAD_PGP_EMAIL_HANDLER, LOAD_PGP_EMAIL_HANDLER,
ENFORCE_SPF, ENFORCE_SPF,
ALERT_REVERSE_ALIAS_UNKNOWN_MAILBOX,
ALERT_BOUNCE_EMAIL,
ALERT_SPAM_EMAIL,
) )
from app.email_utils import ( from app.email_utils import (
send_email, send_email,
@ -70,6 +73,7 @@ from app.email_utils import (
get_spam_info, get_spam_info,
get_orig_message_from_spamassassin_report, get_orig_message_from_spamassassin_report,
parseaddr_unicode, parseaddr_unicode,
send_email_with_rate_control,
) )
from app.extensions import db from app.extensions import db
from app.greylisting import greylisting_needed from app.greylisting import greylisting_needed
@ -511,7 +515,9 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
reply_email, reply_email,
) )
send_email( send_email_with_rate_control(
user,
ALERT_REVERSE_ALIAS_UNKNOWN_MAILBOX,
mailbox_email, mailbox_email,
f"Reply from your alias {alias.email} only works from your mailbox", f"Reply from your alias {alias.email} only works from your mailbox",
render( render(
@ -531,7 +537,9 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
) )
# Notify sender that they cannot send emails to this address # Notify sender that they cannot send emails to this address
send_email( send_email_with_rate_control(
user,
ALERT_REVERSE_ALIAS_UNKNOWN_MAILBOX,
envelope.mail_from, envelope.mail_from,
f"Your email ({envelope.mail_from}) is not allowed to send emails to {reply_email}", f"Your email ({envelope.mail_from}) is not allowed to send emails to {reply_email}",
render( render(
@ -660,7 +668,9 @@ def handle_bounce(
contact.website_email, contact.website_email,
address, address,
) )
send_email( send_email_with_rate_control(
user,
ALERT_BOUNCE_EMAIL,
# use user mail here as only user is authenticated to see the refused email # use user mail here as only user is authenticated to see the refused email
user.email, user.email,
f"Email from {contact.website_email} to {address} cannot be delivered to your inbox", f"Email from {contact.website_email} to {address} cannot be delivered to your inbox",
@ -695,7 +705,9 @@ def handle_bounce(
alias.enabled = False alias.enabled = False
db.session.commit() db.session.commit()
send_email( send_email_with_rate_control(
user,
ALERT_BOUNCE_EMAIL,
# use user mail here as only user is authenticated to see the refused email # use user mail here as only user is authenticated to see the refused email
user.email, user.email,
f"Alias {address} has been disabled due to second undelivered email from {contact.website_email}", f"Alias {address} has been disabled due to second undelivered email from {contact.website_email}",
@ -765,7 +777,9 @@ def handle_spam(
contact.website_email, contact.website_email,
alias.email, alias.email,
) )
send_email( send_email_with_rate_control(
user,
ALERT_SPAM_EMAIL,
mailbox_email, mailbox_email,
f"Email from {contact.website_email} to {alias.email} is detected as spam", f"Email from {contact.website_email} to {alias.email} is detected as spam",
render( render(