Skip to content

Commit

Permalink
Added CC property to message option models
Browse files Browse the repository at this point in the history
Including Create, Forward and Reply
  • Loading branch information
ey-mailosaur authored and jm-mailosaur committed Jan 2, 2025
1 parent 4fd88dd commit 6b71dc6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
6 changes: 5 additions & 1 deletion mailosaur/models/message_create_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class MessageCreateOptions(object):
:param to: The email address to which the email will be sent. Must be a verified email address.
:type to: str
:param cc: The email address to which the email will be CC'd. Must be a verified email address.
:type cc: str
:param send: If true, email will be sent upon creation.
:type send: bool
:param subject: The email subject line.
Expand All @@ -21,8 +23,9 @@ class MessageCreateOptions(object):
:type sendFrom: str
"""

def __init__(self, to, send, subject, text=None, html=None, attachments=None, sendFrom=None):
def __init__(self, to, send, subject, text=None, html=None, attachments=None, sendFrom=None, cc=None):
self.to = to
self.cc = cc
self.send = send
self.subject = subject
self.text = text
Expand All @@ -39,6 +42,7 @@ def to_json(self):

return {
'to': self.to,
'cc': self.cc,
'from': self.sendFrom,
'send': self.send,
'subject': self.subject,
Expand Down
6 changes: 5 additions & 1 deletion mailosaur/models/message_forward_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ class MessageForwardOptions(object):
:param to: The email address to which the email will be sent. Must be a verified email address.
:type to: str
:param cc: The email address to which the email will be CC'd. Must be a verified email address.
:type cc: str
:param text: Any additional plain text content to forward the email with. Note that only text or html can be supplied, not both.
:type text: str
:param html: Any additional HTML content to forward the email with. Note that only html or text can be supplied, not both.
:type html: str
"""

def __init__(self, to, text=None, html=None):
def __init__(self, to, text=None, html=None, cc=None):
self.to = to
self.cc = cc
self.text = text
self.html = html

def to_json(self):
return {
'to': self.to,
'cc': self.cc,
'text': self.text,
'html': self.html
}
6 changes: 5 additions & 1 deletion mailosaur/models/message_reply_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class MessageReplyOptions(object):
"""MessageReplyOptions.
:param cc: The email address to which the email will be CC'd. Must be a verified email address.
:type cc: str
:param text: Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both.
:type text: str
:param html: Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both.
Expand All @@ -12,7 +14,8 @@ class MessageReplyOptions(object):
:type attachments: list[~mailosaur.models.Attachment]
"""

def __init__(self, text=None, html=None, attachments=None):
def __init__(self, text=None, html=None, attachments=None, cc=None):
self.cc = cc
self.text = text
self.html = html
self.attachments = attachments
Expand All @@ -25,6 +28,7 @@ def to_json(self):
attachments.append(a.to_json())

return {
'cc': self.cc,
'text': self.text,
'html': self.html,
'attachments': attachments
Expand Down
48 changes: 47 additions & 1 deletion tests/emails_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_list_received_after(self):
self.assertTrue(len(past_emails) > 0)

future_emails = self.client.messages.list(
self.server, received_after=datetime.today()).items
self.server, received_after=datetime.today() + timedelta(seconds=1)).items
self.assertEqual(0, len(future_emails))

def test_get(self):
Expand Down Expand Up @@ -214,6 +214,21 @@ def test_create_and_send_with_html(self):
self.assertIsNotNone(message.id)
self.assertEqual(subject, message.subject)

def test_create_and_send_with_cc(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")

subject = "CC message"
ccRecipient = "someoneelse@%s" % (self.verified_domain)
options = MessageCreateOptions(
"anything@%s" % (self.verified_domain), True, subject, html="<p>This is a new email.</p>", cc=ccRecipient)
message = self.client.messages.create(self.server, options)

self.assertIsNotNone(message.id)
self.assertEqual(subject, message.subject)
self.assertEqual(1, len(message.cc))
self.assertEqual(ccRecipient, message.cc[0].email)

def test_create_and_send_with_attachment(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")
Expand Down Expand Up @@ -261,6 +276,22 @@ def test_forward_with_html(self):
self.assertIsNotNone(message.id)
self.assertTrue(body in message.html.body)

def test_forward_with_cc(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")

ccRecipient = "someoneelse@%s" % (self.verified_domain)

body = "<p>Forwarded <strong>HTML</strong> message.</p>"
options = MessageForwardOptions(
"forwardcc@%s" % (self.verified_domain), html=body, cc=ccRecipient)
message = self.client.messages.forward(self.emails[0].id, options)

self.assertIsNotNone(message.id)
self.assertTrue(body in message.html.body)
self.assertEqual(1, len(message.cc))
self.assertEqual(ccRecipient, message.cc[0].email)

def test_reply_with_text(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")
Expand All @@ -281,6 +312,21 @@ def test_reply_with_html(self):
self.assertIsNotNone(message.id)
self.assertTrue(body in message.html.body)

def test_reply_with_cc(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")

body = "<p>Reply <strong>HTML</strong> message body.</p>"
ccRecipient = "someoneelse@%s" % (self.verified_domain)

options = MessageReplyOptions(html=body, cc=ccRecipient)
message = self.client.messages.reply(self.emails[0].id, options)

self.assertIsNotNone(message.id)
self.assertTrue(body in message.html.body)
self.assertEqual(1, len(message.cc))
self.assertEqual(ccRecipient, message.cc[0].email)

def test_reply_with_attachment(self):
if self.verified_domain is None:
pytest.skip("Requires verified domain secret")
Expand Down

0 comments on commit 6b71dc6

Please sign in to comment.