mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 12:41:29 +02:00
Fix: Use MIMEText for text contents (#1801)
* Fix: For badly formatted messages use MIMEText * Fix: For badly formatted messages use MIMEText * fix test --------- Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
This commit is contained in:
parent
cb900ed057
commit
04d92b7f23
@ -951,6 +951,8 @@ def add_header(msg: Message, text_header, html_header=None) -> Message:
|
|||||||
for part in msg.get_payload():
|
for part in msg.get_payload():
|
||||||
if isinstance(part, Message):
|
if isinstance(part, Message):
|
||||||
new_parts.append(add_header(part, text_header, html_header))
|
new_parts.append(add_header(part, text_header, html_header))
|
||||||
|
elif isinstance(part, str):
|
||||||
|
new_parts.append(MIMEText(part))
|
||||||
else:
|
else:
|
||||||
new_parts.append(part)
|
new_parts.append(part)
|
||||||
clone_msg = copy(msg)
|
clone_msg = copy(msg)
|
||||||
|
27
tests/example_emls/email_to_pgp_encrypt.eml
Normal file
27
tests/example_emls/email_to_pgp_encrypt.eml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
From: {{sender_address}}
|
||||||
|
To: {{recipient_address}}
|
||||||
|
Subject: Test subject
|
||||||
|
Content-Type: multipart/alternative; boundary="MLF8fvg556fdhFDH7=_?:
|
||||||
|
|
||||||
|
--MLF8fvg556fdhFDH7=_?:
|
||||||
|
Content-Type: text/plain;
|
||||||
|
charset="utf-8"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
*************************************************************************
|
||||||
|
|
||||||
|
This five-part limited series, based on the brilliant graphic novel by Me
|
||||||
|
|
||||||
|
--MLF8fvg556fdhFDH7=_?:
|
||||||
|
Content-Type: text/html;
|
||||||
|
charset="utf-8"
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
--MLF8fvg556fdhFDH7=_?:
|
||||||
|
Content-Type: text/plain;
|
||||||
|
charset="utf-8"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
*************************************************************************
|
||||||
|
*************************************************************************
|
||||||
|
|
||||||
|
|
33
tests/handler/test_encrypt_pgp.py
Normal file
33
tests/handler/test_encrypt_pgp.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from aiosmtpd.smtp import Envelope
|
||||||
|
|
||||||
|
import email_handler
|
||||||
|
from app.config import get_abs_path
|
||||||
|
from app.db import Session
|
||||||
|
from app.pgp_utils import load_public_key
|
||||||
|
from tests.utils import create_new_user, load_eml_file, random_email
|
||||||
|
|
||||||
|
from app.models import Alias
|
||||||
|
|
||||||
|
|
||||||
|
def test_encrypt_with_pgp():
|
||||||
|
user = create_new_user()
|
||||||
|
pgp_public_key = open(get_abs_path("local_data/public-pgp.asc")).read()
|
||||||
|
mailbox = user.default_mailbox
|
||||||
|
mailbox.pgp_public_key = pgp_public_key
|
||||||
|
mailbox.generic_subject = True
|
||||||
|
mailbox.pgp_finger_print = load_public_key(pgp_public_key)
|
||||||
|
alias = Alias.create_new_random(user)
|
||||||
|
Session.flush()
|
||||||
|
sender_address = random_email()
|
||||||
|
msg = load_eml_file(
|
||||||
|
"email_to_pgp_encrypt.eml",
|
||||||
|
{
|
||||||
|
"sender_address": sender_address,
|
||||||
|
"recipient_address": alias.email,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
envelope = Envelope()
|
||||||
|
envelope.mail_from = sender_address
|
||||||
|
envelope.rcpt_tos = [alias.email]
|
||||||
|
result = email_handler.MailHandler()._handle(envelope, msg)
|
||||||
|
assert result is not None
|
@ -810,7 +810,7 @@ def test_add_header_multipart_with_invalid_part():
|
|||||||
if i < 2:
|
if i < 2:
|
||||||
assert part.get_payload().index("INJECT") > -1
|
assert part.get_payload().index("INJECT") > -1
|
||||||
else:
|
else:
|
||||||
assert part == "invalid"
|
assert part.get_payload() == "invalid"
|
||||||
|
|
||||||
|
|
||||||
def test_sl_formataddr():
|
def test_sl_formataddr():
|
||||||
|
Loading…
Reference in New Issue
Block a user