sendgrid-actionmailer 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 439cfb2a51ff36ec5c65b6848312d86ec545d51f
4
- data.tar.gz: da68fced610264b8bb73fef05fa20e419fae45c7
3
+ metadata.gz: 279c424c1fb91a3d43959b079eb62ff18cc49f4b
4
+ data.tar.gz: 612acbbe466f59ef1cfe8fb43d3e50b905b480c7
5
5
  SHA512:
6
- metadata.gz: f26257a6de567602003ea7d15f179a9336ddabdcec1bb7708449c6bba22a8e47c26a5f2ff692d747e02c4af3907c271a9b1da0aa0d56c1e8fef8d52be776bf96
7
- data.tar.gz: 38106c76e663f6d43c0e00a18722560f0d1847c17c544fff7b19cdb44d34450d435a0c9b073dd152fb4c3b180e38ba310cdb0ec20b5a30ffa00ee58a7c3f4d32
6
+ metadata.gz: efa913396a27fca27aaa83f3aa4ee00f9c59a8e5706d881d097e43e7a2d246fb06283f6c58a41ebe468fd997a6b2b7e56fe43b444597c31fe465bfaca2ff007e
7
+ data.tar.gz: 22c1f0dc2f693e4788cd508ccb2a4a7997e4437423ceea8c6eeaf5372dd2905c52447660dd0590f548f1f17dc2faa07410f3efebe1732af47a587502b88702fc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.1 - 2016-04-26
4
+
5
+ ### Fixed
6
+
7
+ - Fix handling of multipart/related inline attachments.
8
+
3
9
  ## 0.2.0 - 2016-04-25
4
10
 
5
11
  ### Added
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- sendgrid-actionmailer (0.2.0)
4
+ sendgrid-actionmailer (0.2.1)
5
5
  mail (~> 2.5)
6
6
  sendgrid-ruby (< 2.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- sendgrid-actionmailer (0.2.0)
4
+ sendgrid-actionmailer (0.2.1)
5
5
  mail (~> 2.5)
6
6
  sendgrid-ruby (< 2.0)
7
7
 
@@ -1,7 +1,8 @@
1
1
  require 'sendgrid_actionmailer/version'
2
2
  require 'sendgrid_actionmailer/railtie' if defined? Rails
3
3
 
4
- require 'tempfile'
4
+ require 'fileutils'
5
+ require 'tmpdir'
5
6
 
6
7
  require 'sendgrid-ruby'
7
8
 
@@ -17,7 +18,7 @@ module SendGridActionMailer
17
18
  end
18
19
 
19
20
  def deliver!(mail)
20
- attachment_tempfiles = []
21
+ attachment_temp_dirs = []
21
22
  from = mail[:from].addrs.first
22
23
 
23
24
  email = SendGrid::Mail.new do |m|
@@ -96,21 +97,30 @@ module SendGridActionMailer
96
97
  when 'text/html'
97
98
  # HTML
98
99
  email.html = mail.body.decoded
99
- when 'multipart/alternative', 'multipart/mixed'
100
+ when 'multipart/alternative', 'multipart/mixed', 'multipart/related'
100
101
  email.html = mail.html_part.decoded if mail.html_part
101
102
  email.text = mail.text_part.decoded if mail.text_part
102
103
 
103
- # This needs to be done better
104
104
  mail.attachments.each do |a|
105
- # Create a tempfile with the same file extension as the real file
106
- # for sendgrid-ruby's mime type lookups.
107
- t = Tempfile.new(["sendgrid-actionmailer", File.extname(a.filename)])
108
- t.binmode
109
- t.write(a.read)
110
- t.flush
111
- t.rewind
112
- email.add_attachment(t, a.filename)
113
- attachment_tempfiles << t
105
+ # Write the attachment into a temporary location, since sendgrid-ruby
106
+ # expects to deal with files.
107
+ #
108
+ # We write to a temporary directory (instead of a tempfile) and then
109
+ # use the original filename inside there, since sendgrid-ruby's
110
+ # add_content method pulls the filename from the path (so tempfiles
111
+ # would lead to random filenames).
112
+ temp_dir = Dir.mktmpdir('sendgrid-actionmailer')
113
+ attachment_temp_dirs << temp_dir
114
+ temp_path = File.join(temp_dir, a.filename)
115
+ File.open(temp_path, 'wb') do |file|
116
+ file.write(a.read)
117
+ end
118
+
119
+ if(mail.mime_type == 'multipart/related' && a.header[:content_id])
120
+ email.add_content(temp_path, a.header[:content_id].field.content_id)
121
+ else
122
+ email.add_attachment(temp_path, a.filename)
123
+ end
114
124
  end
115
125
  end
116
126
 
@@ -118,9 +128,8 @@ module SendGridActionMailer
118
128
  ensure
119
129
  # Close and delete the attachment tempfiles after the e-mail has been
120
130
  # sent.
121
- attachment_tempfiles.each do |file|
122
- file.close
123
- file.unlink
131
+ attachment_temp_dirs.each do |dir|
132
+ FileUtils.remove_entry_secure(dir)
124
133
  end
125
134
  end
126
135
  end
@@ -1,3 +1,3 @@
1
1
  module SendGridActionMailer
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -193,6 +193,43 @@ module SendGridActionMailer
193
193
  end
194
194
  end
195
195
 
196
+ context 'multipart/related' do
197
+ before do
198
+ mail.content_type 'multipart/related'
199
+ mail.part do |part|
200
+ part.text_part = Mail::Part.new do
201
+ content_type 'text/plain'
202
+ body 'I heard you like pineapple.'
203
+ end
204
+ part.html_part = Mail::Part.new do
205
+ content_type 'text/html'
206
+ body 'I heard you like <b>pineapple</b>.'
207
+ end
208
+ end
209
+ mail.attachments.inline['specs.rb'] = File.read(__FILE__)
210
+ end
211
+
212
+ it 'sets the text body' do
213
+ mailer.deliver!(mail)
214
+ expect(client.sent_mail.text).to eq('I heard you like pineapple.')
215
+ end
216
+
217
+ it 'sets the html body' do
218
+ mailer.deliver!(mail)
219
+ expect(client.sent_mail.html)
220
+ .to eq('I heard you like <b>pineapple</b>.')
221
+ end
222
+
223
+ it 'adds the inline attachment' do
224
+ expect(mail.attachments.first.read).to eq(File.read(__FILE__))
225
+ mailer.deliver!(mail)
226
+ content = client.sent_mail.contents.first
227
+ expect(content[:name]).to eq('specs.rb')
228
+ expect(content[:file].content_type.to_s).to eq('application/x-ruby')
229
+ expect(content[:cid].class).to eq(String)
230
+ end
231
+ end
232
+
196
233
  context 'SMTPAPI' do
197
234
  context 'it is not JSON' do
198
235
  before { mail['X-SMTPAPI'] = '<xml>JSON sucks!</xml>' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Zaneski