Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion rosetta-test-py/sendmail-python-emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def sendmail_connected(env, backend):
#

@sendmail_suite.placeholder("sendmail-send-message-full")
def sendmail_send_message(env, sender:SMTPBackend, message, sender_address, recipient_addresses, cc_addresses, bcc_addresses, custom_headers, message_options, recipients_options):
def sendmail_send_message(env, sender:SMTPBackend, message, sender_address, recipient_addresses, cc_addresses, bcc_addresses, custom_headers, attachments, message_options, recipients_options):
try:
message = emails.Message(text=message,
subject="Test",
Expand All @@ -130,6 +130,23 @@ def sendmail_send_message(env, sender:SMTPBackend, message, sender_address, reci
cc=cc_addresses,
bcc=bcc_addresses,
headers=custom_headers,)
for attachment in attachments:
message_properties = {
"content_disposition": attachment["content-disposition"],
}

if "file-name" in attachment:
message_properties["filename"] = attachment["file-name"]

read_mode = "r"
if attachment["data"].endswith(".png"):
read_mode = "rb"
message_properties["data"] = open(rosetta.fixture_path('sendmail-fixtures/' + attachment["data"]), read_mode)

if "content-type" in attachment:
message_properties["content_type"] = attachment["content-type"]

message.attach(**message_properties)
return [message.send(smtp=sender,smtp_mail_options=message_options, smtp_rcpt_options=recipients_options)]
except Exception as e:
return [e]
Expand All @@ -154,6 +171,9 @@ def sendmail_error(env, result: SMTPResponse):
# python-emails does mitigation for addresses but detection for other fields

sendmail_suite.run(
exclude=(
# python-emails does not support attachments without a name
"test_attachment_without_a_name",),
exclude_capabilities=(
"root.connection.lazy-connection", # TODO: python-emails does not handle failed auth correctly
"root.connection.eager-connection",
Expand Down
22 changes: 20 additions & 2 deletions rosetta-test-py/sendmail-redmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import socket as socketlib
import ssl
from redmail import EmailSender
import pathlib
import smtplib

sendmail_suite = rosetta.suite("rosetta-test-suites/sendmail.ros")
Expand Down Expand Up @@ -131,15 +132,20 @@ def sendmail_connected(env, sender: EmailSender):
#

@sendmail_suite.placeholder("sendmail-send-message-full")
def sendmail_send_message(env, sender: EmailSender, message, sender_address, recipient_addresses, cc_addresses, bcc_addresses, custom_headers, message_options, recipients_options):
def sendmail_send_message(env, sender: EmailSender, message, sender_address, recipient_addresses, cc_addresses, bcc_addresses, custom_headers, attachments, message_options, recipients_options):
try:
redmail_attachments = {
attachment["file-name"]: pathlib.Path(rosetta.fixture_path('sendmail-fixtures/' + attachment["data"]))
for attachment in attachments
if attachment["content-disposition"] == "attachment"}
sender.send(sender=sender_address,
receivers=recipient_addresses,
cc=cc_addresses,
bcc=bcc_addresses,
headers=custom_headers,
subject="test",
text=message)
text=message,
attachments=redmail_attachments)
except Exception as e:
return [e]
return [True] # EmailSender.send does not return anything related to the sending
Expand All @@ -162,8 +168,20 @@ def sendmail_error(env, result):
# Running
#

#sendmail_suite.run(only=("test_basic_image_attachment",))

sendmail_suite.run(
exclude=(
# redmail does not support inline disposition
"test_text_attachment_with_inline_disposition",
"test_image_attachment_with_inline_disposition",

# redmail does not support attachments without a filename
"test_attachment_without_a_name",

# redmail does not support multiple attachments with the same name
"test_multiple_attachments_with_same_name",

"test_CRLF_detection_in_send-message_recipient",
"test_CRLF_mitigation_in_send-message_sender",
"test_Connect_with_invalid_credentials"), # TODO redmail leaks sockets when credentials are invalid
Expand Down
1 change: 1 addition & 0 deletions rosetta-test-suites/sendmail-fixtures/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content of info file
Binary file added rosetta-test-suites/sendmail-fixtures/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading