From 0300d38f565b1112aa5b19caa3cf2468822989c0 Mon Sep 17 00:00:00 2001 From: Son NK Date: Wed, 8 Jan 2020 12:42:25 +0100 Subject: [PATCH 1/3] make sure delete_header() delete all headers occurences --- app/email_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 895a5614..bb78c740 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -208,5 +208,8 @@ def add_or_replace_header(msg: Message, header: str, value: str): def delete_header(msg: Message, header: str): - if msg[header]: - del msg[header] + """a header can appear several times in message.""" + for h in msg._headers: + if h[0].lower() == header.lower(): + msg._headers.remove(h) + From aea4426e1e21c112129536ca623cc3d2ce20996a Mon Sep 17 00:00:00 2001 From: Son NK Date: Wed, 8 Jan 2020 12:44:29 +0100 Subject: [PATCH 2/3] make sure user original email not revealed in Received-SPF header --- email_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/email_handler.py b/email_handler.py index 20ff8e3c..ab754274 100644 --- a/email_handler.py +++ b/email_handler.py @@ -110,7 +110,7 @@ class MailHandler: gen_email = GenEmail.get_by(email=alias) if not gen_email: - LOG.d("alias %s not exist") + LOG.d("alias %s not exist", alias) # check if alias is custom-domain alias and if the custom-domain has catch-all enabled alias_domain = get_email_domain_part(alias) @@ -264,6 +264,9 @@ class MailHandler: msg, "List-Unsubscribe-Post", "List-Unsubscribe=One-Click" ) + # Received-SPF is injected by postfix-policyd-spf-python can reveal user original email + delete_header(msg, "Received-SPF") + LOG.d( "send email from %s to %s, mail_options:%s,rcpt_options:%s", alias, From 434f82a244c6bda2f98b5d9f33b86e8b8b5629f8 Mon Sep 17 00:00:00 2001 From: Son NK Date: Wed, 8 Jan 2020 12:58:34 +0100 Subject: [PATCH 3/3] fix formatting --- app/email_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/email_utils.py b/app/email_utils.py index bb78c740..57d853eb 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -212,4 +212,3 @@ def delete_header(msg: Message, header: str): for h in msg._headers: if h[0].lower() == header.lower(): msg._headers.remove(h) -