From 77e38e63fe80ea938610b38a7e3f832111ecaf7a Mon Sep 17 00:00:00 2001 From: Son Date: Sun, 21 Nov 2021 11:31:28 +0100 Subject: [PATCH] handle hotmail complaint during reply phase --- app/config.py | 2 ++ email_handler.py | 36 ++++++++++++++++++- .../hotmail-complaint-reply-phase.txt.jinja2 | 14 ++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 templates/emails/transactional/hotmail-complaint-reply-phase.txt.jinja2 diff --git a/app/config.py b/app/config.py index 40861570..e75ccf30 100644 --- a/app/config.py +++ b/app/config.py @@ -338,6 +338,8 @@ AlERT_WRONG_MX_RECORD_CUSTOM_DOMAIN = "custom_domain_mx_record_issue" ALERT_DIRECTORY_DISABLED_ALIAS_CREATION = "alert_directory_disabled_alias_creation" ALERT_HOTMAIL_COMPLAINT = "alert_hotmail_complaint" +ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE = "alert_hotmail_complaint_reply_phase" +ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL = "alert_hotmail_complaint_transactional" ALERT_YAHOO_COMPLAINT = "alert_yahoo_complaint" # <<<<< END ALERT EMAIL >>>> diff --git a/email_handler.py b/email_handler.py index 4acd4b3f..f3a83e9a 100644 --- a/email_handler.py +++ b/email_handler.py @@ -84,6 +84,8 @@ from app.config import ( ALERT_HOTMAIL_COMPLAINT, ALERT_YAHOO_COMPLAINT, TEMP_DIR, + ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL, + ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE, ) from app.db import Session from app.email import status, headers @@ -1399,6 +1401,38 @@ def handle_hotmail_complaint(msg: Message) -> bool: handle_hotmail_complain_for_transactional_email(user) return True + try: + _, from_address = parse_full_address(get_header_unicode(from_header)) + alias = Alias.get_by(email=from_address) + + # the email is during a reply phase, from=alias and to=destination + if alias: + user = alias.user + LOG.i( + "Hotmail complaint during reply phase %s -> %s, %s", + alias, + to_header, + user, + ) + send_email_with_rate_control( + user, + ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE, + user.email, + f"Hotmail abuse report", + render( + "transactional/hotmail-complaint-reply-phase.txt.jinja2", + user=user, + alias=alias, + destination=to_header, + ), + max_nb_alert=1, + nb_day=7, + ) + return True + + except ValueError: + LOG.w("Cannot parse %s", from_header) + alias = None # try parsing the from header which might contain the reverse alias @@ -1456,7 +1490,7 @@ def handle_hotmail_complain_for_transactional_email(user): """Handle the case when a transactional email is set as Spam by user or by HotMail""" send_email_with_rate_control( user, - ALERT_HOTMAIL_COMPLAINT, + ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL, user.email, f"Hotmail abuse report", render("transactional/hotmail-transactional-complaint.txt.jinja2", user=user), diff --git a/templates/emails/transactional/hotmail-complaint-reply-phase.txt.jinja2 b/templates/emails/transactional/hotmail-complaint-reply-phase.txt.jinja2 new file mode 100644 index 00000000..860b89dd --- /dev/null +++ b/templates/emails/transactional/hotmail-complaint-reply-phase.txt.jinja2 @@ -0,0 +1,14 @@ +Hi, + +This is SimpleLogin team. + +Hotmail has informed us about an email sent from your alias {{ alias.email }} to {{ destination }} that might have been considered as spam, either by the recipient or by their Hotmail spam filter. + +Please note that sending non-solicited from a SimpleLogin alias infringes our terms and condition as it severely affects SimpleLogin email delivery. + +If somehow the recipient's Hotmail considers a forwarded email as Spam, it helps us a lot if you can ask them to move the email out of their Spam folder. + +Looking to hear back from you. + +Best, +SimpleLogin Team. \ No newline at end of file