pony 1.5.1 → 1.6.1
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.rdoc +8 -1
- data/lib/pony.rb +44 -59
- data/pony.gemspec +10 -14
- data/spec/pony_spec.rb +19 -27
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b989ba61f81f34d5bbdc1f6053c3094b923b161b
|
4
|
+
data.tar.gz: 1e22e925f9798fd041a30788e58a86918a19b1b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b6f8cb9c850970c1307a965b706673e12e5317614e097b8590406d2806cb0bebd32d44b57e538e4b30e4ac3f33b12c008fe5987fb3aec330ded706a44c0f7fa
|
7
|
+
data.tar.gz: 3efca87c016ffcccc4b77ea3f66da7b0ce5620fdb403ed8ed69bbe79f22b012d4a858caeedeb34394a47fb74c90e5190b9486566a6ba19b65f11949d187218c3
|
data/README.rdoc
CHANGED
@@ -91,6 +91,7 @@ Options passed pretty much directly to Mail
|
|
91
91
|
body # the plain text body
|
92
92
|
html_body # for sending html-formatted email
|
93
93
|
subject
|
94
|
+
content_type
|
94
95
|
charset # In case you need to send in utf-8 or similar
|
95
96
|
text_part_charset # for multipart messages, set the charset of the text part
|
96
97
|
attachments # see Attachments section above
|
@@ -98,6 +99,7 @@ Options passed pretty much directly to Mail
|
|
98
99
|
message_id
|
99
100
|
sender # Sets "envelope from" (and the Sender header)
|
100
101
|
reply_to
|
102
|
+
smtp_envelope_to
|
101
103
|
|
102
104
|
Other options
|
103
105
|
via # :smtp or :sendmail, see Transport section above
|
@@ -113,7 +115,9 @@ Default options can be set so that they don't have to be repeated. The default o
|
|
113
115
|
|
114
116
|
== Help
|
115
117
|
|
116
|
-
If you need help using Pony, or it looks like you've found a bug,
|
118
|
+
If you need help using Pony, or it looks like you've found a bug,
|
119
|
+
email ponyrb@googlegroups.com. The full forum is
|
120
|
+
https://groups.google.com/forum/#!forum/ponyrb
|
117
121
|
|
118
122
|
== External Dependencies
|
119
123
|
|
@@ -148,6 +152,9 @@ mailing list: ponyrb@googlegroups.com
|
|
148
152
|
|
149
153
|
|
150
154
|
== Releases
|
155
|
+
1.6
|
156
|
+
* Unknown options are passed directly to mail to handle. Remove deprecated syntax
|
157
|
+
|
151
158
|
1.5.1
|
152
159
|
* Loosen mail dependency to >= 2.0 instead of > 2.0
|
153
160
|
|
data/lib/pony.rb
CHANGED
@@ -125,13 +125,11 @@ module Pony
|
|
125
125
|
# Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howsit!')
|
126
126
|
def self.mail(options)
|
127
127
|
options = @@options.merge options
|
128
|
-
|
128
|
+
fail ArgumentError, ':to is required' unless options[:to]
|
129
129
|
|
130
|
-
options[:via] = default_delivery_method unless options.
|
130
|
+
options[:via] = default_delivery_method unless options.key?(:via)
|
131
131
|
|
132
|
-
options
|
133
|
-
|
134
|
-
if options.has_key?(:via) && options[:via] == :sendmail
|
132
|
+
if options.key?(:via) && options[:via] == :sendmail
|
135
133
|
options[:via_options] ||= {}
|
136
134
|
options[:via_options][:location] ||= sendmail_binary
|
137
135
|
end
|
@@ -141,28 +139,6 @@ module Pony
|
|
141
139
|
|
142
140
|
private
|
143
141
|
|
144
|
-
def self.cross_reference_depricated_fields(options)
|
145
|
-
if options.has_key?(:smtp)
|
146
|
-
warn depricated_message(:smtp, :via_options)
|
147
|
-
options[:via_options] = options.delete(:smtp)
|
148
|
-
end
|
149
|
-
|
150
|
-
# cross-reference pony options to be compatible with keys mail expects
|
151
|
-
{ :host => :address, :user => :user_name, :auth => :authentication, :tls => :enable_starttls_auto }.each do |key, val|
|
152
|
-
if options[:via_options] && options[:via_options].has_key?(key)
|
153
|
-
warn depricated_message(key, val)
|
154
|
-
options[:via_options][val] = options[:via_options].delete(key)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
if options[:content_type] && options[:content_type] =~ /html/ && !options[:html_body]
|
159
|
-
warn depricated_message(:content_type, :html_body)
|
160
|
-
options[:html_body] = options[:body]
|
161
|
-
end
|
162
|
-
|
163
|
-
return options
|
164
|
-
end
|
165
|
-
|
166
142
|
def self.deliver(mail)
|
167
143
|
mail.deliver!
|
168
144
|
end
|
@@ -172,16 +148,27 @@ module Pony
|
|
172
148
|
end
|
173
149
|
|
174
150
|
def self.build_mail(options)
|
175
|
-
mail = Mail.new do
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
151
|
+
mail = Mail.new do |m|
|
152
|
+
options[:date] ||= Time.now
|
153
|
+
options[:from] ||= 'pony@unknown'
|
154
|
+
options[:via_options] ||= {}
|
155
|
+
|
156
|
+
non_standard_options = [
|
157
|
+
:attachments,
|
158
|
+
:body,
|
159
|
+
:charset,
|
160
|
+
:enable_starttls_auto,
|
161
|
+
:headers,
|
162
|
+
:html_body,
|
163
|
+
:text_part_charset,
|
164
|
+
:via,
|
165
|
+
:via_options,
|
166
|
+
]
|
167
|
+
|
168
|
+
options.each do |k, v|
|
169
|
+
next if non_standard_options.include?(k)
|
170
|
+
m.send(k, v)
|
171
|
+
end
|
185
172
|
|
186
173
|
if options[:html_body]
|
187
174
|
html_part do
|
@@ -190,8 +177,8 @@ module Pony
|
|
190
177
|
end
|
191
178
|
end
|
192
179
|
|
193
|
-
# If we're using attachments, the body needs to be a separate
|
194
|
-
|
180
|
+
# If we're using attachments, the body needs to be a separate
|
181
|
+
# part. If not, we can just set the body directly.
|
195
182
|
if options[:body] && (options[:html_body] || options[:attachments])
|
196
183
|
text_part do
|
197
184
|
body options[:body]
|
@@ -200,26 +187,15 @@ module Pony
|
|
200
187
|
body options[:body]
|
201
188
|
end
|
202
189
|
|
203
|
-
delivery_method options[:via],
|
204
|
-
end
|
205
|
-
|
206
|
-
(options[:attachments] || []).each do |name, body|
|
207
|
-
# mime-types wants to send these as "quoted-printable"
|
208
|
-
if name =~ /\.xlsx$/
|
209
|
-
mail.attachments[name] = {
|
210
|
-
:content => Base64.encode64(body),
|
211
|
-
:transfer_encoding => :base64
|
212
|
-
}
|
213
|
-
else
|
214
|
-
mail.attachments[name] = body
|
215
|
-
end
|
216
|
-
mail.attachments[name].add_content_id("<#{name}@#{Socket.gethostname}>")
|
190
|
+
delivery_method options[:via], options[:via_options]
|
217
191
|
end
|
218
192
|
|
219
193
|
(options[:headers] ||= {}).each do |key, value|
|
220
194
|
mail[key] = value
|
221
195
|
end
|
222
196
|
|
197
|
+
add_attachments(mail, options[:attachments]) if options[:attachments]
|
198
|
+
|
223
199
|
mail.charset = options[:charset] if options[:charset] # charset must be set after setting content_type
|
224
200
|
|
225
201
|
if mail.multipart? && options[:text_part_charset]
|
@@ -229,14 +205,23 @@ module Pony
|
|
229
205
|
mail
|
230
206
|
end
|
231
207
|
|
208
|
+
def self.add_attachments(mail, attachments)
|
209
|
+
attachments.each do |name, body|
|
210
|
+
# mime-types wants to send these as "quoted-printable"
|
211
|
+
if name =~ /\.xlsx$/
|
212
|
+
mail.attachments[name] = {
|
213
|
+
content: Base64.encode64(body),
|
214
|
+
transfer_encoding: :base64
|
215
|
+
}
|
216
|
+
else
|
217
|
+
mail.attachments[name] = body
|
218
|
+
end
|
219
|
+
mail.attachments[name].add_content_id("<#{name}@#{Socket.gethostname}>")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
232
223
|
def self.sendmail_binary
|
233
224
|
sendmail = `which sendmail`.chomp
|
234
225
|
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
235
226
|
end
|
236
|
-
|
237
|
-
def self.depricated_message(method, alternative)
|
238
|
-
warning_message = "warning: '#{method}' is deprecated"
|
239
|
-
warning_message += "; use '#{alternative}' instead." if alternative
|
240
|
-
return warning_message
|
241
|
-
end
|
242
227
|
end
|
data/pony.gemspec
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.
|
4
|
+
s.name = 'pony'
|
5
|
+
s.version = "1.6.1"
|
6
6
|
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.authors = ["Adam Wiggins", "
|
10
|
-
s.email =
|
11
|
-
s.homepage =
|
12
|
-
s.
|
7
|
+
s.summary = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')Pony, the express way to send email in Ruby"
|
8
|
+
s.description = s.summary
|
9
|
+
s.authors = ["Adam Wiggins", "Ben Prew"]
|
10
|
+
s.email = 'ben@throwingbones.com'
|
11
|
+
s.homepage = 'http://github.com/benprew/pony'
|
12
|
+
s.license = 'MIT'
|
13
13
|
|
14
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
15
14
|
s.files = ["README.rdoc", "Rakefile", "pony.gemspec" ] + Dir.glob("{lib,spec}/**/*")
|
16
|
-
s.has_rdoc = false
|
17
15
|
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
18
16
|
s.require_paths = ["lib"]
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.add_development_dependency "rspec", ">= 2.0.0"
|
22
|
-
s.platform = Gem::Platform::RUBY
|
17
|
+
s.add_runtime_dependency 'mail', '>= 2.0'
|
18
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
23
19
|
end
|
data/spec/pony_spec.rb
CHANGED
@@ -25,30 +25,19 @@ describe Pony do
|
|
25
25
|
lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
|
26
26
|
end
|
27
27
|
|
28
|
-
it "should handle depricated options gracefully" do
|
29
|
-
Pony.should_receive(:build_mail).with(hash_including(:via_options => {:address => 'test'}))
|
30
|
-
Pony.mail(:to => 'foo@bar', :smtp => { :host => 'test' }, :via => :smtp)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should handle depricated content-type gracefully" do
|
34
|
-
Pony.should_receive(:build_mail).with(hash_including(:html_body => "this is <h1>HTML</h1>"))
|
35
|
-
Pony.mail(:to => 'foo@bar', :content_type => 'text/html', :body => 'this is <h1>HTML</h1>')
|
36
|
-
end
|
37
|
-
####################
|
38
|
-
|
39
28
|
describe "builds a Mail object with field:" do
|
40
29
|
it "to" do
|
41
30
|
Pony.build_mail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
|
42
31
|
end
|
43
|
-
|
32
|
+
|
44
33
|
it "to with multiple recipients" do
|
45
34
|
Pony.build_mail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
46
35
|
end
|
47
|
-
|
36
|
+
|
48
37
|
it "to with multiple recipients and names" do
|
49
38
|
Pony.build_mail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
50
39
|
end
|
51
|
-
|
40
|
+
|
52
41
|
it "to with multiple recipients and names in an array" do
|
53
42
|
Pony.build_mail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
54
43
|
end
|
@@ -56,11 +45,11 @@ describe Pony do
|
|
56
45
|
it "cc" do
|
57
46
|
Pony.build_mail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
|
58
47
|
end
|
59
|
-
|
48
|
+
|
60
49
|
it "reply_to" do
|
61
50
|
Pony.build_mail(:reply_to => 'joe@example.com').reply_to.should == [ 'joe@example.com' ]
|
62
|
-
end
|
63
|
-
|
51
|
+
end
|
52
|
+
|
64
53
|
it "cc with multiple recipients" do
|
65
54
|
Pony.build_mail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
66
55
|
end
|
@@ -88,8 +77,8 @@ describe Pony do
|
|
88
77
|
end
|
89
78
|
|
90
79
|
it "default charset" do
|
91
|
-
Pony.build_mail(:
|
92
|
-
Pony.build_mail(:
|
80
|
+
Pony.build_mail(body: 'body').charset.should eq 'UTF-8'
|
81
|
+
Pony.build_mail(html_body: 'body').charset.should eq 'UTF-8'
|
93
82
|
end
|
94
83
|
|
95
84
|
it "from (default)" do
|
@@ -101,12 +90,20 @@ describe Pony do
|
|
101
90
|
end
|
102
91
|
|
103
92
|
it "body" do
|
104
|
-
Pony.build_mail(:
|
93
|
+
Pony.build_mail(body: 'What do you know, Joe?').body.should
|
94
|
+
eq 'What do you know, Joe?'
|
105
95
|
end
|
106
96
|
|
107
97
|
it "html_body" do
|
108
|
-
Pony.build_mail(:
|
109
|
-
|
98
|
+
Pony.build_mail(html_body: 'What do you know, Joe?').parts.first.body.should
|
99
|
+
eq 'What do you know, Joe?'
|
100
|
+
Pony.build_mail(html_body: 'What do you know, Joe?').parts.first.content_type.should
|
101
|
+
eq 'text/html; charset=UTF-8'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'content_type' do
|
105
|
+
Pony.build_mail(content_type: 'multipart/related').content_type.should
|
106
|
+
eq 'multipart/related'
|
110
107
|
end
|
111
108
|
|
112
109
|
it "date" do
|
@@ -114,11 +111,6 @@ describe Pony do
|
|
114
111
|
Pony.build_mail(:date => now).date.should == DateTime.parse(now.to_s)
|
115
112
|
end
|
116
113
|
|
117
|
-
it "content_type of html should set html_body" do
|
118
|
-
Pony.should_receive(:build_mail).with(hash_including(:html_body => '<h1>test</h1>'))
|
119
|
-
Pony.mail(:to => 'foo@bar', :content_type => 'text/html', :body => '<h1>test</h1>')
|
120
|
-
end
|
121
|
-
|
122
114
|
it "message_id" do
|
123
115
|
Pony.build_mail(:message_id => '<abc@def.com>').message_id.should == 'abc@def.com'
|
124
116
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
8
|
-
-
|
8
|
+
- Ben Prew
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mail
|
@@ -40,8 +40,8 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 2.0.0
|
42
42
|
description: 'Send email in one command: Pony.mail(:to => ''someone@example.com'',
|
43
|
-
:body => ''hello'')'
|
44
|
-
email: ben
|
43
|
+
:body => ''hello'')Pony, the express way to send email in Ruby'
|
44
|
+
email: ben@throwingbones.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
@@ -53,7 +53,8 @@ files:
|
|
53
53
|
- spec/base.rb
|
54
54
|
- spec/pony_spec.rb
|
55
55
|
homepage: http://github.com/benprew/pony
|
56
|
-
licenses:
|
56
|
+
licenses:
|
57
|
+
- MIT
|
57
58
|
metadata: {}
|
58
59
|
post_install_message:
|
59
60
|
rdoc_options:
|
@@ -72,10 +73,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
74
75
|
requirements: []
|
75
|
-
rubyforge_project:
|
76
|
-
rubygems_version: 2.0.
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.3
|
77
78
|
signing_key:
|
78
79
|
specification_version: 4
|
79
80
|
summary: 'Send email in one command: Pony.mail(:to => ''someone@example.com'', :body
|
80
|
-
=> ''hello'')'
|
81
|
+
=> ''hello'')Pony, the express way to send email in Ruby'
|
81
82
|
test_files: []
|