Skip to content

Commit

Permalink
Preserve X-SL-Queue-Id (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus authored Mar 22, 2024
1 parent 0da1811 commit 36cf530
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/email/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
LIST_UNSUBSCRIBE_POST = "List-Unsubscribe-Post"
RETURN_PATH = "Return-Path"
AUTHENTICATION_RESULTS = "Authentication-Results"
SL_QUEUE_ID = "X-SL-Queue-Id"

# headers used to DKIM sign in order of preference
DKIM_HEADERS = [
Expand Down
1 change: 1 addition & 0 deletions email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ def forward_email_to_mailbox(
# References and In-Reply-To are used for keeping the email thread
headers.REFERENCES,
headers.IN_REPLY_TO,
headers.SL_QUEUE_ID,
headers.LIST_UNSUBSCRIBE,
headers.LIST_UNSUBSCRIBE_POST,
] + headers.MIME_HEADERS
Expand Down
27 changes: 27 additions & 0 deletions tests/test_email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,30 @@ def test_break_loop_alias_as_mailbox(flask_client):
msg[headers.SUBJECT] = random_string()
result = email_handler.handle(envelope, msg)
assert result == status.E525


@mail_sender.store_emails_test_decorator
def test_preserve_headers(flask_client):
headers_to_keep = [
headers.SUBJECT,
headers.DATE,
headers.MESSAGE_ID,
headers.REFERENCES,
headers.IN_REPLY_TO,
headers.SL_QUEUE_ID,
] + headers.MIME_HEADERS
user = create_new_user()
alias = Alias.create_new_random(user)
envelope = Envelope()
envelope.mail_from = "somewhere@lo.cal"
envelope.rcpt_tos = [alias.email]
msg = EmailMessage()
for header in headers_to_keep:
msg[header] = header + "keep"
result = email_handler.handle(envelope, msg)
assert result == status.E200
sent_mails = mail_sender.get_stored_emails()
assert len(sent_mails) == 1
msg = sent_mails[0].msg
for header in headers_to_keep:
assert msg[header] == header + "keep"

0 comments on commit 36cf530

Please sign in to comment.