letter_opener 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,24 +1,31 @@
1
+ ## 1.1.0 ##
2
+
3
+ * Update Launchy dependency to `~> 2.2.0` (thanks [webdevotion](https://github.com/webdevotion))
4
+ * Handle `sender` field (thanks [sjtipton](https://github.com/sjtipton))
5
+ * Show subject only if it's present (thanks [jadehyper](https://github.com/jadehyper))
6
+ * Show subject as title of web page (thanks [statique](https://github.com/statique))
7
+
1
8
  ## 1.0.0 ##
2
9
 
3
- * Attachment Support (thanks David Cornu)
10
+ * Attachment Support (thanks [David Cornu](https://github.com/davidcornu))
4
11
  * Escape HTML in subject and other fields
5
12
  * Raise an exception if the :location option is not present instead of using a default
6
- * Open rich version by default (thanks Damir)
7
- * Override margin on dt and dd elements in CSS (thanks Edgars Beigarts)
8
- * Autolink URLs in plain version (thanks Matt Burke)
13
+ * Open rich version by default (thanks [Damir](https://github.com/sidonath))
14
+ * Override margin on dt and dd elements in CSS (thanks [Edgars Beigarts](https://github.com/ebeigarts))
15
+ * Autolink URLs in plain version (thanks [Matt Burke](https://github.com/spraints))
9
16
 
10
17
  ## 0.1.0 ##
11
18
 
12
19
  * From and To show name and Email when specified
13
20
  * Fix bug when letter_opener couldn't open email in Windows
14
- * Handle spaces in the application path (thanks Mike Boone)
15
- * As letter_opener doesn't work with Launchy < 2.0.4 let's depend on >= 2.0.4 (thanks Samnang Chhun)
16
- * Handle `reply_to` field (thanks Wes Gibbs)
17
- * Set the charset in email preview (thanks Bruno Michel)
21
+ * Handle spaces in the application path (thanks [Mike Boone](https://github.com/boone))
22
+ * As letter_opener doesn't work with Launchy < 2.0.4 let's depend on >= 2.0.4 (thanks [Samnang Chhun](https://github.com/samnang))
23
+ * Handle `reply_to` field (thanks [Wes Gibbs](https://github.com/wgibbs))
24
+ * Set the charset in email preview (thanks [Bruno Michel](https://github.com/nono))
18
25
 
19
26
  ## 0.0.2 ##
20
27
 
21
- * Fixing launchy requirement (thanks Bruno Michel)
28
+ * Fixing launchy requirement (thanks [Bruno Michel](https://github.com/nono))
22
29
 
23
30
  ## 0.0.1 ##
24
31
 
data/README.rdoc CHANGED
@@ -15,6 +15,9 @@ Then set the delivery method in <tt>config/environments/development.rb</tt>
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
17
 
18
+ ==== For Rails 2.3.x support
19
+
20
+ There is a fork that add support for Rails 2.3.x, in order to use that or just check it out you should go to https://github.com/cavi21/letter_opener
18
21
 
19
22
  == Non Rails Setup
20
23
 
@@ -25,6 +28,14 @@ If you aren't using Rails, this can be easily set up with the Mail gem. Just set
25
28
  delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
26
29
  end
27
30
 
31
+ The method is similar if you're using the Pony gem:
32
+
33
+ require "letter_opener"
34
+ Pony.options = {
35
+ :via => LetterOpener::DeliveryMethod,
36
+ :via_options => {:location => File.expand_path('../tmp/letter_opener', __FILE__)}
37
+ }
38
+
28
39
  Alternatively, if you are using ActionMailer directly (without Rails) you will need to add the delivery method.
29
40
 
30
41
  require "letter_opener"
@@ -32,6 +43,13 @@ Alternatively, if you are using ActionMailer directly (without Rails) you will n
32
43
  ActionMailer::Base.delivery_method = :letter_opener
33
44
 
34
45
 
46
+ == Remote Alternatives
47
+
48
+ Letter Opener uses {Launchy}[https://github.com/copiousfreetime/launchy] to open sent mail in the browser. This assumes the Ruby process is running on the local development machine. If you are using a separate staging server or VM this will not work. In that case consider using {Mailtrap}[http://mailtrap.io/] or {MailCatcher}[http://mailcatcher.me/].
49
+
50
+ In order to keep this project simple, I don't have plans to turn it into a Rails engine with an interface for browsing the sent mail but there is a work in progress gem being developed at https://github.com/fgrehm/letter_opener_web
51
+
52
+
35
53
  == Development & Feedback
36
54
 
37
55
  Questions or problems? Please use the {issue tracker}[https://github.com/ryanb/letter_opener/issues]. If you would like to contribute to this project, fork this repository and run +bundle+ and +rake+ to run the tests. Pull requests appreciated.
@@ -12,7 +12,7 @@ module LetterOpener
12
12
  def deliver!(mail)
13
13
  location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
14
14
  messages = Message.rendered_messages(location, mail)
15
- Launchy.open(URI.parse(URI.escape(messages.first.filepath)))
15
+ Launchy.open(URI.escape(messages.first.filepath))
16
16
  end
17
17
  end
18
18
  end
@@ -1,4 +1,7 @@
1
1
  <meta http-equiv="Content-Type" content="text/html; charset=<%= encoding %>">
2
+ <% if mail.subject %>
3
+ <title><%= h mail.subject %></title>
4
+ <% end %>
2
5
 
3
6
  <style type="text/css">
4
7
  #message_headers {
@@ -53,13 +56,20 @@
53
56
  <dt>From:</dt>
54
57
  <dd><%= h from %></dd>
55
58
 
59
+ <% unless sender.empty? %>
60
+ <dt>Sender:</dt>
61
+ <dd><%= h sender %></dd>
62
+ <% end %>
63
+
56
64
  <% unless reply_to.empty? %>
57
65
  <dt>Reply-To:</dt>
58
66
  <dd><%= h reply_to %></dd>
59
67
  <% end %>
60
68
 
61
- <dt>Subject:</dt>
62
- <dd><strong><%= h mail.subject %></strong></dd>
69
+ <% if mail.subject %>
70
+ <dt>Subject:</dt>
71
+ <dd><strong><%= h mail.subject %></strong></dd>
72
+ <% end %>
63
73
 
64
74
  <dt>Date:</dt>
65
75
  <dd><%= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z") %></dd>
@@ -1,3 +1,5 @@
1
+ require "erb"
2
+
1
3
  module LetterOpener
2
4
  class Message
3
5
  attr_reader :mail
@@ -68,6 +70,10 @@ module LetterOpener
68
70
  @from ||= Array(@mail.from).join(", ")
69
71
  end
70
72
 
73
+ def sender
74
+ @sender ||= Array(@mail.sender).join(", ")
75
+ end
76
+
71
77
  def to
72
78
  @to ||= Array(@mail.to).join(", ")
73
79
  end
@@ -1,7 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe LetterOpener::DeliveryMethod do
4
- let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
4
+ let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
5
+
6
+ let(:plain_file) { Dir["#{location}/*/plain.html"].first }
7
+ let(:plain) { File.read(plain_file) }
5
8
 
6
9
  before do
7
10
  Launchy.stub(:open)
@@ -19,15 +22,13 @@ describe LetterOpener::DeliveryMethod do
19
22
  end
20
23
 
21
24
  context 'content' do
22
- let(:plain_file) { Dir["#{location}/*/plain.html"].first }
23
- let(:plain) { File.read(plain_file) }
24
-
25
25
  context 'plain' do
26
26
  before do
27
27
  Launchy.should_receive(:open)
28
28
 
29
29
  Mail.deliver do
30
30
  from 'Foo foo@example.com'
31
+ sender 'Baz baz@example.com'
31
32
  reply_to 'No Reply no-reply@example.com'
32
33
  to 'Bar bar@example.com'
33
34
  subject 'Hello'
@@ -43,6 +44,10 @@ describe LetterOpener::DeliveryMethod do
43
44
  plain.should include("Foo foo@example.com")
44
45
  end
45
46
 
47
+ it 'saves Sender field' do
48
+ plain.should include("Baz baz@example.com")
49
+ end
50
+
46
51
  it 'saves Reply-to field' do
47
52
  plain.should include("No Reply no-reply@example.com")
48
53
  end
@@ -104,13 +109,15 @@ describe LetterOpener::DeliveryMethod do
104
109
  it 'saves escaped Subject field' do
105
110
  plain.should include("Many parts with &lt;html&gt;")
106
111
  end
112
+
113
+ it 'shows subject as title' do
114
+ rich.should include("<title>Many parts with &lt;html&gt;</title>")
115
+ end
107
116
  end
108
117
  end
109
118
 
110
119
  context 'document with spaces in name' do
111
120
  let(:location) { File.expand_path('../../../tmp/letter_opener with space', __FILE__) }
112
- let(:file) { Dir["#{location}/*/plain.html"].first }
113
- let(:plain) { File.read(file) }
114
121
 
115
122
  before do
116
123
  Launchy.should_receive(:open)
@@ -124,7 +131,7 @@ describe LetterOpener::DeliveryMethod do
124
131
  end
125
132
 
126
133
  it 'creates plain html document' do
127
- File.exist?(file)
134
+ File.exist?(plain_file)
128
135
  end
129
136
 
130
137
  it 'saves From filed' do
@@ -133,9 +140,6 @@ describe LetterOpener::DeliveryMethod do
133
140
  end
134
141
 
135
142
  context 'using deliver! method' do
136
- let(:plain_file) { Dir["#{location}/*/plain.html"].first }
137
- let(:plain) { File.read(plain_file) }
138
-
139
143
  before do
140
144
  Launchy.should_receive(:open)
141
145
  Mail.new do
@@ -220,4 +224,21 @@ describe LetterOpener::DeliveryMethod do
220
224
  text.should include("attachments/#{File.basename(__FILE__)}")
221
225
  end
222
226
  end
227
+
228
+ context 'subjectless mail' do
229
+ before do
230
+ Launchy.should_receive(:open)
231
+
232
+ Mail.deliver do
233
+ from 'Foo foo@example.com'
234
+ reply_to 'No Reply no-reply@example.com'
235
+ to 'Bar bar@example.com'
236
+ body 'World! http://example.com'
237
+ end
238
+ end
239
+
240
+ it 'creates plain html document' do
241
+ File.exist?(plain_file).should be_true
242
+ end
243
+ end
223
244
  end
@@ -27,6 +27,18 @@ describe LetterOpener::Message do
27
27
  end
28
28
  end
29
29
 
30
+ describe '#sender' do
31
+ it 'handles one email as a string' do
32
+ message = described_class.new(location, mock(sender: 'sender@example.com'))
33
+ message.sender.should eq('sender@example.com')
34
+ end
35
+
36
+ it 'handles array of emails' do
37
+ message = described_class.new(location, mock(sender: ['sender1@example.com', 'sender2@example.com']))
38
+ message.sender.should eq('sender1@example.com, sender2@example.com')
39
+ end
40
+ end
41
+
30
42
  describe '#<=>' do
31
43
  it 'sorts rich type before plain type' do
32
44
  plain = described_class.new(location, mock(content_type: 'text/plain'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_opener
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: launchy
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.4
21
+ version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.0.4
29
+ version: 2.2.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.6.0
37
+ version: 2.12.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.6.0
45
+ version: 2.12.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: mail
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 2.3.0
53
+ version: 2.5.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 2.3.0
61
+ version: 2.5.0
62
62
  description: When mail is sent from your application, Letter Opener will open a preview
63
63
  in the browser instead of sending.
64
64
  email: ryan@railscasts.com
@@ -91,6 +91,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 4310965530759568709
94
97
  required_rubygems_version: !ruby/object:Gem::Requirement
95
98
  none: false
96
99
  requirements:
@@ -99,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
102
  version: 1.3.4
100
103
  requirements: []
101
104
  rubyforge_project: letter_opener
102
- rubygems_version: 1.8.23
105
+ rubygems_version: 1.8.24
103
106
  signing_key:
104
107
  specification_version: 3
105
108
  summary: Preview mail in browser instead of sending.