postmark 0.9.18 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 0.9.19
4
+
5
+ * Added support for native attachments API provided by Ruby Mail library.
6
+
3
7
  == 0.9.18
4
8
 
5
9
  * Fixed regression introduced by removing ActiveSupport#wrap in case when a Hash instance is passed.
data/README.md CHANGED
@@ -84,34 +84,21 @@ message.deliver
84
84
 
85
85
  ### Message with attachments
86
86
 
87
- You can use postmark gem to send messages with attachments. Please note that:
88
-
89
- * Only allowed file types can be sent as attachments. The message will be rejected (or you will get an SMTP API bounce if using SMTP) with a description of the rejected file, if you try to send a file with a disallowed extension.
90
- * Attachment size can be 10 MB at most. That means you can send three attachments weighing at three megabytes each, but you won't be able to send a single 11MB attachment. Don't worry about base64 encoding making your data larger than it really is. Attachment size is calculated using the real binary data (after base64-decoding it).
91
- * Many applications can get away with sending email as a response to a user action and do that right in the same web request handler. Sending attachments changes that. Message size can and will get bigger and the time to submit it to the Postmark servers will get longer. That is why we recommend that you send email with attachments from a background job. Your users will love you for that!
92
-
93
- Check out our [special documentation section](http://developer.postmarkapp.com/developer-build.html#attachments)
94
- for detailed information.
95
-
96
87
  ``` ruby
97
- require 'rubygems'
98
- require 'postmark'
99
- require 'mail'
100
- require 'json'
101
-
102
88
  message = Mail.new do
103
89
  from 'leonard@bigbangtheory.com'
104
90
  to 'Dr. Sheldon Cooper <sheldon@bigbangtheory.com>'
105
91
  subject 'Have you seen these pictures of yours?'
106
92
  body 'You look like a real geek!'
93
+ add_file '1.jpeg'
107
94
 
108
95
  delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
109
96
  end
110
97
 
111
- message.postmark_attachments = [File.open("1.jpeg"), File.open("2.jpeg")]
98
+ message.attachments['sheldon.jpeg'] = File.read('2.jpeg')
112
99
 
113
100
  message.deliver
114
- # => <Mail::Message:70235449249320, Multipart: false, Headers: <From: leonard@bigbangtheory.com>, <To: sheldon@bigbangtheory.com>, <Message-ID: 91cbdb90-9daa-455d-af24-e233711b02c2>, <Subject: Have you seen these pictures of yours?>>
101
+ # => #<Mail::Message:70185826686240, Multipart: true, Headers: <From: leonard@bigbangtheory.com>, <To: sheldon@bigbangtheory.com>, <Message-ID: ba644cc1-b5b1-4bcb-aaf8-2f290b5aad80>, <Subject: Have you seen these pictures of yours?>, <Content-Type: multipart/mixed; boundary=--==_mimepart_5121f9f1ec653_12c53fd569035ad817726>>
115
102
  ```
116
103
 
117
104
  ### Multipart message
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.18
1
+ 0.9.19
data/lib/postmark.rb CHANGED
@@ -96,6 +96,7 @@ module Postmark
96
96
  def convert_message_to_options_hash(message)
97
97
  options = Hash.new
98
98
  headers = extract_headers_according_to_message_format(message)
99
+ attachments = message.export_attachments
99
100
 
100
101
  options["From"] = message['from'].to_s if message.from
101
102
  options["ReplyTo"] = Array[message.reply_to].flatten.join(", ") if message.reply_to
@@ -103,11 +104,11 @@ module Postmark
103
104
  options["Cc"] = message['cc'].to_s if message.cc
104
105
  options["Bcc"] = Array[message.bcc].flatten.join(", ") if message.bcc
105
106
  options["Subject"] = message.subject
106
- options["Attachments"] = message.postmark_attachments
107
+ options["Attachments"] = attachments unless attachments.empty?
107
108
  options["Tag"] = message.tag.to_s if message.tag
108
109
  options["Headers"] = headers if headers.size > 0
109
110
 
110
- options = options.delete_if{|k,v| v.nil?}
111
+ options = options.delete_if { |k,v| v.nil? }
111
112
 
112
113
  html = message.body_html
113
114
  text = message.body_text
@@ -22,6 +22,20 @@ module Mail
22
22
  text_part.body.to_s
23
23
  end
24
24
  end
25
+
26
+ def export_attachments
27
+ export_native_attachments + postmark_attachments
28
+ end
29
+
30
+ protected
31
+
32
+ def export_native_attachments
33
+ attachments.map do |attachment|
34
+ {"Name" => attachment.filename,
35
+ "Content" => pack_attachment_data(attachment.body.decoded),
36
+ "ContentType" => attachment.mime_type}
37
+ end
38
+ end
25
39
 
26
40
  end
27
41
  end
@@ -14,7 +14,7 @@ module Postmark
14
14
  end
15
15
 
16
16
  def postmark_attachments
17
- return if @_attachments.nil?
17
+ return [] if @_attachments.nil?
18
18
 
19
19
  @_attachments.map do |item|
20
20
  if item.is_a?(Hash)
@@ -22,7 +22,7 @@ module Postmark
22
22
  elsif item.is_a?(File)
23
23
  {
24
24
  "Name" => item.path.split("/")[-1],
25
- "Content" => [ IO.read(item.path) ].pack("m"),
25
+ "Content" => pack_attachment_data(IO.read(item.path)),
26
26
  "ContentType" => "application/octet-stream"
27
27
  }
28
28
  end
@@ -31,6 +31,10 @@ module Postmark
31
31
 
32
32
  protected
33
33
 
34
+ def pack_attachment_data(data)
35
+ [data].pack('m')
36
+ end
37
+
34
38
  # From ActiveSupport (Array#wrap)
35
39
  def wrap_in_array(object)
36
40
  if object.nil?
@@ -107,5 +107,9 @@ module TMail
107
107
  puts "END"
108
108
  end
109
109
 
110
+ def export_attachments
111
+ postmark_attachments
112
+ end
113
+
110
114
  end
111
115
  end
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = "0.9.18"
2
+ VERSION = "0.9.19"
3
3
  end
@@ -187,9 +187,18 @@ describe Postmark do
187
187
  end
188
188
  end
189
189
 
190
- context "attachments setter", :ruby => 1.9 do
191
- let(:attached_hash) { { "Name" => "picture.jpeg", "ContentType" => "image/jpeg" } }
190
+ context "attachments setter" do
192
191
  let(:attached_file) { mock("file") }
192
+ let(:attached_hash) { {'Name' => 'picture.jpeg',
193
+ 'ContentType' => 'image/jpeg'} }
194
+ let(:exported_file) { {'Name' => 'file.jpeg',
195
+ 'ContentType' => 'application/octet-stream',
196
+ 'Content' => ''} }
197
+
198
+ before do
199
+ attached_file.stub(:is_a?) { |arg| arg == File ? true : false }
200
+ attached_file.stub(:path) { '/tmp/file.jpeg' }
201
+ end
193
202
 
194
203
  it "should store attachments as array" do
195
204
  mail_message.postmark_attachments = attached_hash
@@ -197,17 +206,31 @@ describe Postmark do
197
206
  end
198
207
 
199
208
  it "should save the attachments in attachments array" do
200
- mail_message.postmark_attachments = [attached_hash, attached_file]
201
-
202
- attached_file.stub(:is_a?) { |arg| arg == File ? true : false }
203
- attached_file.stub(:path) { '/tmp/file.jpeg' }
204
209
  IO.should_receive(:read).with("/tmp/file.jpeg").and_return("")
205
210
 
206
211
  mail_message.postmark_attachments = [attached_hash, attached_file]
207
- attachments = mail_message.postmark_attachments.map { |a| a['Name'] }
212
+ attachments = mail_message.export_attachments
213
+
214
+ attachments.should include(attached_hash)
215
+ attachments.should include(exported_file)
216
+ end
217
+ end
218
+
219
+ context "native attachments" do
220
+ let(:file_data) { 'binarydatahere' }
221
+ let(:exported_data) do
222
+ {'Name' => 'face.jpeg',
223
+ 'Content' => "YmluYXJ5ZGF0YWhlcmU=\n",
224
+ 'ContentType' => 'image/jpeg'}
225
+ end
226
+
227
+ before do
228
+ mail_message.attachments["face.jpeg"] = file_data
229
+ end
208
230
 
209
- attachments.should include('picture.jpeg')
210
- attachments.should include('file.jpeg')
231
+ it "exports native attachments" do
232
+ attachments = mail_message.export_attachments
233
+ attachments.should include(exported_data)
211
234
  end
212
235
  end
213
236
 
metadata CHANGED
@@ -1,176 +1,187 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.19
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 18
10
- version: 0.9.18
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Petyo Ivanov
14
9
  - Ilya Sabanin
15
10
  - Artem Chistyakov
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2013-01-12 00:00:00 Z
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- prerelease: false
33
- type: :runtime
14
+ date: 2013-02-18 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
34
17
  name: rake
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
- prerelease: false
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
47
24
  type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
48
33
  name: json
49
- requirement: *id002
50
- - !ruby/object:Gem::Dependency
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
60
41
  prerelease: false
61
- type: :development
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
62
49
  name: tmail
63
- requirement: *id003
64
- - !ruby/object:Gem::Dependency
65
- version_requirements: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- prerelease: false
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
75
56
  type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
76
65
  name: mail
77
- requirement: *id004
78
- - !ruby/object:Gem::Dependency
79
- version_requirements: &id005 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
80
67
  none: false
81
- requirements:
82
- - - ~>
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 2
87
- - 0
88
- version: "2.0"
89
- prerelease: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
90
72
  type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
91
81
  name: rspec-core
92
- requirement: *id005
93
- - !ruby/object:Gem::Dependency
94
- version_requirements: &id006 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
95
83
  none: false
96
- requirements:
84
+ requirements:
97
85
  - - ~>
98
- - !ruby/object:Gem::Version
99
- hash: 7
100
- segments:
101
- - 3
102
- - 0
103
- version: "3.0"
104
- prerelease: false
86
+ - !ruby/object:Gem::Version
87
+ version: '2.0'
105
88
  type: :development
106
- name: activesupport
107
- requirement: *id006
108
- - !ruby/object:Gem::Dependency
109
- version_requirements: &id007 !ruby/object:Gem::Requirement
110
- none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
89
  prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: activesupport
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
119
104
  type: :development
120
- name: fakeweb
121
- requirement: *id007
122
- - !ruby/object:Gem::Dependency
123
- version_requirements: &id008 !ruby/object:Gem::Requirement
124
- none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
132
105
  prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: fakeweb
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
133
120
  type: :development
134
- name: fakeweb-matcher
135
- requirement: *id008
136
- - !ruby/object:Gem::Dependency
137
- version_requirements: &id009 !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- hash: 3
143
- segments:
144
- - 0
145
- version: "0"
146
121
  prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ - !ruby/object:Gem::Dependency
129
+ name: fakeweb-matcher
130
+ requirement: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
147
136
  type: :development
148
- name: timecop
149
- requirement: *id009
150
- - !ruby/object:Gem::Dependency
151
- version_requirements: &id010 !ruby/object:Gem::Requirement
152
- none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- hash: 3
157
- segments:
158
- - 0
159
- version: "0"
160
137
  prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ - !ruby/object:Gem::Dependency
145
+ name: timecop
146
+ requirement: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
161
152
  type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ - !ruby/object:Gem::Dependency
162
161
  name: yajl-ruby
163
- requirement: *id010
164
- description: Use this gem to send emails through Postmark HTTP API and retrieve info about bounces.
162
+ requirement: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ description: Use this gem to send emails through Postmark HTTP API and retrieve info
177
+ about bounces.
165
178
  email: ilya@wildbit.com
166
179
  executables: []
167
-
168
180
  extensions: []
169
-
170
- extra_rdoc_files:
181
+ extra_rdoc_files:
171
182
  - LICENSE
172
183
  - README.md
173
- files:
184
+ files:
174
185
  - .document
175
186
  - .gitignore
176
187
  - .rake_tasks
@@ -202,40 +213,36 @@ files:
202
213
  - spec/spec_helper.rb
203
214
  homepage: http://postmarkapp.com
204
215
  licenses: []
205
-
206
- post_install_message: "\n ==================\n Thanks for installing the postmark gem. If you don't have an account, please sign up at http://postmarkapp.com/.\n Review the README.md for implementation details and examples.\n ==================\n "
207
- rdoc_options:
216
+ post_install_message: ! "\n ==================\n Thanks for installing the postmark
217
+ gem. If you don't have an account, please sign up at http://postmarkapp.com/.\n
218
+ \ Review the README.md for implementation details and examples.\n ==================\n
219
+ \ "
220
+ rdoc_options:
208
221
  - --charset=UTF-8
209
- require_paths:
222
+ require_paths:
210
223
  - lib
211
- required_ruby_version: !ruby/object:Gem::Requirement
224
+ required_ruby_version: !ruby/object:Gem::Requirement
212
225
  none: false
213
- requirements:
214
- - - ">="
215
- - !ruby/object:Gem::Version
216
- hash: 3
217
- segments:
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ segments:
218
231
  - 0
219
- version: "0"
220
- required_rubygems_version: !ruby/object:Gem::Requirement
232
+ hash: -1526820895297093205
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
234
  none: false
222
- requirements:
223
- - - ">="
224
- - !ruby/object:Gem::Version
225
- hash: 21
226
- segments:
227
- - 1
228
- - 3
229
- - 7
235
+ requirements:
236
+ - - ! '>='
237
+ - !ruby/object:Gem::Version
230
238
  version: 1.3.7
231
239
  requirements: []
232
-
233
240
  rubyforge_project:
234
241
  rubygems_version: 1.8.24
235
242
  signing_key:
236
243
  specification_version: 3
237
244
  summary: Official Postmark API wrapper.
238
- test_files:
245
+ test_files:
239
246
  - spec/bounce_spec.rb
240
247
  - spec/postmark_spec.rb
241
248
  - spec/shared_examples.rb