Skip to content

Commit

Permalink
Preserve original from header in X-SimpleLogin-Original-From (simple-…
Browse files Browse the repository at this point in the history
…login#1784)

* Preserve original from in the headers

* Update the settings page

---------

Co-authored-by: Adrià Casajús <[email protected]>
  • Loading branch information
acasajus and acasajus authored Jun 23, 2023
1 parent 8512093 commit d3aae31
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/email/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
SL_DIRECTION = "X-SimpleLogin-Type"
SL_EMAIL_LOG_ID = "X-SimpleLogin-EmailLog-ID"
SL_ENVELOPE_FROM = "X-SimpleLogin-Envelope-From"
SL_ORIGINAL_FROM = "X-SimpleLogin-Original-From"
SL_ENVELOPE_TO = "X-SimpleLogin-Envelope-To"
SL_CLIENT_IP = "X-SimpleLogin-Client-IP"

Expand Down
1 change: 1 addition & 0 deletions email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def forward_email_to_mailbox(
msg[headers.SL_EMAIL_LOG_ID] = str(email_log.id)
if user.include_header_email_header:
msg[headers.SL_ENVELOPE_FROM] = envelope.mail_from
msg[headers.SL_ORIGINAL_FROM] = contact.website_email
# when an alias isn't in the To: header, there's no way for users to know what alias has received the email
msg[headers.SL_ENVELOPE_TO] = alias.email

Expand Down
3 changes: 2 additions & 1 deletion templates/dashboard/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@
SimpleLogin forwards emails to your mailbox from the <b>reverse-alias</b> and not from the <b>original</b>
sender address.
<br />
If this option is enabled, the original sender addresses is stored in the email header <b>X-SimpleLogin-Envelope-From</b>.
If this option is enabled, the original sender addresses is stored in the email header <b>X-SimpleLogin-Envelope-From</b>
and the original From header is stored in <b>X-SimpleLogin-Original-From<b>.
You can choose to display this header in your email client.
<br />
As email headers aren't encrypted, your mailbox service can know the sender address via this header.
Expand Down
1 change: 1 addition & 0 deletions tests/example_emls/replacement_on_forward_phase.eml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ References:
<[email protected]>
From: {{ sender_address }}
To: {{ recipient_address }}
CC: {{ cc_address }}
Subject: Something
Message-ID: <[email protected]>
X-Mailer: Front (1.0; +https://frontapp.com;
Expand Down
7 changes: 6 additions & 1 deletion tests/handler/test_preserved_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def test_original_headers_from_preserved():
original_sender_address = random_email()
msg = load_eml_file(
"replacement_on_forward_phase.eml",
{"sender_address": original_sender_address, "recipient_address": alias.email},
{
"sender_address": original_sender_address,
"recipient_address": alias.email,
"cc_address": random_email(),
},
)
envelope = Envelope()
envelope.mail_from = f"env.{original_sender_address}"
Expand All @@ -28,6 +32,7 @@ def test_original_headers_from_preserved():
assert len(send_requests) == 1
request = send_requests[0]
assert request.msg[headers.SL_ENVELOPE_FROM] == envelope.mail_from
assert request.msg[headers.SL_ORIGINAL_FROM] == original_sender_address
assert (
request.msg[headers.AUTHENTICATION_RESULTS]
== msg[headers.AUTHENTICATION_RESULTS]
Expand Down

0 comments on commit d3aae31

Please sign in to comment.