Browse Source

Convert str to python email in common module

master
juga 2 years ago
parent
commit
720d807474
4 changed files with 18 additions and 10 deletions
  1. +2
    -1
      mixnet/common.py
  2. +2
    -4
      mixnet/remailer/remailer.py
  3. +3
    -1
      setup.cfg
  4. +11
    -4
      tests/test_remailer.py

+ 2
- 1
mixnet/common.py View File

@ -86,7 +86,8 @@ def create_outgoing_msg(me, to, subject, body):
return msg
def send_email(mail):
def send_email(mail_str):
mail = email.message_from_string(mail_str)
s = smtplib.SMTP("localhost")
s.send_message(mail)
s.quit()

+ 2
- 4
mixnet/remailer/remailer.py View File

@ -1,5 +1,4 @@
"""Mixnet remailer library."""
import email
import logging
import os
@ -37,9 +36,8 @@ def decrypt_email(email_str):
# XXX: is it yellow >= 0?
if pEp.color(rating) < 0:
raise exceptions.EmailNotTrusted
email_to_send = email.message_from_string(dec_msg.longmsg)
logger.info("Next hop: %s", email_to_send["To"])
return email_to_send
logger.info("Next hop: %s", dec_msg.to)
return dec_msg.longmsg
def process_email(email_str):


+ 3
- 1
setup.cfg View File

@ -73,7 +73,9 @@ verbose = 1
[flake8]
max-line-length = 79
ignore = D100,D101,D103,D104,D107
# DXXX: missing docstrings,
# W503 line break before binary operator
ignore = D100,D101,D103,D104,D107,W503
exclude = docs/*
verbose = 1


+ 11
- 4
tests/test_remailer.py View File

@ -89,9 +89,13 @@ def test_decrypt_email_succeed(
email_to_send = remailer.decrypt_email(
email_signed_encrypted_from_alice_to_bob
)
assert email_to_send["From"] == BOB_NAME_ADDR
assert email_to_send["To"] == CAROL_NAME_ADDR
assert str(email_to_send) == email_signed_encrypted_from_bob_to_carol
email_lines = email_to_send.split("\r\n")
assert email_lines[0] == "From: Bob Babagge <bob@openpgp.example>"
assert email_lines[1] == "To: Carol Hopper <carol@openpgp.example>"
assert (
str(email_to_send).replace("\r", "")
== email_signed_encrypted_from_bob_to_carol
)
def test_decrypt_email_not_encrypted(import_keys, email_from_bob_to_carol):
@ -156,4 +160,7 @@ def test_set_identity_decrypt(
email_to_send = remailer.decrypt_email(
email_signed_encrypted_from_alice_to_bob
)
assert email_to_send["From"] == BOB_NAME_ADDR
assert (
email_to_send.split("\r\n")[0]
== "From: Bob Babagge <bob@openpgp.example>"
)

Loading…
Cancel
Save