Skip to content

Commit 5260bfc

Browse files
ey-mailosaurjm-mailosaur
authored andcommitted
Added CC property to message option models
Including Create, Forward and Reply
1 parent 7a921b8 commit 5260bfc

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

lib/Mailosaur/models/message_create_options.rb

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Models
33
class MessageCreateOptions < BaseModel
44
def initialize(data = {})
55
@to = data['to']
6+
@cc = data['cc']
67
@from = data['from']
78
@send = data['send']
89
@subject = data['subject']
@@ -15,6 +16,10 @@ def initialize(data = {})
1516
# Must be a verified email address.
1617
attr_accessor :to
1718

19+
# @return [String] The email address to which the email will be CC'd.
20+
# Must be a verified email address.
21+
attr_accessor :cc
22+
1823
# @return [String] Allows for the partial override of the message's
1924
# 'from' address. This **must** be an address ending with
2025
# `YOUR_SERVER.mailosaur.net`, such as `[email protected]`.

lib/Mailosaur/models/message_forward_options.rb

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Models
33
class MessageForwardOptions < BaseModel
44
def initialize(data = {})
55
@to = data['to']
6+
@cc = data['cc']
67
@text = data['text']
78
@html = data['html']
89
end
@@ -11,6 +12,10 @@ def initialize(data = {})
1112
# Must be a verified email address.
1213
attr_accessor :to
1314

15+
# @return [String] The email address to which the email will be CC'd.
16+
# Must be a verified email address.
17+
attr_accessor :cc
18+
1419
# @return [String] Any additional plain text content to forward the
1520
# email with. Note that only text or html can be supplied, not both.
1621
attr_accessor :text

lib/Mailosaur/models/message_reply_options.rb

+5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ module Mailosaur
22
module Models
33
class MessageReplyOptions < BaseModel
44
def initialize(data = {})
5+
@cc = data['cc']
56
@text = data['text']
67
@html = data['html']
78
@attachments = data['attachments']
89
end
910

11+
# @return [String] The email address to which the email will be CC'd.
12+
# Must be a verified email address.
13+
attr_accessor :cc
14+
1015
# @return [String] Any additional plain text content to include in
1116
# the reply. Note that only text or html can be supplied, not both.
1217
attr_accessor :text

test/emails_test.rb

+55-4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ def startup
264264
assert_equal(subject, message.subject)
265265
end
266266

267+
should 'send with CC recipient' do
268+
omit_if(@@verified_domain.nil?)
269+
subject = 'CC message'
270+
cc_recipient = 'someoneelse@%s' % [@@verified_domain]
271+
options = Mailosaur::Models::MessageCreateOptions.new()
272+
options.to = 'anything@%s' % [@@verified_domain]
273+
options.cc = cc_recipient
274+
options.send = true
275+
options.subject = subject
276+
options.html = '<p>This is a new email.</p>'
277+
message = @@client.messages.create(@@server, options)
278+
279+
assert_not_nil(message.id)
280+
assert_equal(subject, message.subject)
281+
assert_equal(1, message.cc.count)
282+
assert_equal(cc_recipient, message.cc[0].email)
283+
end
284+
267285
should 'send with attachment' do
268286
omit_if(@@verified_domain.nil?)
269287

@@ -317,15 +335,32 @@ def startup
317335
assert_not_nil(message.id)
318336
assert_true(message.html.body.include?(body))
319337
end
338+
339+
should 'forward with CC recipient' do
340+
omit_if(@@verified_domain.nil?)
341+
target_email = @@emails[0]
342+
body = '<p>Forwarded <strong>HTML</strong> message.</p>'
343+
cc_recipient = 'someoneelse@%s' % [@@verified_domain]
344+
345+
options = Mailosaur::Models::MessageForwardOptions.new()
346+
options.to = 'forwardcc@%s' % [@@verified_domain]
347+
options.cc = cc_recipient
348+
options.html = body
349+
message = @@client.messages.forward(target_email.id, options)
350+
351+
assert_not_nil(message.id)
352+
assert_true(message.html.body.include?(body))
353+
assert_equal(1, message.cc.count)
354+
assert_equal(cc_recipient, message.cc[0].email)
355+
end
320356
end
321357

322358
context 'reply' do
323359
should 'reply with text content' do
324360
omit_if(@@verified_domain.nil?)
325361
target_email = @@emails[0]
326362
body = 'Reply message'
327-
options = Mailosaur::Models::MessageForwardOptions.new()
328-
options.to = 'anything@%s' % [@@verified_domain]
363+
options = Mailosaur::Models::MessageReplyOptions.new()
329364
options.text = body
330365
message = @@client.messages.reply(target_email.id, options)
331366
assert_not_nil(message.id)
@@ -336,14 +371,30 @@ def startup
336371
omit_if(@@verified_domain.nil?)
337372
target_email = @@emails[0]
338373
body = '<p>Reply <strong>HTML</strong> message.</p>'
339-
options = Mailosaur::Models::MessageForwardOptions.new()
340-
options.to = 'anything@%s' % [@@verified_domain]
374+
options = Mailosaur::Models::MessageReplyOptions.new()
341375
options.html = body
342376
message = @@client.messages.reply(target_email.id, options)
343377
assert_not_nil(message.id)
344378
assert_true(message.html.body.include?(body))
345379
end
346380

381+
should 'reply with CC recipient' do
382+
omit_if(@@verified_domain.nil?)
383+
target_email = @@emails[0]
384+
body = '<p>Reply <strong>HTML</strong> message.</p>'
385+
cc_recipient = 'someoneelse@%s' % [@@verified_domain]
386+
387+
options = Mailosaur::Models::MessageReplyOptions.new()
388+
options.cc = cc_recipient
389+
options.html = body
390+
message = @@client.messages.reply(target_email.id, options)
391+
392+
assert_not_nil(message.id)
393+
assert_true(message.html.body.include?(body))
394+
assert_equal(1, message.cc.count)
395+
assert_equal(cc_recipient, message.cc[0].email)
396+
end
397+
347398
should 'reply with attachment' do
348399
omit_if(@@verified_domain.nil?)
349400
target_email = @@emails[0]

0 commit comments

Comments
 (0)