mirror of
https://github.com/simple-login/app.git
synced 2025-10-09 06:50:45 +08:00
Preserve also contact name in Original-From (#1787)
Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
This commit is contained in:
parent
ac9d550069
commit
fc205157a8
2 changed files with 40 additions and 1 deletions
|
@ -899,7 +899,11 @@ def forward_email_to_mailbox(
|
||||||
msg[headers.SL_EMAIL_LOG_ID] = str(email_log.id)
|
msg[headers.SL_EMAIL_LOG_ID] = str(email_log.id)
|
||||||
if user.include_header_email_header:
|
if user.include_header_email_header:
|
||||||
msg[headers.SL_ENVELOPE_FROM] = envelope.mail_from
|
msg[headers.SL_ENVELOPE_FROM] = envelope.mail_from
|
||||||
msg[headers.SL_ORIGINAL_FROM] = contact.website_email
|
if contact.name:
|
||||||
|
original_from = f"{contact.name} <{contact.website_email}>"
|
||||||
|
else:
|
||||||
|
original_from = contact.website_email
|
||||||
|
msg[headers.SL_ORIGINAL_FROM] = original_from
|
||||||
# when an alias isn't in the To: header, there's no way for users to know what alias has received the 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
|
msg[headers.SL_ENVELOPE_TO] = alias.email
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from app.db import Session
|
||||||
from app.email import headers, status
|
from app.email import headers, status
|
||||||
from app.mail_sender import mail_sender
|
from app.mail_sender import mail_sender
|
||||||
from app.models import Alias
|
from app.models import Alias
|
||||||
|
from app.utils import random_string
|
||||||
from tests.utils import create_new_user, load_eml_file, random_email
|
from tests.utils import create_new_user, load_eml_file, random_email
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,3 +38,37 @@ def test_original_headers_from_preserved():
|
||||||
request.msg[headers.AUTHENTICATION_RESULTS]
|
request.msg[headers.AUTHENTICATION_RESULTS]
|
||||||
== msg[headers.AUTHENTICATION_RESULTS]
|
== msg[headers.AUTHENTICATION_RESULTS]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mail_sender.store_emails_test_decorator
|
||||||
|
def test_original_headers_from_with_name_preserved():
|
||||||
|
user = create_new_user()
|
||||||
|
alias = Alias.create_new_random(user)
|
||||||
|
Session.flush()
|
||||||
|
assert user.include_header_email_header
|
||||||
|
original_sender_address = random_email()
|
||||||
|
name = random_string(10)
|
||||||
|
msg = load_eml_file(
|
||||||
|
"replacement_on_forward_phase.eml",
|
||||||
|
{
|
||||||
|
"sender_address": f"{name} <{original_sender_address}>",
|
||||||
|
"recipient_address": alias.email,
|
||||||
|
"cc_address": random_email(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
envelope = Envelope()
|
||||||
|
envelope.mail_from = f"env.{original_sender_address}"
|
||||||
|
envelope.rcpt_tos = [alias.email]
|
||||||
|
result = email_handler.MailHandler()._handle(envelope, msg)
|
||||||
|
assert result == status.E200
|
||||||
|
send_requests = mail_sender.get_stored_emails()
|
||||||
|
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] == f"{name} <{original_sender_address}>"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
request.msg[headers.AUTHENTICATION_RESULTS]
|
||||||
|
== msg[headers.AUTHENTICATION_RESULTS]
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue