letter_opener 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 791bc4430c69cf7cd36b26cc8f8c610f9b1206cc
4
- data.tar.gz: 948b12833885db1d6e51c8d594dc3193c800f296
2
+ SHA256:
3
+ metadata.gz: 01b0762b4aecc2dab14ff7cd85a99f5983185a528429b80a34daf75b53003b01
4
+ data.tar.gz: 00ceedf63ed4a2a18b0ef2f6571ad7338e9ab6154b41f870cf61a3caf4d58dcc
5
5
  SHA512:
6
- metadata.gz: 115a513680145c304e82e56530ea8f36c9555ce7714be0316f614bc7cafe2bf43dfc00af01c0b21977863d4e17df32275ad27033affdace860b43b33171dce7a
7
- data.tar.gz: c846117e41eefde83358fc04ab8f30e11580d9311ca6c4e2b4ed725a0245ef858f956cf933a04e6f8d232f85b52643db0b28a0c46e22afe4323705f115f54435
6
+ metadata.gz: b0b6fe51bf7aca4604c7fcc8bdce55c4ae88530015fb34638fe7f97f5ef50321b059d36c1101b6405a37513ba32db346e8984532495ba152382b178c561824a2
7
+ data.tar.gz: 9f7ea030c5a857720d3f01548d5174c8d172914b4223396c9bbe50704ca8db4cb523ff7b0a070b12658c51065ca8e6dc5b963fd30e1418dcebcefdfbf8394cbb
@@ -1,3 +1,13 @@
1
+ ## 1.5.0 ##
2
+ * Use proper check for `Rails::Railties` (thanks [Florian Weingarten](https://github.com/fw42))
3
+ * Add a shim for the iFrame "srcdoc" attribute (make it work with IE).
4
+ * Do not convert `-` to `_` in attachment file names. (thanks [Steven Harman](https://github.com/stevenharman))
5
+ * Drop Ruby 1.9 support.
6
+ * Escape inline attachment names the same way they are stored in the attachments directory (thanks [Daniel Rikowski](https://github.com/daniel-rikowski))
7
+ * Increase timestamp precision in the mail filename. (thanks [Piotr Usewicz](https://github.com/pusewicz))
8
+ * Add ability to configure location of stored mails. (thanks [Ben](https://github.com/beejamin))
9
+ * Add light version of template for mails that doesn't render any additional styling. (thanks [Ben](https://github.com/beejamin))
10
+
1
11
  ## 1.4.1 ##
2
12
  * Stop base tag appearing in plain-text previews. (thanks [Coby Chapple](https://github.com/cobyism))
3
13
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem "rake"
@@ -14,6 +14,19 @@ Then set the delivery method in <tt>config/environments/development.rb</tt>
14
14
  config.action_mailer.delivery_method = :letter_opener
15
15
 
16
16
  Now any email will pop up in your browser instead of being sent. The messages are stored in <tt>tmp/letter_opener</tt>.
17
+ If you want to change application that will be used to open your emails you should override <tt>LAUNCHY_APPLICATION</tt> environment variable or set <tt>Launchy.application</tt> in the initializer.
18
+
19
+ ==== Configuration
20
+
21
+ LetterOpener.configure do |config|
22
+ # To overrider the location for message storage.
23
+ # Default value is <tt>tmp/letter_opener</tt>
24
+ config.location = Rails.root.join('tmp', 'my_mails')
25
+
26
+ # To render only the message body, without any metadata or extra containers or styling.
27
+ # Default value is <tt>:default</tt> that renders styled message with showing useful metadata.
28
+ config.message_template = :light
29
+ end
17
30
 
18
31
  ==== For Rails 2.3.x support
19
32
 
@@ -1,9 +1,15 @@
1
- require "fileutils"
2
- require "digest/sha1"
3
- require "cgi"
4
- require "uri"
5
- require "launchy"
1
+ module LetterOpener
2
+ autoload :Message, "letter_opener/message"
3
+ autoload :DeliveryMethod, "letter_opener/delivery_method"
4
+ autoload :Configuration, "letter_opener/configuration"
6
5
 
7
- require "letter_opener/message"
8
- require "letter_opener/delivery_method"
9
- require "letter_opener/railtie" if defined? Rails
6
+ def self.configuration
7
+ @configration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield(configuration)
12
+ end
13
+ end
14
+
15
+ require "letter_opener/railtie" if defined?(Rails::Railtie)
@@ -0,0 +1,10 @@
1
+ module LetterOpener
2
+ class Configuration
3
+ attr_accessor :location, :message_template
4
+
5
+ def initialize
6
+ @location = Rails.root.join('tmp', 'letter_opener') if defined?(Rails)
7
+ @message_template = 'default'
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,9 @@
1
+ require "digest/sha1"
2
+ require "launchy"
1
3
  begin
2
- require 'mail/check_delivery_params'
3
- rescue LoadError => e
4
+ require "mail"
5
+ require "mail/check_delivery_params"
6
+ rescue LoadError
4
7
  end
5
8
 
6
9
  module LetterOpener
@@ -12,16 +15,20 @@ module LetterOpener
12
15
  attr_accessor :settings
13
16
 
14
17
  def initialize(options = {})
18
+ options[:message_template] ||= LetterOpener.configuration.message_template
19
+ options[:location] ||= LetterOpener.configuration.location
20
+
15
21
  raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil?
22
+
16
23
  self.settings = options
17
24
  end
18
25
 
19
26
  def deliver!(mail)
20
27
  check_delivery_params(mail) if respond_to?(:check_delivery_params)
28
+ location = File.join(settings[:location], "#{Time.now.to_f.to_s.tr('.', '_')}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
21
29
 
22
- location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
23
- messages = Message.rendered_messages(location, mail)
24
- Launchy.open("file:///#{URI.parse(URI.escape(messages.first.filepath))}")
30
+ messages = Message.rendered_messages(mail, location: location, message_template: settings[:message_template])
31
+ Launchy.open("file:///#{URI.parse(CGI.escape(messages.first.filepath))}")
25
32
  end
26
33
  end
27
34
  end
@@ -1,22 +1,26 @@
1
+ require "cgi"
1
2
  require "erb"
3
+ require "fileutils"
4
+ require "uri"
2
5
 
3
6
  module LetterOpener
4
7
  class Message
5
8
  attr_reader :mail
6
9
 
7
- def self.rendered_messages(location, mail)
10
+ def self.rendered_messages(mail, options = {})
8
11
  messages = []
9
- messages << new(location, mail, mail.html_part) if mail.html_part
10
- messages << new(location, mail, mail.text_part) if mail.text_part
11
- messages << new(location, mail) if messages.empty?
12
+ messages << new(mail, options.merge(part: mail.html_part)) if mail.html_part
13
+ messages << new(mail, options.merge(part: mail.text_part)) if mail.text_part
14
+ messages << new(mail, options) if messages.empty?
12
15
  messages.each(&:render)
13
16
  messages.sort
14
17
  end
15
18
 
16
- def initialize(location, mail, part = nil)
17
- @location = location
19
+ def initialize(mail, options = {})
18
20
  @mail = mail
19
- @part = part
21
+ @location = options[:location]
22
+ @part = options[:part]
23
+ @template = options[:message_template]
20
24
  @attachments = []
21
25
  end
22
26
 
@@ -27,14 +31,14 @@ module LetterOpener
27
31
  attachments_dir = File.join(@location, 'attachments')
28
32
  FileUtils.mkdir_p(attachments_dir)
29
33
  mail.attachments.each do |attachment|
30
- filename = attachment.filename.gsub(/[^\w.]/, '_')
34
+ filename = attachment_filename(attachment)
31
35
  path = File.join(attachments_dir, filename)
32
36
 
33
- unless File.exists?(path) # true if other parts have already been rendered
37
+ unless File.exist?(path) # true if other parts have already been rendered
34
38
  File.open(path, 'wb') { |f| f.write(attachment.body.raw_source) }
35
39
  end
36
40
 
37
- @attachments << [attachment.filename, "attachments/#{URI.escape(filename)}"]
41
+ @attachments << [attachment.filename, "attachments/#{CGI.escape(filename)}"]
38
42
  end
39
43
  end
40
44
 
@@ -44,7 +48,7 @@ module LetterOpener
44
48
  end
45
49
 
46
50
  def template
47
- File.read(File.expand_path("../message.html.erb", __FILE__))
51
+ File.read(File.expand_path("../templates/#{@template}.html.erb", __FILE__))
48
52
  end
49
53
 
50
54
  def filepath
@@ -60,7 +64,7 @@ module LetterOpener
60
64
  body = (@part || @mail).decoded
61
65
 
62
66
  mail.attachments.each do |attachment|
63
- body.gsub!(attachment.url, "attachments/#{attachment.filename}")
67
+ body.gsub!(attachment.url, "attachments/#{attachment_filename(attachment)}")
64
68
  end
65
69
 
66
70
  body
@@ -100,7 +104,7 @@ module LetterOpener
100
104
  end
101
105
 
102
106
  def auto_link(text)
103
- text.gsub(URI.regexp(%W[https http])) do |link|
107
+ text.gsub(URI::Parser.new.make_regexp(%W[https http])) do |link|
104
108
  "<a href=\"#{ link }\">#{ link }</a>"
105
109
  end
106
110
  end
@@ -109,6 +113,10 @@ module LetterOpener
109
113
  CGI.escapeHTML(content)
110
114
  end
111
115
 
116
+ def attachment_filename(attachment)
117
+ attachment.filename.gsub(/[^\w\-_.]/, '_')
118
+ end
119
+
112
120
  def <=>(other)
113
121
  order = %w[rich plain]
114
122
  order.index(type) <=> order.index(other.type)
@@ -2,7 +2,10 @@ module LetterOpener
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "letter_opener.add_delivery_method" do
4
4
  ActiveSupport.on_load :action_mailer do
5
- ActionMailer::Base.add_delivery_method :letter_opener, LetterOpener::DeliveryMethod, :location => Rails.root.join("tmp", "letter_opener")
5
+ ActionMailer::Base.add_delivery_method(
6
+ :letter_opener,
7
+ LetterOpener::DeliveryMethod
8
+ )
6
9
  end
7
10
  end
8
11
  end
@@ -127,5 +127,12 @@
127
127
  <iframe seamless="seamless" srcdoc="<base target='_top'><%= h(body) %>"></iframe>
128
128
  <% end %>
129
129
  </div>
130
+
131
+ <script type="text/javascript">
132
+ /*! srcdoc-polyfill - v0.1.1 - 2013-03-01
133
+ * http://github.com/jugglinmike/srcdoc-polyfill/
134
+ * Copyright (c) 2013 Mike Pennisi; Licensed MIT */
135
+ (function(t,e){var c,n,o=t.srcDoc,r=!!("srcdoc"in e.createElement("iframe")),i={compliant:function(t,e){e&&t.setAttribute("srcdoc",e)},legacy:function(t,e){var c;t&&t.getAttribute&&(e?t.setAttribute("srcdoc",e):e=t.getAttribute("srcdoc"),e&&(c="javascript: window.frameElement.getAttribute('srcdoc');",t.setAttribute("src",c),t.contentWindow&&(t.contentWindow.location=c)))}},s=t.srcDoc={set:i.compliant,noConflict:function(){return t.srcDoc=o,s}};if(!r)for(s.set=i.legacy,n=e.getElementsByTagName("iframe"),c=n.length;c--;)s.set(n[c])})(this,this.document);
136
+ </script>
130
137
  </body>
131
138
  </html>
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=<%= encoding %>">
4
+ <% if mail.subject %>
5
+ <title><%= h mail.subject %></title>
6
+ <% end %>
7
+ </head>
8
+ <body>
9
+ <%= body %>
10
+ </body>
11
+ </html>
@@ -7,7 +7,7 @@ describe LetterOpener::DeliveryMethod do
7
7
  let(:plain) { CGI.unescape_html(File.read(plain_file)) }
8
8
 
9
9
  before do
10
- Launchy.stub(:open)
10
+ allow(Launchy).to receive(:open)
11
11
  FileUtils.rm_rf(location)
12
12
  context = self
13
13
 
@@ -23,7 +23,7 @@ describe LetterOpener::DeliveryMethod do
23
23
 
24
24
  context 'integration' do
25
25
  before do
26
- Launchy.unstub(:open)
26
+ expect(Launchy).to receive(:open).and_call_original
27
27
  ENV['LAUNCHY_DRY_RUN'] = 'true'
28
28
  end
29
29
 
@@ -74,7 +74,7 @@ describe LetterOpener::DeliveryMethod do
74
74
  end
75
75
 
76
76
  it 'creates plain html document' do
77
- expect(File.exist?(plain_file)).to be_true
77
+ expect(File.exist?(plain_file)).to be_truthy
78
78
  end
79
79
 
80
80
  it 'saves From field' do
@@ -124,11 +124,11 @@ describe LetterOpener::DeliveryMethod do
124
124
  end
125
125
 
126
126
  it 'creates plain html document' do
127
- expect(File.exist?(plain_file)).to be_true
127
+ expect(File.exist?(plain_file)).to be_truthy
128
128
  end
129
129
 
130
130
  it 'creates rich html document' do
131
- expect(File.exist?(rich_file)).to be_true
131
+ expect(File.exist?(rich_file)).to be_truthy
132
132
  end
133
133
 
134
134
  it 'shows link to rich html version' do
@@ -188,7 +188,7 @@ describe LetterOpener::DeliveryMethod do
188
188
  end
189
189
 
190
190
  it 'creates plain html document' do
191
- expect(File.exist?(plain_file)).to be_true
191
+ expect(File.exist?(plain_file)).to be_truthy
192
192
  end
193
193
 
194
194
  it 'saves From field' do
@@ -223,7 +223,7 @@ describe LetterOpener::DeliveryMethod do
223
223
 
224
224
  it 'creates attachments dir with attachment' do
225
225
  attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
226
- expect(File.exists?(attachment)).to be_true
226
+ expect(File.exist?(attachment)).to be_truthy
227
227
  end
228
228
 
229
229
  it 'saves attachment name' do
@@ -251,7 +251,7 @@ describe LetterOpener::DeliveryMethod do
251
251
 
252
252
  it 'creates attachments dir with attachment' do
253
253
  attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
254
- expect(File.exists?(attachment)).to be_true
254
+ expect(File.exist?(attachment)).to be_truthy
255
255
  end
256
256
 
257
257
  it 'replaces inline attachment urls' do
@@ -271,18 +271,30 @@ describe LetterOpener::DeliveryMethod do
271
271
  text_part do
272
272
  body 'This is <plain> text'
273
273
  end
274
- attachments['non word:chars/used,01.txt'] = File.read(__FILE__)
274
+ attachments['non word:chars/used,01-02.txt'] = File.read(__FILE__)
275
+
276
+ url = attachments[0].url
277
+ html_part do
278
+ content_type 'text/html; charset=UTF-8'
279
+ body "This is an image: <img src='#{url}'>"
280
+ end
275
281
  end
276
282
  end
277
283
 
278
284
  it 'creates attachments dir with attachment' do
279
- attachment = Dir["#{location}/*/attachments/non_word_chars_used_01.txt"].first
280
- expect(File.exists?(attachment)).to be_true
285
+ attachment = Dir["#{location}/*/attachments/non_word_chars_used_01-02.txt"].first
286
+ expect(File.exist?(attachment)).to be_truthy
281
287
  end
282
288
 
283
289
  it 'saves attachment name' do
284
290
  plain = File.read(Dir["#{location}/*/plain.html"].first)
285
- expect(plain).to include('non_word_chars_used_01.txt')
291
+ expect(plain).to include('non_word_chars_used_01-02.txt')
292
+ end
293
+
294
+ it 'replaces inline attachment names' do
295
+ text = File.read(Dir["#{location}/*/rich.html"].first)
296
+ expect(text).to_not include('attachments/non word:chars/used,01-02.txt')
297
+ expect(text).to include('attachments/non_word_chars_used_01-02.txt')
286
298
  end
287
299
  end
288
300
 
@@ -299,7 +311,7 @@ describe LetterOpener::DeliveryMethod do
299
311
  end
300
312
 
301
313
  it 'creates plain html document' do
302
- expect(File.exist?(plain_file)).to be_true
314
+ expect(File.exist?(plain_file)).to be_truthy
303
315
  end
304
316
  end
305
317
 
@@ -316,4 +328,36 @@ describe LetterOpener::DeliveryMethod do
316
328
  }.to raise_exception(ArgumentError)
317
329
  end
318
330
  end
331
+
332
+ context 'light template' do
333
+ before do
334
+ expect(Launchy).to receive(:open)
335
+
336
+ LetterOpener.configure do |config|
337
+ config.message_template = :light
338
+ end
339
+
340
+ Mail.defaults do
341
+ delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../../../tmp/letter_opener', __FILE__)
342
+ end
343
+
344
+ Mail.deliver do
345
+ subject 'Foo subject'
346
+ from 'Foo foo@example.com'
347
+ reply_to 'No Reply no-reply@example.com'
348
+ to 'Bar bar@example.com'
349
+ body 'World! http://example.com'
350
+ end
351
+ end
352
+
353
+ after do
354
+ LetterOpener.configure do |config|
355
+ config.message_template = :default
356
+ end
357
+ end
358
+
359
+ it 'creates plain html document' do
360
+ expect(File.exist?(plain_file)).to be_truthy
361
+ end
362
+ end
319
363
  end
@@ -11,25 +11,25 @@ describe LetterOpener::Message do
11
11
  describe '#reply_to' do
12
12
  it 'handles one email as a string' do
13
13
  mail = mail(:reply_to => 'test@example.com')
14
- message = described_class.new(location, mail)
14
+ message = described_class.new(mail, location: location)
15
15
  expect(message.reply_to).to eq('test@example.com')
16
16
  end
17
17
 
18
18
  it 'handles one email with display names' do
19
19
  mail = mail(:reply_to => 'test <test@example.com>')
20
- message = described_class.new(location, mail)
20
+ message = described_class.new(mail, location: location)
21
21
  expect(message.reply_to).to eq('test <test@example.com>')
22
22
  end
23
23
 
24
24
  it 'handles array of emails' do
25
25
  mail = mail(:reply_to => ['test1@example.com', 'test2@example.com'])
26
- message = described_class.new(location, mail)
26
+ message = described_class.new(mail, location: location)
27
27
  expect(message.reply_to).to eq('test1@example.com, test2@example.com')
28
28
  end
29
29
 
30
30
  it 'handles array of emails with display names' do
31
31
  mail = mail(:reply_to => ['test1 <test1@example.com>', 'test2 <test2@example.com>'])
32
- message = described_class.new(location, mail)
32
+ message = described_class.new(mail, location: location)
33
33
  expect(message.reply_to).to eq('test1 <test1@example.com>, test2 <test2@example.com>')
34
34
  end
35
35
 
@@ -38,25 +38,25 @@ describe LetterOpener::Message do
38
38
  describe '#to' do
39
39
  it 'handles one email as a string' do
40
40
  mail = mail(:to => 'test@example.com')
41
- message = described_class.new(location, mail)
41
+ message = described_class.new(mail, location: location)
42
42
  expect(message.to).to eq('test@example.com')
43
43
  end
44
44
 
45
45
  it 'handles one email with display names' do
46
46
  mail = mail(:to => 'test <test@example.com>')
47
- message = described_class.new(location, mail)
47
+ message = described_class.new(mail, location: location)
48
48
  expect(message.to).to eq('test <test@example.com>')
49
49
  end
50
50
 
51
51
  it 'handles array of emails' do
52
52
  mail = mail(:to => ['test1@example.com', 'test2@example.com'])
53
- message = described_class.new(location, mail)
53
+ message = described_class.new(mail, location: location)
54
54
  expect(message.to).to eq('test1@example.com, test2@example.com')
55
55
  end
56
56
 
57
57
  it 'handles array of emails with display names' do
58
58
  mail = mail(:to => ['test1 <test1@example.com>', 'test2 <test2@example.com>'])
59
- message = described_class.new(location, mail)
59
+ message = described_class.new(mail, location: location)
60
60
  expect(message.to).to eq('test1 <test1@example.com>, test2 <test2@example.com>')
61
61
  end
62
62
 
@@ -65,25 +65,25 @@ describe LetterOpener::Message do
65
65
  describe '#cc' do
66
66
  it 'handles one cc email as a string' do
67
67
  mail = mail(:cc => 'test@example.com')
68
- message = described_class.new(location, mail)
68
+ message = described_class.new(mail, location: location)
69
69
  expect(message.cc).to eq('test@example.com')
70
70
  end
71
71
 
72
72
  it 'handles one cc email with display name' do
73
73
  mail = mail(:cc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
74
- message = described_class.new(location, mail)
74
+ message = described_class.new(mail, location: location)
75
75
  expect(message.cc).to eq('test <test1@example.com>, test2 <test2@example.com>')
76
76
  end
77
77
 
78
78
  it 'handles array of cc emails' do
79
79
  mail = mail(:cc => ['test1@example.com', 'test2@example.com'])
80
- message = described_class.new(location, mail)
80
+ message = described_class.new(mail, location: location)
81
81
  expect(message.cc).to eq('test1@example.com, test2@example.com')
82
82
  end
83
83
 
84
84
  it 'handles array of cc emails with display names' do
85
85
  mail = mail(:cc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
86
- message = described_class.new(location, mail)
86
+ message = described_class.new(mail, location: location)
87
87
  expect(message.cc).to eq('test <test1@example.com>, test2 <test2@example.com>')
88
88
  end
89
89
 
@@ -92,25 +92,25 @@ describe LetterOpener::Message do
92
92
  describe '#bcc' do
93
93
  it 'handles one bcc email as a string' do
94
94
  mail = mail(:bcc => 'test@example.com')
95
- message = described_class.new(location, mail)
95
+ message = described_class.new(mail, location: location)
96
96
  expect(message.bcc).to eq('test@example.com')
97
97
  end
98
98
 
99
99
  it 'handles one bcc email with display name' do
100
100
  mail = mail(:bcc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
101
- message = described_class.new(location, mail)
101
+ message = described_class.new(mail, location: location)
102
102
  expect(message.bcc).to eq('test <test1@example.com>, test2 <test2@example.com>')
103
103
  end
104
104
 
105
105
  it 'handles array of bcc emails' do
106
106
  mail = mail(:bcc => ['test1@example.com', 'test2@example.com'])
107
- message = described_class.new(location, mail)
107
+ message = described_class.new(mail, location: location)
108
108
  expect(message.bcc).to eq('test1@example.com, test2@example.com')
109
109
  end
110
110
 
111
111
  it 'handles array of bcc emails with display names' do
112
112
  mail = mail(:bcc => ['test <test1@example.com>', 'test2 <test2@example.com>'])
113
- message = described_class.new(location, mail)
113
+ message = described_class.new(mail, location: location)
114
114
  expect(message.bcc).to eq('test <test1@example.com>, test2 <test2@example.com>')
115
115
  end
116
116
 
@@ -119,25 +119,25 @@ describe LetterOpener::Message do
119
119
  describe '#sender' do
120
120
  it 'handles one email as a string' do
121
121
  mail = mail(:sender => 'sender@example.com')
122
- message = described_class.new(location, mail)
122
+ message = described_class.new(mail, location: location)
123
123
  expect(message.sender).to eq('sender@example.com')
124
124
  end
125
125
 
126
126
  it 'handles one email as a string with display name' do
127
127
  mail = mail(:sender => 'test <test@example.com>')
128
- message = described_class.new(location, mail)
128
+ message = described_class.new(mail, location: location)
129
129
  expect(message.sender).to eq('test <test@example.com>')
130
130
  end
131
131
 
132
132
  it 'handles array of emails' do
133
133
  mail = mail(:sender => ['sender1@example.com', 'sender2@example.com'])
134
- message = described_class.new(location, mail)
134
+ message = described_class.new(mail, location: location)
135
135
  expect(message.sender).to eq('sender1@example.com, sender2@example.com')
136
136
  end
137
137
 
138
138
  it 'handles array of emails with display names' do
139
139
  mail = mail(:sender => ['test <test1@example.com>', 'test2 <test2@example.com>'])
140
- message = described_class.new(location, mail)
140
+ message = described_class.new(mail, location: location)
141
141
  expect(message.sender).to eq('test <test1@example.com>, test2 <test2@example.com>')
142
142
  end
143
143
 
@@ -145,14 +145,14 @@ describe LetterOpener::Message do
145
145
 
146
146
  describe '#<=>' do
147
147
  it 'sorts rich type before plain type' do
148
- plain = described_class.new(location, double(content_type: 'text/plain'))
149
- rich = described_class.new(location, double(content_type: 'text/html'))
148
+ plain = described_class.new(double(content_type: 'text/plain'), location: location)
149
+ rich = described_class.new(double(content_type: 'text/html'), location: location)
150
150
  expect([plain, rich].sort).to eq([rich, plain])
151
151
  end
152
152
  end
153
153
 
154
154
  describe '#auto_link' do
155
- let(:message){ described_class.new(location, mail) }
155
+ let(:message){ described_class.new(mail, location: location) }
156
156
 
157
157
  it 'does not modify unlinkable text' do
158
158
  text = 'the quick brown fox jumped over the lazy dog'
@@ -173,7 +173,7 @@ describe LetterOpener::Message do
173
173
  content_transfer_encoding 'quoted-printable'
174
174
  body "☃"
175
175
  end
176
- message = described_class.new(location, mail)
176
+ message = message = described_class.new(mail, location: location)
177
177
  expect(message.body.encoding.name).to eq('UTF-8')
178
178
  end
179
179
 
@@ -185,7 +185,7 @@ describe LetterOpener::Message do
185
185
  body "☃"
186
186
  end
187
187
  end
188
- message = described_class.new(location, mail, mail.html_part)
188
+ message = described_class.new(mail, location: location, part: mail.html_part)
189
189
  expect(message.body.encoding.name).to eq('UTF-8')
190
190
  end
191
191
 
@@ -197,7 +197,7 @@ describe LetterOpener::Message do
197
197
  body "☃"
198
198
  end
199
199
  end
200
- message = described_class.new(location, mail, mail.text_part)
200
+ message = described_class.new(mail, location: location, part: mail.text_part)
201
201
  expect(message.body.encoding.name).to eq('UTF-8')
202
202
  end
203
203
  end
@@ -5,6 +5,5 @@ Bundler.require(:default)
5
5
  require "mail"
6
6
 
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_opener
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.0
33
+ version: 3.5.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.14.0
40
+ version: 3.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mail
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,17 +64,19 @@ files:
64
64
  - LICENSE
65
65
  - README.rdoc
66
66
  - Rakefile
67
- - letter_opener.gemspec
68
67
  - lib/letter_opener.rb
68
+ - lib/letter_opener/configuration.rb
69
69
  - lib/letter_opener/delivery_method.rb
70
- - lib/letter_opener/message.html.erb
71
70
  - lib/letter_opener/message.rb
72
71
  - lib/letter_opener/railtie.rb
72
+ - lib/letter_opener/templates/default.html.erb
73
+ - lib/letter_opener/templates/light.html.erb
73
74
  - spec/letter_opener/delivery_method_spec.rb
74
75
  - spec/letter_opener/message_spec.rb
75
76
  - spec/spec_helper.rb
76
77
  homepage: http://github.com/ryanb/letter_opener
77
- licenses: []
78
+ licenses:
79
+ - MIT
78
80
  metadata: {}
79
81
  post_install_message:
80
82
  rdoc_options: []
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  version: 1.3.4
93
95
  requirements: []
94
96
  rubyforge_project: letter_opener
95
- rubygems_version: 2.4.6
97
+ rubygems_version: 2.6.14
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: Preview mail in browser instead of sending.
@@ -1,19 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "letter_opener"
3
- s.version = "1.4.1"
4
- s.author = "Ryan Bates"
5
- s.email = "ryan@railscasts.com"
6
- s.homepage = "http://github.com/ryanb/letter_opener"
7
- s.summary = "Preview mail in browser instead of sending."
8
- s.description = "When mail is sent from your application, Letter Opener will open a preview in the browser instead of sending."
9
-
10
- s.files = Dir["{lib,spec}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
11
- s.require_path = "lib"
12
-
13
- s.add_dependency 'launchy', '~> 2.2'
14
- s.add_development_dependency 'rspec', '~> 2.14.0'
15
- s.add_development_dependency 'mail', '~> 2.6.0'
16
-
17
- s.rubyforge_project = s.name
18
- s.required_rubygems_version = ">= 1.3.4"
19
- end