pony 1.11 → 1.12
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.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/Rakefile +1 -0
- data/lib/pony.rb +118 -119
- data/pony.gemspec +2 -2
- data/spec/pony_spec.rb +37 -37
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 756a7871e13ad465c063b18683d18202907948b1
|
|
4
|
+
data.tar.gz: 38a9f0e41442da28577320ed8c54afe991d77be5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e913d65e224fcebb25ab8eb5ae82afddd84530a9eafc7e3c11aff3a3f8554e383386e5a1d077fe041c3ebd9fdcb871b5989b385b632e458a4f8defd755c9542b
|
|
7
|
+
data.tar.gz: d74bf0263e7acfc0f33b1172ecca76a01a23b9149a00245d9682bbc7e89c5f42b6e5c1dd05e11dd5d881d3b32e1c59d89d04c3bf01bc796f6158dd840941b7dd
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Any option key may be omitted except for ```:to```. See List Of Options section
|
|
|
14
14
|
|
|
15
15
|
Pony uses ```/usr/sbin/sendmail``` to send mail if it is available, otherwise it uses SMTP to localhost.
|
|
16
16
|
|
|
17
|
-
This can be
|
|
17
|
+
This can be overridden if you specify a via option:
|
|
18
18
|
|
|
19
19
|
Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
|
|
20
20
|
Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail
|
|
@@ -44,12 +44,14 @@ Gmail example (with TLS/SSL)
|
|
|
44
44
|
:port => '587',
|
|
45
45
|
:enable_starttls_auto => true,
|
|
46
46
|
:user_name => 'user',
|
|
47
|
-
:password => '
|
|
47
|
+
:password => 'password_see_note',
|
|
48
48
|
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
|
|
49
49
|
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
|
50
50
|
}
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
+
Note: If you use 2 step verification, you will have to generate an application specific password and NOT use your normal password - see https://support.google.com/accounts/answer/185833?hl=en
|
|
54
|
+
|
|
53
55
|
And options for Sendmail:
|
|
54
56
|
|
|
55
57
|
Pony.mail({
|
|
@@ -61,7 +63,7 @@ And options for Sendmail:
|
|
|
61
63
|
}
|
|
62
64
|
})
|
|
63
65
|
|
|
64
|
-
If you're using
|
|
66
|
+
If you're using smtp, set ```:arguments => ''```.
|
|
65
67
|
|
|
66
68
|
## Attachments ##
|
|
67
69
|
|
|
@@ -159,6 +161,17 @@ Append the options passd into Pony.mail to the body of the email. Useful for de
|
|
|
159
161
|
|
|
160
162
|
Pony.append_inputs
|
|
161
163
|
|
|
164
|
+
### Using Pony with Testing or Spec'ing Libraries ###
|
|
165
|
+
|
|
166
|
+
As pony relies on mail to send the mails, you can also use its TestMailer in your tests.
|
|
167
|
+
|
|
168
|
+
Pony.override_options = { :via => :test }
|
|
169
|
+
Pony.mail(:to => 'foo@bar')
|
|
170
|
+
Mail::TestMailer.deliveries.length
|
|
171
|
+
=> 1
|
|
172
|
+
|
|
173
|
+
For further examples see the [corresponding section of mail's readme](https://github.com/mikel/mail#using-mail-with-testing-or-specing-libraries)
|
|
174
|
+
|
|
162
175
|
## Help ##
|
|
163
176
|
|
|
164
177
|
If you need help using Pony, or it looks like you've found a bug,
|
|
@@ -173,9 +186,11 @@ https://groups.google.com/forum/#!forum/ponyrb
|
|
|
173
186
|
|
|
174
187
|
## Authors ##
|
|
175
188
|
* Adam Wiggins [@adamwiggins](https://github.com/adamwiggins)
|
|
189
|
+
* Andrea Talbot [@janehax](https://github.com/janehax)
|
|
176
190
|
* Ben Prew [@benprew](https://github.com/benprew)
|
|
177
191
|
* Cameron Matheson [@cmatheson](https://github.com/cmatheson)
|
|
178
192
|
* Carl Hörberg [@carlhoerberg](https://github.com/carlhoerberg)
|
|
193
|
+
* Christian Haase [@krissi](https://github.com/krissi)
|
|
179
194
|
* Daniel Lopes [@danielvlopes](https://github.com/danielvlopes)
|
|
180
195
|
* Doug Hammond [@dslh](https://github.com/dslh)
|
|
181
196
|
* Hiroshi Saito [@hiroshi](https://github.com/hiroshi)
|
|
@@ -183,6 +198,8 @@ https://groups.google.com/forum/#!forum/ponyrb
|
|
|
183
198
|
* MIKAMI Yoshiyuki [@yoshuki](https://github.com/yoshuki)
|
|
184
199
|
* Mathieu Martin [@webmat](https://github.com/webmat)
|
|
185
200
|
* Michael Durrant [@durrantm](https://github.com/durrantm)
|
|
201
|
+
* Michał Kwiatkowski [@mkwiatkowski](https://github.com/mkwiatkowski)
|
|
202
|
+
* Nami-Doc
|
|
186
203
|
* Neil Middleton [@neilmiddleton](https://github.com/neilmiddleton)
|
|
187
204
|
* Neil Mock [@neilmock](https://github.com/neilmock)
|
|
188
205
|
* Nickolas Means [@nmeans](https://github.com/nmeans)
|
|
@@ -192,12 +209,16 @@ https://groups.google.com/forum/#!forum/ponyrb
|
|
|
192
209
|
* Ryan Malecky [@rmalecky](https://github.com/rmalecky)
|
|
193
210
|
* Seamus Abshere [@seamusabshere](https://github.com/seamusabshere)
|
|
194
211
|
* Stephen Celis [@stephencelis](https://github.com/stephencelis)
|
|
212
|
+
* Steve Root [@steveroot](https://github.com/steveroot)
|
|
195
213
|
* arunthampi [@arunthampi](https://github.com/arunthampi)
|
|
196
214
|
* rick [@rick](https://github.com/rick)
|
|
197
215
|
* rohit [@rohit](https://github.com/rohit)
|
|
198
216
|
|
|
199
217
|
## Changelog ##
|
|
200
218
|
|
|
219
|
+
#### 1.12 ####
|
|
220
|
+
* fix bug: NoMethodError when using mail 2.7.0
|
|
221
|
+
|
|
201
222
|
#### 1.11 ####
|
|
202
223
|
* Improved handling of mails with both text and html bodies and attachments
|
|
203
224
|
|
data/Rakefile
CHANGED
data/lib/pony.rb
CHANGED
|
@@ -146,7 +146,7 @@ module Pony
|
|
|
146
146
|
if @@append_inputs
|
|
147
147
|
options[:body] = "#{options[:body]}/n #{options.to_s}"
|
|
148
148
|
end
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
options = @@options.merge options
|
|
151
151
|
options = options.merge @@override_options
|
|
152
152
|
|
|
@@ -170,56 +170,61 @@ module Pony
|
|
|
170
170
|
standard_options + non_standard_options
|
|
171
171
|
end
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
class << self
|
|
174
|
+
private
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
def deliver(mail)
|
|
177
|
+
mail.deliver!
|
|
178
|
+
end
|
|
178
179
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
def default_delivery_method
|
|
181
|
+
File.executable?(sendmail_binary) ? :sendmail : :smtp
|
|
182
|
+
end
|
|
182
183
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
184
|
+
def standard_options
|
|
185
|
+
[
|
|
186
|
+
:to,
|
|
187
|
+
:cc,
|
|
188
|
+
:bcc,
|
|
189
|
+
:from,
|
|
190
|
+
:subject,
|
|
191
|
+
:content_type,
|
|
192
|
+
:message_id,
|
|
193
|
+
:sender,
|
|
194
|
+
:reply_to,
|
|
195
|
+
:smtp_envelope_to
|
|
196
|
+
]
|
|
197
|
+
end
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
199
|
+
def non_standard_options
|
|
200
|
+
[
|
|
201
|
+
:attachments,
|
|
202
|
+
:body,
|
|
203
|
+
:charset,
|
|
204
|
+
:enable_starttls_auto,
|
|
205
|
+
:headers,
|
|
206
|
+
:html_body,
|
|
207
|
+
:text_part_charset,
|
|
208
|
+
:via,
|
|
209
|
+
:via_options,
|
|
210
|
+
:body_part_header,
|
|
211
|
+
:html_body_part_header
|
|
212
|
+
]
|
|
213
|
+
end
|
|
213
214
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
def build_mail(options)
|
|
216
|
+
nso = non_standard_options
|
|
217
|
+
mail = Mail.new do |m|
|
|
218
|
+
options[:date] ||= Time.now
|
|
219
|
+
options[:from] ||= 'pony@unknown'
|
|
220
|
+
options[:via_options] ||= {}
|
|
221
|
+
|
|
222
|
+
options.each do |k, v|
|
|
223
|
+
next if nso.include?(k)
|
|
224
|
+
m.send(k, v)
|
|
225
|
+
end
|
|
219
226
|
|
|
220
|
-
|
|
221
|
-
next if Pony.non_standard_options.include?(k)
|
|
222
|
-
m.send(k, v)
|
|
227
|
+
m.delivery_method options[:via], options[:via_options]
|
|
223
228
|
end
|
|
224
229
|
|
|
225
230
|
# Automatic handling of multipart messages in the underlying
|
|
@@ -229,107 +234,101 @@ module Pony
|
|
|
229
234
|
# boundary to encapsulate the body-parts within the
|
|
230
235
|
# multipart/mixed boundary that will be created automatically.
|
|
231
236
|
if options[:attachments] && options[:html_body] && options[:body]
|
|
232
|
-
part(:content_type => 'multipart/alternative') do |p|
|
|
233
|
-
p.html_part =
|
|
234
|
-
p.text_part =
|
|
237
|
+
mail.part(:content_type => 'multipart/alternative') do |p|
|
|
238
|
+
p.html_part = build_html_part(options)
|
|
239
|
+
p.text_part = build_text_part(options)
|
|
235
240
|
end
|
|
236
241
|
|
|
237
242
|
# Otherwise if there is more than one part we still need to
|
|
238
243
|
# ensure that they are all declared to be separate.
|
|
239
244
|
elsif options[:html_body] || options[:attachments]
|
|
240
|
-
if options[:html_body]
|
|
241
|
-
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
if options[:body]
|
|
245
|
-
m.text_part = Pony.build_text_part(options)
|
|
246
|
-
end
|
|
245
|
+
mail.html_part = build_html_part(options) if options[:html_body]
|
|
246
|
+
mail.text_part = build_text_part(options) if options[:body]
|
|
247
247
|
|
|
248
248
|
# If all we have is a text body, we don't need to worry about parts.
|
|
249
249
|
elsif options[:body]
|
|
250
|
-
body options[:body]
|
|
250
|
+
mail.body options[:body]
|
|
251
251
|
end
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
(options[:headers] ||= {}).each do |key, value|
|
|
257
|
-
mail[key] = value
|
|
258
|
-
end
|
|
253
|
+
(options[:headers] ||= {}).each do |key, value|
|
|
254
|
+
mail[key] = value
|
|
255
|
+
end
|
|
259
256
|
|
|
260
|
-
|
|
257
|
+
add_attachments(mail, options[:attachments]) if options[:attachments]
|
|
261
258
|
|
|
262
|
-
|
|
259
|
+
mail.charset = options[:charset] if options[:charset] # charset must be set after setting content_type
|
|
263
260
|
|
|
264
|
-
|
|
265
|
-
|
|
261
|
+
if mail.multipart? && options[:text_part_charset]
|
|
262
|
+
mail.text_part.charset = options[:text_part_charset]
|
|
263
|
+
end
|
|
264
|
+
set_content_type(mail, options[:content_type])
|
|
265
|
+
mail
|
|
266
266
|
end
|
|
267
|
-
set_content_type(mail, options[:content_type])
|
|
268
|
-
mail
|
|
269
|
-
end
|
|
270
267
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
268
|
+
def build_html_part(options)
|
|
269
|
+
Mail::Part.new(:content_type => 'text/html;charset=UTF-8') do
|
|
270
|
+
content_transfer_encoding 'quoted-printable'
|
|
271
|
+
body Mail::Encodings::QuotedPrintable.encode(options[:html_body])
|
|
272
|
+
if options[:html_body_part_header] && options[:html_body_part_header].is_a?(Hash)
|
|
273
|
+
options[:html_body_part_header].each do |k,v|
|
|
274
|
+
header[k] = v
|
|
275
|
+
end
|
|
278
276
|
end
|
|
279
277
|
end
|
|
280
278
|
end
|
|
281
|
-
end
|
|
282
279
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
280
|
+
def build_text_part(options)
|
|
281
|
+
Mail::Part.new(:content_type => 'text/plain') do
|
|
282
|
+
content_type options[:charset] if options[:charset]
|
|
283
|
+
body options[:body]
|
|
284
|
+
if options[:body_part_header] && options[:body_part_header].is_a?(Hash)
|
|
285
|
+
options[:body_part_header].each do |k,v|
|
|
286
|
+
header[k] = v
|
|
287
|
+
end
|
|
290
288
|
end
|
|
291
289
|
end
|
|
292
290
|
end
|
|
293
|
-
end
|
|
294
291
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
292
|
+
def set_content_type(mail, user_content_type)
|
|
293
|
+
params = mail.content_type_parameters || {}
|
|
294
|
+
content_type =
|
|
295
|
+
case
|
|
296
|
+
when user_content_type
|
|
297
|
+
user_content_type
|
|
298
|
+
when mail.has_attachments?
|
|
299
|
+
if mail.attachments.detect { |a| a.inline? }
|
|
300
|
+
["multipart", "related", params]
|
|
301
|
+
else
|
|
302
|
+
["multipart", "mixed", params]
|
|
303
|
+
end
|
|
304
|
+
when mail.multipart?
|
|
305
|
+
["multipart", "alternative", params]
|
|
306
|
+
else
|
|
307
|
+
false
|
|
308
|
+
end
|
|
309
|
+
mail.content_type = content_type if content_type
|
|
310
310
|
end
|
|
311
|
-
mail.content_type = content_type if content_type
|
|
312
|
-
end
|
|
313
311
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
312
|
+
def add_attachments(mail, attachments)
|
|
313
|
+
attachments.each do |name, body|
|
|
314
|
+
name = name.gsub /\s+/, ' '
|
|
315
|
+
|
|
316
|
+
# mime-types wants to send these as "quoted-printable"
|
|
317
|
+
if name =~ /\.xlsx$/
|
|
318
|
+
mail.attachments[name] = {
|
|
319
|
+
:content => Base64.encode64(body),
|
|
320
|
+
:transfer_encoding => :base64
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
mail.attachments[name] = body
|
|
324
|
+
end
|
|
325
|
+
mail.attachments[name].add_content_id("<#{name}@#{Socket.gethostname}>")
|
|
326
326
|
end
|
|
327
|
-
mail.attachments[name].add_content_id("<#{name}@#{Socket.gethostname}>")
|
|
328
327
|
end
|
|
329
|
-
end
|
|
330
328
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
329
|
+
def sendmail_binary
|
|
330
|
+
sendmail = `which sendmail`.chomp
|
|
331
|
+
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
|
332
|
+
end
|
|
334
333
|
end
|
|
335
334
|
end
|
data/pony.gemspec
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'pony'
|
|
5
|
-
s.version = "1.
|
|
5
|
+
s.version = "1.12"
|
|
6
6
|
|
|
7
7
|
s.summary = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
|
8
8
|
s.description = s.summary
|
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
s.require_paths = ["lib"]
|
|
17
17
|
s.add_runtime_dependency 'mail', '>= 2.0'
|
|
18
18
|
s.add_development_dependency "rspec", ">= 2.14"
|
|
19
|
-
s.add_development_dependency "rake"
|
|
19
|
+
s.add_development_dependency "rake"
|
|
20
20
|
end
|
data/spec/pony_spec.rb
CHANGED
|
@@ -31,116 +31,116 @@ describe Pony do
|
|
|
31
31
|
|
|
32
32
|
describe "builds a Mail object with field:" do
|
|
33
33
|
it "to" do
|
|
34
|
-
expect(Pony.
|
|
34
|
+
expect(Pony.send(:build_mail, :to => 'joe@example.com').to).to eq [ 'joe@example.com' ]
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "to with multiple recipients" do
|
|
38
|
-
expect(Pony.
|
|
38
|
+
expect(Pony.send(:build_mail, :to => 'joe@example.com, friedrich@example.com').to).to eq [ 'joe@example.com', 'friedrich@example.com' ]
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "to with multiple recipients and names" do
|
|
42
|
-
expect(Pony.
|
|
42
|
+
expect(Pony.send(:build_mail, :to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to).to eq [ 'joe@example.com', 'friedrich@example.com' ]
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "to with multiple recipients and names in an array" do
|
|
46
|
-
expect(Pony.
|
|
46
|
+
expect(Pony.send(:build_mail, :to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to).to eq [ 'joe@example.com', 'friedrich@example.com' ]
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "cc" do
|
|
50
|
-
expect(Pony.
|
|
50
|
+
expect(Pony.send(:build_mail, :cc => 'joe@example.com').cc).to eq [ 'joe@example.com' ]
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "reply_to" do
|
|
54
|
-
expect(Pony.
|
|
54
|
+
expect(Pony.send(:build_mail, :reply_to => 'joe@example.com').reply_to).to eq [ 'joe@example.com' ]
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "cc with multiple recipients" do
|
|
58
|
-
expect(Pony.
|
|
58
|
+
expect(Pony.send(:build_mail, :cc => 'joe@example.com, friedrich@example.com').cc).to eq [ 'joe@example.com', 'friedrich@example.com' ]
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "from" do
|
|
62
|
-
expect(Pony.
|
|
62
|
+
expect(Pony.send(:build_mail, :from => 'joe@example.com').from).to eq [ 'joe@example.com' ]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "bcc" do
|
|
66
|
-
expect(Pony.
|
|
66
|
+
expect(Pony.send(:build_mail, :bcc => 'joe@example.com').bcc).to eq [ 'joe@example.com' ]
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "bcc with multiple recipients" do
|
|
70
|
-
expect(Pony.
|
|
70
|
+
expect(Pony.send(:build_mail, :bcc => 'joe@example.com, friedrich@example.com').bcc).to eq [ 'joe@example.com', 'friedrich@example.com' ]
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "charset" do
|
|
74
|
-
mail = Pony.
|
|
74
|
+
mail = Pony.send(:build_mail, :charset => 'UTF-8')
|
|
75
75
|
expect(mail.charset).to eq 'UTF-8'
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "text_part_charset" do
|
|
79
|
-
mail = Pony.
|
|
79
|
+
mail = Pony.send(:build_mail, :attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test', :text_part_charset => 'ISO-2022-JP')
|
|
80
80
|
expect(mail.text_part.charset).to eq 'ISO-2022-JP'
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it "default charset" do
|
|
84
|
-
expect(Pony.build_mail
|
|
85
|
-
expect(Pony.build_mail
|
|
84
|
+
expect(Pony.send(:build_mail, body: 'body').charset).to eq 'UTF-8'
|
|
85
|
+
expect(Pony.send(:build_mail, html_body: 'body').charset).to eq 'UTF-8'
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "from (default)" do
|
|
89
|
-
expect(Pony.build_mail
|
|
89
|
+
expect(Pony.send(:build_mail, {}).from).to eq [ 'pony@unknown' ]
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "subject" do
|
|
93
|
-
expect(Pony.
|
|
93
|
+
expect(Pony.send(:build_mail, :subject => 'hello').subject).to eq 'hello'
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
it "body" do
|
|
97
|
-
expect(Pony.build_mail
|
|
97
|
+
expect(Pony.send(:build_mail, body: 'What do you know, Joe?').body)
|
|
98
98
|
.to eq 'What do you know, Joe?'
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it "html_body" do
|
|
102
|
-
expect(Pony.build_mail
|
|
102
|
+
expect(Pony.send(:build_mail, html_body: 'What do you know, Joe?').parts.first.body)
|
|
103
103
|
.to eq 'What do you know, Joe?'
|
|
104
|
-
expect(Pony.build_mail
|
|
104
|
+
expect(Pony.send(:build_mail, html_body: 'What do you know, Joe?').parts.first.content_type)
|
|
105
105
|
.to eq 'text/html; charset=UTF-8'
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
it 'content_type' do
|
|
109
|
-
expect(Pony.build_mail
|
|
109
|
+
expect(Pony.send(:build_mail, content_type: 'multipart/related').content_type)
|
|
110
110
|
.to eq 'multipart/related'
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
it "date" do
|
|
114
114
|
now = Time.now
|
|
115
|
-
expect(Pony.
|
|
115
|
+
expect(Pony.send(:build_mail, :date => now).date).to eq DateTime.parse(now.to_s)
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "message_id" do
|
|
119
|
-
expect(Pony.
|
|
119
|
+
expect(Pony.send(:build_mail, :message_id => '<abc@def.com>').message_id).to eq 'abc@def.com'
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
it "custom headers" do
|
|
123
|
-
expect(Pony.
|
|
123
|
+
expect(Pony.send(:build_mail, :headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s).to eq '<abc@def.com>'
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
it "sender" do
|
|
127
|
-
expect(Pony.
|
|
127
|
+
expect(Pony.send(:build_mail, :sender => "abc@def.com")['Sender'].to_s).to eq 'abc@def.com'
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it "utf-8 encoded subject line" do
|
|
131
|
-
mail = Pony.
|
|
131
|
+
mail = Pony.send(:build_mail, :to => 'btp@foo', :subject => 'Café', :body => 'body body body')
|
|
132
132
|
expect(mail['subject'].encoded).to match( /^Subject: =\?UTF-8/ )
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it "attachments" do
|
|
136
|
-
mail = Pony.
|
|
136
|
+
mail = Pony.send(:build_mail, :attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test')
|
|
137
137
|
expect(mail.parts.length).to eq 2
|
|
138
138
|
expect(mail.parts.first.to_s).to match( /Content-Type: text\/plain/ )
|
|
139
139
|
expect(mail.attachments.first.content_id).to eq "<foo.txt@#{Socket.gethostname}>"
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
it "suggests mime-type" do
|
|
143
|
-
mail = Pony.
|
|
143
|
+
mail = Pony.send(:build_mail, :attachments => {"foo.pdf" => "content of foo.pdf"})
|
|
144
144
|
expect(mail.parts.length).to eq 1
|
|
145
145
|
expect(mail.parts.first.to_s).to match( /Content-Type: application\/pdf/ )
|
|
146
146
|
expect(mail.parts.first.to_s).to match( /filename=foo.pdf/ )
|
|
@@ -148,7 +148,7 @@ describe Pony do
|
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "encodes xlsx files as base64" do
|
|
151
|
-
mail = Pony.
|
|
151
|
+
mail = Pony.send(:build_mail, :attachments => {"foo.xlsx" => "content of foo.xlsx"})
|
|
152
152
|
expect(mail.parts.length).to eq 1
|
|
153
153
|
expect(mail.parts.first.to_s).to match( /Content-Type: application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/ )
|
|
154
154
|
expect(mail.parts.first.to_s).to match( /filename=foo.xlsx/ )
|
|
@@ -156,7 +156,7 @@ describe Pony do
|
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
it "passes cc and bcc as the list of recipients" do
|
|
159
|
-
mail = Pony.
|
|
159
|
+
mail = Pony.send(:build_mail, :to => ['to'], :cc => ['cc'], :from => ['from'], :bcc => ['bcc'])
|
|
160
160
|
expect(mail.destinations).to eq ['to', 'cc', 'bcc']
|
|
161
161
|
end
|
|
162
162
|
end
|
|
@@ -177,12 +177,12 @@ describe Pony do
|
|
|
177
177
|
describe "SMTP transport" do
|
|
178
178
|
|
|
179
179
|
it "defaults to localhost as the SMTP server" do
|
|
180
|
-
mail = Pony.
|
|
180
|
+
mail = Pony.send(:build_mail, :to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
|
181
181
|
expect(mail.delivery_method.settings[:address]).to eq 'localhost'
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
it "enable starttls when tls option is true" do
|
|
185
|
-
mail = Pony.
|
|
185
|
+
mail = Pony.send(:build_mail, :to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
|
|
186
186
|
expect(mail.delivery_method.settings[:enable_starttls_auto]).to eq true
|
|
187
187
|
end
|
|
188
188
|
end
|
|
@@ -190,12 +190,12 @@ describe Pony do
|
|
|
190
190
|
|
|
191
191
|
describe ":via option should over-ride the default transport mechanism" do
|
|
192
192
|
it "should send via sendmail if :via => sendmail" do
|
|
193
|
-
mail = Pony.
|
|
193
|
+
mail = Pony.send(:build_mail, :to => 'joe@example.com', :via => :sendmail)
|
|
194
194
|
expect(mail.delivery_method.kind_of?(Mail::Sendmail)).to eq true
|
|
195
195
|
end
|
|
196
196
|
|
|
197
197
|
it "should send via smtp if :via => smtp" do
|
|
198
|
-
mail = Pony.
|
|
198
|
+
mail = Pony.send(:build_mail, :to => 'joe@example.com', :via => :smtp)
|
|
199
199
|
expect(mail.delivery_method.kind_of?(Mail::SMTP)).to eq true
|
|
200
200
|
end
|
|
201
201
|
|
|
@@ -204,7 +204,7 @@ describe Pony do
|
|
|
204
204
|
describe "sendmail binary location" do
|
|
205
205
|
it "should default to /usr/sbin/sendmail if not in path" do
|
|
206
206
|
allow(Pony).to receive(:'`').and_return('')
|
|
207
|
-
expect(Pony.sendmail_binary).to eq '/usr/sbin/sendmail'
|
|
207
|
+
expect(Pony.send(:sendmail_binary)).to eq '/usr/sbin/sendmail'
|
|
208
208
|
end
|
|
209
209
|
end
|
|
210
210
|
|
|
@@ -303,7 +303,7 @@ describe Pony do
|
|
|
303
303
|
describe "content type" do
|
|
304
304
|
context "mail with attachments, html_body and body " do
|
|
305
305
|
subject(:mail) do
|
|
306
|
-
Pony.build_mail
|
|
306
|
+
Pony.send(:build_mail,
|
|
307
307
|
:body => 'test',
|
|
308
308
|
:html_body => 'What do you know, Joe?',
|
|
309
309
|
:attachments => {"foo.txt" => "content of foo.txt"},
|
|
@@ -322,7 +322,7 @@ describe Pony do
|
|
|
322
322
|
|
|
323
323
|
describe "additional headers" do
|
|
324
324
|
subject(:mail) do
|
|
325
|
-
Pony.build_mail
|
|
325
|
+
Pony.send(:build_mail,
|
|
326
326
|
:body => 'test',
|
|
327
327
|
:html_body => 'What do you know, Joe?',
|
|
328
328
|
:attachments => {"foo.txt" => "content of foo.txt"},
|
|
@@ -336,7 +336,7 @@ describe Pony do
|
|
|
336
336
|
|
|
337
337
|
context "when parts aren't present" do
|
|
338
338
|
subject(:mail) do
|
|
339
|
-
Pony.build_mail
|
|
339
|
+
Pony.send(:build_mail,
|
|
340
340
|
:body => 'test',
|
|
341
341
|
:body_part_header => { content_disposition: "inline"},
|
|
342
342
|
:html_body_part_header => { content_disposition: "inline"}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pony
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.12'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam Wiggins
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mail
|
|
@@ -45,14 +45,14 @@ dependencies:
|
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '
|
|
48
|
+
version: '0'
|
|
49
49
|
type: :development
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
55
|
+
version: '0'
|
|
56
56
|
description: 'Send email in one command: Pony.mail(:to => ''someone@example.com'',
|
|
57
57
|
:body => ''hello'')'
|
|
58
58
|
email: ben@throwingbones.com
|
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
88
|
version: '0'
|
|
89
89
|
requirements: []
|
|
90
90
|
rubyforge_project:
|
|
91
|
-
rubygems_version: 2.
|
|
91
|
+
rubygems_version: 2.6.14
|
|
92
92
|
signing_key:
|
|
93
93
|
specification_version: 4
|
|
94
94
|
summary: 'Send email in one command: Pony.mail(:to => ''someone@example.com'', :body
|