pony 1.6.2 → 1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd8ec51f958a8381a430a207d3c841c74062d7ca
4
- data.tar.gz: 10fd40c67cedaa1e49501abb77c449aa33113681
3
+ metadata.gz: ce1e07719a6d6f72a10ac2ae08217d85fb3aa5f4
4
+ data.tar.gz: 9d8e1332919f03c78ab439e2b22b894b3afcc3a3
5
5
  SHA512:
6
- metadata.gz: 6ff87c2cd04aa72fd42341d485d187eb64828f7cb1657bb239b5f27281709e11a281ee348f4e1af5bca6d8db44a157cb3006528e1d6cb5cbf679df49c6ae6b99
7
- data.tar.gz: 55bf1444151fa19569c0c273043f65bb849fa4b029ae607332330c57fff99442a33b7f83430af6905e13538176b7854a5b24b9aef70920d672e2e4fa81fca00b
6
+ metadata.gz: 1343e76f77aa91409afbd022495de50580b376fee2e0954bc98b197f787043e58642ed3b216c1b08d9efd3d1e3af2d32ffe85513bc30a95da18b1780e84a7810
7
+ data.tar.gz: f867a5b22fbbfc411ae524e5020ae09d749f92b14aaeadec1365199891e6bcbcc6b8319814dd5b58dc103e70cef1202efa050831b4cd49cc477c1905e8bae476
@@ -152,6 +152,9 @@ mailing list: ponyrb@googlegroups.com
152
152
 
153
153
 
154
154
  == Releases
155
+ 1.7
156
+ * Better default content_type with attachments
157
+
155
158
  1.6
156
159
  * Unknown options are passed directly to mail to handle. Remove deprecated syntax
157
160
 
@@ -201,10 +201,29 @@ module Pony
201
201
  if mail.multipart? && options[:text_part_charset]
202
202
  mail.text_part.charset = options[:text_part_charset]
203
203
  end
204
-
204
+ set_content_type(mail, options[:content_type])
205
205
  mail
206
206
  end
207
207
 
208
+ def self.set_content_type(mail, user_content_type)
209
+ params = mail.content_type_parameters || {}
210
+ content_type = case
211
+ when user_content_type
212
+ user_content_type
213
+ when mail.has_attachments?
214
+ if mail.attachments.detect { |a| a.inline? }
215
+ ["multipart", "related", params]
216
+ else
217
+ ["multipart", "mixed", params]
218
+ end
219
+ when mail.multipart?
220
+ ["multipart", "alternative", params]
221
+ else
222
+ false
223
+ end
224
+ mail.content_type = content_type if content_type
225
+ end
226
+
208
227
  def self.add_attachments(mail, attachments)
209
228
  attachments.each do |name, body|
210
229
  # mime-types wants to send these as "quoted-printable"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'pony'
5
- s.version = "1.6.2"
5
+ s.version = "1.7"
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
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
16
16
  s.require_paths = ["lib"]
17
17
  s.add_runtime_dependency 'mail', '>= 2.0'
18
- s.add_development_dependency "rspec", ">= 2.0.0"
18
+ s.add_development_dependency "rspec", ">= 2.14"
19
19
  end
@@ -4,169 +4,169 @@ require File.dirname(__FILE__) + '/base'
4
4
  describe Pony do
5
5
 
6
6
  before(:each) do
7
- Pony.stub!(:deliver)
7
+ Pony.stub(:deliver)
8
8
  end
9
9
 
10
10
  it "sends mail" do
11
- Pony.should_receive(:deliver) do |mail|
12
- mail.to.should == [ 'joe@example.com' ]
13
- mail.from.should == [ 'sender@example.com' ]
14
- mail.subject.should == 'hi'
15
- mail.body.should == 'Hello, Joe.'
11
+ expect(Pony).to receive(:deliver) do |mail|
12
+ expect(mail.to).to eq [ 'joe@example.com' ]
13
+ expect(mail.from).to eq [ 'sender@example.com' ]
14
+ expect(mail.subject).to eq 'hi'
15
+ expect(mail.body).to eq 'Hello, Joe.'
16
16
  end
17
17
  Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
18
18
  end
19
19
 
20
20
  it "requires :to param" do
21
- lambda { Pony.mail({}) }.should raise_error(ArgumentError)
21
+ expect{ Pony.mail({}) }.to raise_error(ArgumentError)
22
22
  end
23
23
 
24
24
  it "doesn't require any other param" do
25
- lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
25
+ expect{ Pony.mail(:to => 'joe@example.com') }.to_not raise_error
26
26
  end
27
27
 
28
28
  describe "builds a Mail object with field:" do
29
29
  it "to" do
30
- Pony.build_mail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
30
+ expect(Pony.build_mail(:to => 'joe@example.com').to).to eq [ 'joe@example.com' ]
31
31
  end
32
32
 
33
33
  it "to with multiple recipients" do
34
- Pony.build_mail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
34
+ expect(Pony.build_mail(:to => 'joe@example.com, friedrich@example.com').to).to eq [ 'joe@example.com', 'friedrich@example.com' ]
35
35
  end
36
36
 
37
37
  it "to with multiple recipients and names" do
38
- Pony.build_mail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
38
+ expect(Pony.build_mail(:to => 'joe@example.com, "Friedrich Hayek" <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 in an array" do
42
- Pony.build_mail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
42
+ expect(Pony.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 "cc" do
46
- Pony.build_mail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
46
+ expect(Pony.build_mail(:cc => 'joe@example.com').cc).to eq [ 'joe@example.com' ]
47
47
  end
48
48
 
49
49
  it "reply_to" do
50
- Pony.build_mail(:reply_to => 'joe@example.com').reply_to.should == [ 'joe@example.com' ]
50
+ expect(Pony.build_mail(:reply_to => 'joe@example.com').reply_to).to eq [ 'joe@example.com' ]
51
51
  end
52
52
 
53
53
  it "cc with multiple recipients" do
54
- Pony.build_mail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
54
+ expect(Pony.build_mail(:cc => 'joe@example.com, friedrich@example.com').cc).to eq [ 'joe@example.com', 'friedrich@example.com' ]
55
55
  end
56
56
 
57
57
  it "from" do
58
- Pony.build_mail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
58
+ expect(Pony.build_mail(:from => 'joe@example.com').from).to eq [ 'joe@example.com' ]
59
59
  end
60
60
 
61
61
  it "bcc" do
62
- Pony.build_mail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
62
+ expect(Pony.build_mail(:bcc => 'joe@example.com').bcc).to eq [ 'joe@example.com' ]
63
63
  end
64
64
 
65
65
  it "bcc with multiple recipients" do
66
- Pony.build_mail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
66
+ expect(Pony.build_mail(:bcc => 'joe@example.com, friedrich@example.com').bcc).to eq [ 'joe@example.com', 'friedrich@example.com' ]
67
67
  end
68
68
 
69
69
  it "charset" do
70
70
  mail = Pony.build_mail(:charset => 'UTF-8')
71
- mail.charset.should == 'UTF-8'
71
+ expect(mail.charset).to eq 'UTF-8'
72
72
  end
73
73
 
74
74
  it "text_part_charset" do
75
75
  mail = Pony.build_mail(:attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test', :text_part_charset => 'ISO-2022-JP')
76
- mail.text_part.charset.should == 'ISO-2022-JP'
76
+ expect(mail.text_part.charset).to eq 'ISO-2022-JP'
77
77
  end
78
78
 
79
79
  it "default charset" do
80
- Pony.build_mail(body: 'body').charset.should eq 'UTF-8'
81
- Pony.build_mail(html_body: 'body').charset.should eq 'UTF-8'
80
+ expect(Pony.build_mail(body: 'body').charset).to eq 'UTF-8'
81
+ expect(Pony.build_mail(html_body: 'body').charset).to eq 'UTF-8'
82
82
  end
83
83
 
84
84
  it "from (default)" do
85
- Pony.build_mail({}).from.should == [ 'pony@unknown' ]
85
+ expect(Pony.build_mail({}).from).to eq [ 'pony@unknown' ]
86
86
  end
87
87
 
88
88
  it "subject" do
89
- Pony.build_mail(:subject => 'hello').subject.should == 'hello'
89
+ expect(Pony.build_mail(:subject => 'hello').subject).to eq 'hello'
90
90
  end
91
91
 
92
92
  it "body" do
93
- Pony.build_mail(body: 'What do you know, Joe?').body.should
94
- eq 'What do you know, Joe?'
93
+ expect(Pony.build_mail(body: 'What do you know, Joe?').body)
94
+ .to eq 'What do you know, Joe?'
95
95
  end
96
96
 
97
97
  it "html_body" do
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'
98
+ expect(Pony.build_mail(html_body: 'What do you know, Joe?').parts.first.body)
99
+ .to eq 'What do you know, Joe?'
100
+ expect(Pony.build_mail(html_body: 'What do you know, Joe?').parts.first.content_type)
101
+ .to eq 'text/html; charset=UTF-8'
102
102
  end
103
103
 
104
104
  it 'content_type' do
105
- Pony.build_mail(content_type: 'multipart/related').content_type.should
106
- eq 'multipart/related'
105
+ expect(Pony.build_mail(content_type: 'multipart/related').content_type)
106
+ .to eq 'multipart/related'
107
107
  end
108
108
 
109
109
  it "date" do
110
110
  now = Time.now
111
- Pony.build_mail(:date => now).date.should == DateTime.parse(now.to_s)
111
+ expect(Pony.build_mail(:date => now).date).to eq DateTime.parse(now.to_s)
112
112
  end
113
113
 
114
114
  it "message_id" do
115
- Pony.build_mail(:message_id => '<abc@def.com>').message_id.should == 'abc@def.com'
115
+ expect(Pony.build_mail(:message_id => '<abc@def.com>').message_id).to eq 'abc@def.com'
116
116
  end
117
117
 
118
118
  it "custom headers" do
119
- Pony.build_mail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s.should == '<abc@def.com>'
119
+ expect(Pony.build_mail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s).to eq '<abc@def.com>'
120
120
  end
121
121
 
122
122
  it "sender" do
123
- Pony.build_mail(:sender => "abc@def.com")['Sender'].to_s.should == 'abc@def.com'
123
+ expect(Pony.build_mail(:sender => "abc@def.com")['Sender'].to_s).to eq 'abc@def.com'
124
124
  end
125
125
 
126
126
  it "utf-8 encoded subject line" do
127
127
  mail = Pony.build_mail(:to => 'btp@foo', :subject => 'Café', :body => 'body body body')
128
- mail['subject'].encoded.should =~ /^Subject: =\?UTF-8/;
128
+ expect(mail['subject'].encoded).to match( /^Subject: =\?UTF-8/ )
129
129
  end
130
130
 
131
131
  it "attachments" do
132
132
  mail = Pony.build_mail(:attachments => {"foo.txt" => "content of foo.txt"}, :body => 'test')
133
- mail.parts.length.should == 2
134
- mail.parts.first.to_s.should =~ /Content-Type: text\/plain/
135
- mail.attachments.first.content_id.should == "<foo.txt@#{Socket.gethostname}>"
133
+ expect(mail.parts.length).to eq 2
134
+ expect(mail.parts.first.to_s).to match( /Content-Type: text\/plain/ )
135
+ expect(mail.attachments.first.content_id).to eq "<foo.txt@#{Socket.gethostname}>"
136
136
  end
137
137
 
138
138
  it "suggests mime-type" do
139
139
  mail = Pony.build_mail(:attachments => {"foo.pdf" => "content of foo.pdf"})
140
- mail.parts.length.should == 1
141
- mail.parts.first.to_s.should =~ /Content-Type: application\/pdf/
142
- mail.parts.first.to_s.should =~ /filename=foo.pdf/
143
- mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
140
+ expect(mail.parts.length).to eq 1
141
+ expect(mail.parts.first.to_s).to match( /Content-Type: application\/pdf/ )
142
+ expect(mail.parts.first.to_s).to match( /filename=foo.pdf/ )
143
+ expect(mail.parts.first.content_transfer_encoding.to_s).to eq 'base64'
144
144
  end
145
145
 
146
146
  it "encodes xlsx files as base64" do
147
147
  mail = Pony.build_mail(:attachments => {"foo.xlsx" => "content of foo.xlsx"})
148
- mail.parts.length.should == 1
149
- mail.parts.first.to_s.should =~ /Content-Type: application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/
150
- mail.parts.first.to_s.should =~ /filename=foo.xlsx/
151
- mail.parts.first.content_transfer_encoding.to_s.should == 'base64'
148
+ expect(mail.parts.length).to eq 1
149
+ expect(mail.parts.first.to_s).to match( /Content-Type: application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/ )
150
+ expect(mail.parts.first.to_s).to match( /filename=foo.xlsx/ )
151
+ expect(mail.parts.first.content_transfer_encoding.to_s).to eq 'base64'
152
152
  end
153
153
 
154
154
  it "passes cc and bcc as the list of recipients" do
155
155
  mail = Pony.build_mail(:to => ['to'], :cc => ['cc'], :from => ['from'], :bcc => ['bcc'])
156
- mail.destinations.should == ['to', 'cc', 'bcc']
156
+ expect(mail.destinations).to eq ['to', 'cc', 'bcc']
157
157
  end
158
158
  end
159
159
 
160
160
  describe "transport" do
161
161
  it "transports via smtp if no sendmail binary" do
162
- Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
163
- Pony.should_receive(:build_mail).with(hash_including(:via => :smtp))
162
+ Pony.stub(:sendmail_binary).and_return('/does/not/exist')
163
+ expect(Pony).to receive(:build_mail).with(hash_including(:via => :smtp))
164
164
  Pony.mail(:to => 'foo@bar')
165
165
  end
166
166
 
167
167
  it "defaults to sendmail if no via is specified and sendmail exists" do
168
- File.stub!(:executable?).and_return(true)
169
- Pony.should_receive(:build_mail).with(hash_including(:via => :sendmail))
168
+ File.stub(:executable?).and_return(true)
169
+ expect(Pony).to receive(:build_mail).with(hash_including(:via => :sendmail))
170
170
  Pony.mail(:to => 'foo@bar')
171
171
  end
172
172
 
@@ -174,12 +174,12 @@ describe Pony do
174
174
 
175
175
  it "defaults to localhost as the SMTP server" do
176
176
  mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
177
- mail.delivery_method.settings[:address].should == 'localhost'
177
+ expect(mail.delivery_method.settings[:address]).to eq 'localhost'
178
178
  end
179
179
 
180
180
  it "enable starttls when tls option is true" do
181
181
  mail = Pony.build_mail(:to => "foo@bar", :enable_starttls_auto => true, :via => :smtp)
182
- mail.delivery_method.settings[:enable_starttls_auto].should == true
182
+ expect(mail.delivery_method.settings[:enable_starttls_auto]).to eq true
183
183
  end
184
184
  end
185
185
  end
@@ -187,32 +187,32 @@ describe Pony do
187
187
  describe ":via option should over-ride the default transport mechanism" do
188
188
  it "should send via sendmail if :via => sendmail" do
189
189
  mail = Pony.build_mail(:to => 'joe@example.com', :via => :sendmail)
190
- mail.delivery_method.kind_of?(Mail::Sendmail).should == true
190
+ expect(mail.delivery_method.kind_of?(Mail::Sendmail)).to eq true
191
191
  end
192
192
 
193
193
  it "should send via smtp if :via => smtp" do
194
194
  mail = Pony.build_mail(:to => 'joe@example.com', :via => :smtp)
195
- mail.delivery_method.kind_of?(Mail::SMTP).should == true
195
+ expect(mail.delivery_method.kind_of?(Mail::SMTP)).to eq true
196
196
  end
197
197
 
198
198
  end
199
199
 
200
200
  describe "sendmail binary location" do
201
201
  it "should default to /usr/sbin/sendmail if not in path" do
202
- Pony.stub!(:'`').and_return('')
203
- Pony.sendmail_binary.should == '/usr/sbin/sendmail'
202
+ Pony.stub(:'`').and_return('')
203
+ expect(Pony.sendmail_binary).to eq '/usr/sbin/sendmail'
204
204
  end
205
205
  end
206
206
 
207
207
  describe "default options" do
208
208
  it "should use default options" do
209
- Pony.should_receive(:build_mail).with(hash_including(:from => 'noreply@pony'))
209
+ expect(Pony).to receive(:build_mail).with(hash_including(:from => 'noreply@pony'))
210
210
  Pony.options = { :from => 'noreply@pony' }
211
211
  Pony.mail(:to => 'foo@bar')
212
212
  end
213
213
 
214
214
  it "should merge default options with options" do
215
- Pony.should_receive(:build_mail).with(hash_including(:from => 'override@pony'))
215
+ expect(Pony).to receive(:build_mail).with(hash_including(:from => 'override@pony'))
216
216
  Pony.options = { :from => 'noreply@pony' }
217
217
  Pony.mail(:from => 'override@pony', :to => "foo@bar")
218
218
  end
@@ -221,7 +221,25 @@ describe Pony do
221
221
  input = { :from => 'noreply@pony' }
222
222
  Pony.options = input
223
223
  output = Pony.options
224
- output.should == input
224
+ expect(output).to eq input
225
+ end
226
+ end
227
+
228
+ describe "content type" do
229
+ context "mail with attachments, html_body and body " do
230
+ subject(:mail) do
231
+ Pony.build_mail(
232
+ :body => 'test',
233
+ :html_body => 'What do you know, Joe?',
234
+ :attachments => {"foo.txt" => "content of foo.txt"},
235
+ )
236
+ end
237
+
238
+ it { expect(mail.parts.length).to eq 3 }
239
+ it { expect(mail.content_type.to_s).to include( 'multipart/mixed' ) }
240
+ it { expect(mail.parts[0].to_s).to include( 'Content-Type: text/html' ) }
241
+ it { expect(mail.parts[1].to_s).to include( 'Content-Type: text/plain' ) }
242
+ it { expect(mail.parts[2].to_s).to include( 'Content-Type: text/plain' ) }
225
243
  end
226
244
  end
227
245
 
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.6.2
4
+ version: '1.7'
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: 2013-12-05 00:00:00.000000000 Z
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - '>='
33
33
  - !ruby/object:Gem::Version
34
- version: 2.0.0
34
+ version: '2.14'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '>='
40
40
  - !ruby/object:Gem::Version
41
- version: 2.0.0
41
+ version: '2.14'
42
42
  description: 'Send email in one command: Pony.mail(:to => ''someone@example.com'',
43
43
  :body => ''hello'')'
44
44
  email: ben@throwingbones.com