malone 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/malone.rb +25 -3
- data/malone.gemspec +1 -1
- data/test/malone.rb +12 -6
- metadata +1 -1
data/lib/malone.rb
CHANGED
@@ -36,14 +36,22 @@ class Malone
|
|
36
36
|
|
37
37
|
begin
|
38
38
|
smtp.start(config.domain, config.user, config.password, config.auth)
|
39
|
-
smtp.send_message(mail.to_s, mail.from.first, mail
|
39
|
+
smtp.send_message(mail.to_s, mail.from.first, *recipients(mail))
|
40
40
|
ensure
|
41
41
|
smtp.finish if smtp.started?
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def recipients(mail)
|
46
|
+
[].tap do |ret|
|
47
|
+
ret.push(*mail.to)
|
48
|
+
ret.push(*mail.cc)
|
49
|
+
ret.push(*mail.bcc)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
45
53
|
def envelope(dict)
|
46
|
-
envelope =
|
54
|
+
envelope = Envelope.new
|
47
55
|
envelope.from = dict[:from]
|
48
56
|
envelope.to = dict[:to]
|
49
57
|
envelope.cc = dict[:cc] if dict[:cc]
|
@@ -66,7 +74,7 @@ class Malone
|
|
66
74
|
|
67
75
|
def initialize(options)
|
68
76
|
opts = options.dup
|
69
|
-
|
77
|
+
|
70
78
|
@tls = true
|
71
79
|
|
72
80
|
url = opts.delete(:url) || ENV["MALONE_URL"]
|
@@ -97,4 +105,18 @@ class Malone
|
|
97
105
|
CGI.unescape(val)
|
98
106
|
end
|
99
107
|
end
|
108
|
+
|
109
|
+
class Envelope < MailFactory
|
110
|
+
attr :bcc
|
111
|
+
|
112
|
+
def initialize
|
113
|
+
super
|
114
|
+
|
115
|
+
@bcc = []
|
116
|
+
end
|
117
|
+
|
118
|
+
def bcc=(bcc)
|
119
|
+
@bcc.push(bcc)
|
120
|
+
end
|
121
|
+
end
|
100
122
|
end
|
data/malone.gemspec
CHANGED
data/test/malone.rb
CHANGED
@@ -88,9 +88,12 @@ test "#envelope" do
|
|
88
88
|
m = Malone.connect
|
89
89
|
|
90
90
|
mail = m.envelope(to: "recipient@me.com", from: "no-reply@mydomain.com",
|
91
|
-
subject: "SUB", text: "TEXT", html: "<h1>TEXT</h1>"
|
91
|
+
subject: "SUB", text: "TEXT", html: "<h1>TEXT</h1>",
|
92
|
+
cc: "cc@me.com", bcc: "bcc@me.com")
|
92
93
|
|
93
94
|
assert_equal ["recipient@me.com"], mail.to
|
95
|
+
assert_equal ["cc@me.com"], mail.cc
|
96
|
+
assert_equal ["bcc@me.com"], mail.bcc
|
94
97
|
assert_equal ["no-reply@mydomain.com"], mail.from
|
95
98
|
assert_equal ["=?utf-8?Q?SUB?="], mail.subject
|
96
99
|
|
@@ -118,8 +121,8 @@ scope do
|
|
118
121
|
@finish = true
|
119
122
|
end
|
120
123
|
|
121
|
-
def send_message(blob, from,
|
122
|
-
@blob, @from, @
|
124
|
+
def send_message(blob, from, *recipients)
|
125
|
+
@blob, @from, @recipients = blob, from, recipients
|
123
126
|
end
|
124
127
|
|
125
128
|
def [](key)
|
@@ -140,7 +143,7 @@ scope do
|
|
140
143
|
|
141
144
|
test "delivering successfully" do |m|
|
142
145
|
m.deliver(to: "recipient@me.com", from: "no-reply@mydomain.com",
|
143
|
-
subject: "SUB", text: "TEXT")
|
146
|
+
subject: "SUB", text: "TEXT", cc: "cc@me.com", bcc: "bcc@me.com")
|
144
147
|
|
145
148
|
assert_equal "smtp.gmail.com", $smtp.host
|
146
149
|
assert_equal 587, $smtp.port
|
@@ -151,9 +154,12 @@ scope do
|
|
151
154
|
assert_equal "pass1234", $smtp[:password]
|
152
155
|
assert_equal :login, $smtp[:auth]
|
153
156
|
|
154
|
-
|
157
|
+
|
158
|
+
assert_equal ["recipient@me.com", "cc@me.com", "bcc@me.com"], $smtp[:recipients]
|
155
159
|
assert_equal "no-reply@mydomain.com", $smtp[:from]
|
156
160
|
|
161
|
+
assert ! $smtp[:blob].include?("bcc@me.com")
|
162
|
+
|
157
163
|
assert $smtp[:started]
|
158
164
|
assert $smtp[:finish]
|
159
165
|
end
|
@@ -171,7 +177,7 @@ scope do
|
|
171
177
|
assert_equal "pass1234", $smtp[:password]
|
172
178
|
assert_equal :login, $smtp[:auth]
|
173
179
|
|
174
|
-
assert_equal ["recipient@me.com"], $smtp[:
|
180
|
+
assert_equal ["recipient@me.com"], $smtp[:recipients]
|
175
181
|
assert_equal "no-reply@mydomain.com", $smtp[:from]
|
176
182
|
|
177
183
|
assert $smtp[:started]
|