mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 00:03:03 +08:00
Added fix for parts that are not messages
This commit is contained in:
parent
dbc55c50a2
commit
c16fd25b2e
5 changed files with 60 additions and 21 deletions
|
@ -970,7 +970,10 @@ def add_header(msg: Message, text_header, html_header) -> Message:
|
|||
elif content_type in ("multipart/alternative", "multipart/related"):
|
||||
new_parts = []
|
||||
for part in msg.get_payload():
|
||||
new_parts.append(add_header(part, text_header, html_header))
|
||||
if isinstance(part, Message):
|
||||
new_parts.append(add_header(part, text_header, html_header))
|
||||
else:
|
||||
new_parts.append(part)
|
||||
clone_msg = copy(msg)
|
||||
clone_msg.set_payload(new_parts)
|
||||
return clone_msg
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[pytest]
|
||||
addopts =
|
||||
xaddopts =
|
||||
--cov
|
||||
--cov-config coverage.ini
|
||||
--cov-report=html:htmlcov
|
||||
|
|
25
tests/example_emls/multipart_alternative.eml
Normal file
25
tests/example_emls/multipart_alternative.eml
Normal file
|
@ -0,0 +1,25 @@
|
|||
Content-Type: multipart/alternative; boundary="===============5006593052976639648=="
|
||||
MIME-Version: 1.0
|
||||
Subject: My subject
|
||||
From: foo@example.org
|
||||
To: bar@example.net
|
||||
|
||||
--===============5006593052976639648==
|
||||
Content-Type: text/plain; charset="us-ascii"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
This is HTML
|
||||
--===============5006593052976639648==
|
||||
Content-Type: text/html; charset="us-ascii"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
<html>
|
||||
<body>
|
||||
This is <i>HTML</i>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
--===============5006593052976639648==--
|
||||
|
|
@ -98,25 +98,24 @@ def test_dmarc_quarantine(flask_client):
|
|||
assert f"{alias.email} has a new mail in quarantine" == notifications[0].title
|
||||
|
||||
|
||||
# todo: re-enable test when softfail is quarantined
|
||||
# def test_gmail_dmarc_softfail(flask_client):
|
||||
# user = create_random_user()
|
||||
# alias = Alias.create_new_random(user)
|
||||
# msg = load_eml_file("dmarc_gmail_softfail.eml", {"alias_email": alias.email})
|
||||
# envelope = Envelope()
|
||||
# envelope.mail_from = msg["from"]
|
||||
# envelope.rcpt_tos = [msg["to"]]
|
||||
# result = email_handler.handle(envelope, msg)
|
||||
# assert result == status.E215
|
||||
# email_logs = (
|
||||
# EmailLog.filter_by(user_id=user.id, alias_id=alias.id)
|
||||
# .order_by(EmailLog.id.desc())
|
||||
# .all()
|
||||
# )
|
||||
# assert len(email_logs) == 1
|
||||
# email_log = email_logs[0]
|
||||
# assert email_log.blocked
|
||||
# assert email_log.refused_email_id
|
||||
def test_gmail_dmarc_softfail(flask_client):
|
||||
user = create_random_user()
|
||||
alias = Alias.create_new_random(user)
|
||||
msg = load_eml_file("dmarc_gmail_softfail.eml", {"alias_email": alias.email})
|
||||
envelope = Envelope()
|
||||
envelope.mail_from = msg["from"]
|
||||
envelope.rcpt_tos = [msg["to"]]
|
||||
result = email_handler.handle(envelope, msg)
|
||||
assert result == status.E215
|
||||
email_logs = (
|
||||
EmailLog.filter_by(user_id=user.id, alias_id=alias.id)
|
||||
.order_by(EmailLog.id.desc())
|
||||
.all()
|
||||
)
|
||||
assert len(email_logs) == 1
|
||||
email_log = email_logs[0]
|
||||
assert email_log.blocked
|
||||
assert email_log.refused_email_id
|
||||
|
||||
|
||||
def test_prevent_5xx_from_spf(flask_client):
|
||||
|
|
|
@ -823,3 +823,15 @@ def test_dmarc_result_na():
|
|||
def test_dmarc_result_bad_policy():
|
||||
msg = load_eml_file("dmarc_bad_policy.eml")
|
||||
assert DmarcCheckResult.bad_policy == get_spamd_result(msg).dmarc
|
||||
|
||||
|
||||
def test_add_header_multipart_with_invalid_part():
|
||||
msg = load_eml_file("multipart_alternative.eml")
|
||||
parts = msg.get_payload() + ["invalid"]
|
||||
msg.set_payload(parts)
|
||||
msg = add_header(msg, "INJECT", "INJECT")
|
||||
for i, part in enumerate(msg.get_payload()):
|
||||
if i < 2:
|
||||
assert part.get_payload().index("INJECT") > -1
|
||||
else:
|
||||
assert part == "invalid"
|
||||
|
|
Loading…
Reference in a new issue