padrino-mailer 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.rdoc +75 -35
  2. data/Rakefile +4 -52
  3. data/lib/padrino-mailer.rb +16 -8
  4. data/lib/padrino-mailer/base.rb +57 -78
  5. data/lib/padrino-mailer/ext.rb +231 -0
  6. data/lib/padrino-mailer/helpers.rb +125 -0
  7. data/lib/padrino-mailer/mime.rb +42 -0
  8. data/padrino-mailer.gemspec +15 -70
  9. data/test/fixtures/basic.erb +1 -0
  10. data/test/fixtures/layout.erb +1 -0
  11. data/test/fixtures/padrino_app/app.rb +69 -0
  12. data/test/fixtures/{mailer_app/views/demo_mailer → padrino_app/views/mailers/demo}/sample_mail.erb +0 -0
  13. data/test/fixtures/{mailer_app/views/sample_mailer/anniversary_message.erb → padrino_app/views/mailers/sample/anniversary.erb} +0 -0
  14. data/test/fixtures/{mailer_app/views/sample_mailer/birthday_message.erb → padrino_app/views/mailers/sample/birthday.erb} +0 -0
  15. data/test/fixtures/{mailer_app/views/sample_mailer → padrino_app/views/mailers/sample}/foo_message.erb +0 -0
  16. data/test/fixtures/sinatra_app/app.rb +67 -0
  17. data/test/fixtures/sinatra_app/views/mailers/demo/sample_mail.erb +1 -0
  18. data/test/fixtures/sinatra_app/views/mailers/sample/anniversary.erb +2 -0
  19. data/test/fixtures/sinatra_app/views/mailers/sample/birthday.erb +2 -0
  20. data/test/fixtures/sinatra_app/views/mailers/sample/foo_message.erb +1 -0
  21. data/test/fixtures/views/mailers/alternate/foo.erb +1 -0
  22. data/test/fixtures/views/mailers/bar.erb +1 -0
  23. data/test/fixtures/views/mailers/i18n/hello.en.erb +1 -0
  24. data/test/fixtures/views/mailers/i18n/hello.it.erb +1 -0
  25. data/test/fixtures/views/mailers/layouts/sample.erb +1 -0
  26. data/test/fixtures/views/mailers/multipart/basic.html.erb +1 -0
  27. data/test/fixtures/views/mailers/multipart/basic.plain.erb +1 -0
  28. data/test/fixtures/views/mailers/sample/foo.erb +1 -0
  29. data/test/helper.rb +38 -42
  30. data/test/test_email.rb +158 -0
  31. data/test/test_message.rb +153 -0
  32. data/test/test_padrino_mailer.rb +64 -23
  33. data/test/test_part.rb +119 -0
  34. metadata +95 -51
  35. data/lib/padrino-mailer/delivery.rb +0 -110
  36. data/lib/padrino-mailer/mail_object.rb +0 -65
  37. data/test/fixtures/mailer_app/app.rb +0 -64
  38. data/test/test_base.rb +0 -86
  39. data/test/test_mail_object.rb +0 -25
data/test/test_part.rb ADDED
@@ -0,0 +1,119 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestPart < Test::Unit::TestCase
4
+
5
+ context "the part" do
6
+ should "use correctly parts" do
7
+ message = Mail::Message.new do
8
+ views File.dirname(__FILE__) + '/fixtures/views/mailers'
9
+ to 'padrino@test.lindsaar.net'
10
+ subject "nested multipart"
11
+ from "test@example.com"
12
+
13
+ text_part do
14
+ body 'plain text'
15
+ end
16
+
17
+ html_part do
18
+ render 'sample/foo'
19
+ end
20
+
21
+ part do
22
+ body 'other'
23
+ end
24
+ end
25
+
26
+ assert_not_nil message.html_part
27
+ assert_not_nil message.text_part
28
+ assert_equal 4, message.parts.length
29
+ assert_equal :plain, message.parts[0].content_type
30
+ assert_equal "plain text", message.parts[0].body.decoded
31
+ assert_equal :html, message.parts[1].content_type
32
+ assert_equal "This is a foo message in mailers/sample dir", message.parts[1].body.decoded
33
+ assert_equal :plain, message.parts[2].content_type
34
+ assert_equal "other", message.parts[2].body.decoded
35
+ end
36
+
37
+ should "works with multipart templates" do
38
+ message = Mail::Message.new do
39
+ views File.dirname(__FILE__) + '/fixtures/views/mailers'
40
+ to 'padrino@test.lindsaar.net'
41
+ subject "nested multipart"
42
+ from "test@example.com"
43
+
44
+ text_part do
45
+ render 'multipart/basic.text'
46
+ end
47
+
48
+ html_part do
49
+ render 'multipart/basic.html'
50
+ end
51
+ end
52
+
53
+ assert_not_nil message.html_part
54
+ assert_not_nil message.text_part
55
+ assert_equal 2, message.parts.length
56
+ assert_equal :plain, message.parts[0].content_type
57
+ assert_equal "plain text", message.parts[0].body.decoded
58
+ assert_equal :html, message.parts[1].content_type
59
+ assert_equal "text html", message.parts[1].body.decoded
60
+ end
61
+
62
+ should "works with less explict multipart templates" do
63
+ message = Mail::Message.new do
64
+ views File.dirname(__FILE__) + '/fixtures/views/mailers'
65
+ to 'padrino@test.lindsaar.net'
66
+ subject "nested multipart"
67
+ from "test@example.com"
68
+
69
+ text_part { render('multipart/basic.plain') }
70
+ html_part { render('multipart/basic.html') }
71
+ end
72
+
73
+ assert_not_nil message.html_part
74
+ assert_not_nil message.text_part
75
+ assert_equal 2, message.parts.length
76
+ assert_equal :plain, message.parts[0].content_type
77
+ assert_equal "plain text", message.parts[0].body.decoded
78
+ assert_equal :html, message.parts[1].content_type
79
+ assert_equal "text html", message.parts[1].body.decoded
80
+ end
81
+
82
+ should "works with provides" do
83
+ message = Mail::Message.new do
84
+ views File.dirname(__FILE__) + '/fixtures/views/mailers'
85
+ to 'padrino@test.lindsaar.net'
86
+ subject "nested multipart"
87
+ from "test@example.com"
88
+ provides :plain, :html
89
+ render 'multipart/basic'
90
+ end
91
+
92
+ assert_equal 2, message.parts.length
93
+ assert_equal :plain, message.parts[0].content_type
94
+ assert_equal "plain text", message.parts[0].body.decoded
95
+ assert_equal :html, message.parts[1].content_type
96
+ assert_equal "text html", message.parts[1].body.decoded
97
+ end
98
+
99
+ # should "provide a way to instantiate a new part as you go down" do
100
+ # message = Mail::Message.new do
101
+ # to 'padrino@test.lindsaar.net'
102
+ # subject "nested multipart"
103
+ # from "test@example.com"
104
+ # content_type "multipart/mixed"
105
+ #
106
+ # part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p|
107
+ # p.part :content_type => "text/plain", :body => "test text\nline #2"
108
+ # p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
109
+ # end
110
+ # end
111
+ #
112
+ # assert_equal 2, message.parts.first.parts.length
113
+ # assert_equal :plain, message.parts.first.parts[0].content_type
114
+ # assert_equal "test text\nline #2", message.parts.first.parts[0].body.decoded
115
+ # assert_equal :html, message.parts.first.parts[1].content_type
116
+ # assert_equal "<b>test</b> HTML<br/>\nline #2", message.parts.first.parts[1].body.decoded
117
+ # end
118
+ end
119
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 10
9
- version: 0.9.10
8
+ - 11
9
+ version: 0.9.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Padrino Team
@@ -17,106 +17,129 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-04-22 00:00:00 +02:00
20
+ date: 2010-06-17 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: padrino-core
25
- prerelease: false
26
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
30
30
  segments:
31
31
  - 0
32
32
  - 9
33
- - 10
34
- version: 0.9.10
33
+ - 11
34
+ version: 0.9.11
35
35
  type: :runtime
36
+ prerelease: false
36
37
  version_requirements: *id001
37
38
  - !ruby/object:Gem::Dependency
38
- name: tmail
39
- prerelease: false
39
+ name: mail
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
45
  segments:
45
- - 1
46
46
  - 2
47
- version: "1.2"
47
+ - 2
48
+ - 0
49
+ version: 2.2.0
48
50
  type: :runtime
51
+ prerelease: false
49
52
  version_requirements: *id002
50
53
  - !ruby/object:Gem::Dependency
51
- name: shoulda
52
- prerelease: false
54
+ name: rake
53
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
54
57
  requirements:
55
58
  - - ">="
56
59
  - !ruby/object:Gem::Version
57
60
  segments:
58
- - 2
59
- - 10
60
- - 3
61
- version: 2.10.3
61
+ - 0
62
+ - 8
63
+ - 7
64
+ version: 0.8.7
62
65
  type: :development
66
+ prerelease: false
63
67
  version_requirements: *id003
64
68
  - !ruby/object:Gem::Dependency
65
- name: haml
66
- prerelease: false
69
+ name: mocha
67
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
68
72
  requirements:
69
73
  - - ">="
70
74
  - !ruby/object:Gem::Version
71
75
  segments:
72
- - 2
73
- - 2
74
- - 1
75
- version: 2.2.1
76
+ - 0
77
+ - 9
78
+ - 8
79
+ version: 0.9.8
76
80
  type: :development
81
+ prerelease: false
77
82
  version_requirements: *id004
78
83
  - !ruby/object:Gem::Dependency
79
- name: mocha
80
- prerelease: false
84
+ name: rack-test
81
85
  requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
82
87
  requirements:
83
88
  - - ">="
84
89
  - !ruby/object:Gem::Version
85
90
  segments:
86
91
  - 0
87
- - 9
88
- - 7
89
- version: 0.9.7
92
+ - 5
93
+ - 0
94
+ version: 0.5.0
90
95
  type: :development
96
+ prerelease: false
91
97
  version_requirements: *id005
92
98
  - !ruby/object:Gem::Dependency
93
- name: rack-test
94
- prerelease: false
99
+ name: webrat
95
100
  requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
96
102
  requirements:
97
103
  - - ">="
98
104
  - !ruby/object:Gem::Version
99
105
  segments:
100
106
  - 0
101
107
  - 5
102
- - 0
103
- version: 0.5.0
108
+ - 1
109
+ version: 0.5.1
104
110
  type: :development
111
+ prerelease: false
105
112
  version_requirements: *id006
106
113
  - !ruby/object:Gem::Dependency
107
- name: webrat
108
- prerelease: false
114
+ name: haml
109
115
  requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
110
117
  requirements:
111
118
  - - ">="
112
119
  - !ruby/object:Gem::Version
113
120
  segments:
114
- - 0
115
- - 5
116
- - 1
117
- version: 0.5.1
121
+ - 2
122
+ - 2
123
+ - 22
124
+ version: 2.2.22
118
125
  type: :development
126
+ prerelease: false
119
127
  version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: shoulda
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 2
137
+ - 10
138
+ - 3
139
+ version: 2.10.3
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: *id008
120
143
  description: Mailer system for padrino allowing easy delivery of application emails
121
144
  email: padrinorb@gmail.com
122
145
  executables: []
@@ -131,20 +154,37 @@ files:
131
154
  - LICENSE
132
155
  - README.rdoc
133
156
  - Rakefile
134
- - lib/padrino-mailer.rb
135
- - lib/padrino-mailer/base.rb
136
- - lib/padrino-mailer/delivery.rb
137
- - lib/padrino-mailer/mail_object.rb
138
157
  - padrino-mailer.gemspec
139
- - test/fixtures/mailer_app/app.rb
140
- - test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb
141
- - test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb
142
- - test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb
143
- - test/fixtures/mailer_app/views/sample_mailer/foo_message.erb
158
+ - lib/padrino-mailer/base.rb
159
+ - lib/padrino-mailer/ext.rb
160
+ - lib/padrino-mailer/helpers.rb
161
+ - lib/padrino-mailer/mime.rb
162
+ - lib/padrino-mailer.rb
163
+ - test/fixtures/basic.erb
164
+ - test/fixtures/layout.erb
165
+ - test/fixtures/padrino_app/app.rb
166
+ - test/fixtures/padrino_app/views/mailers/demo/sample_mail.erb
167
+ - test/fixtures/padrino_app/views/mailers/sample/anniversary.erb
168
+ - test/fixtures/padrino_app/views/mailers/sample/birthday.erb
169
+ - test/fixtures/padrino_app/views/mailers/sample/foo_message.erb
170
+ - test/fixtures/sinatra_app/app.rb
171
+ - test/fixtures/sinatra_app/views/mailers/demo/sample_mail.erb
172
+ - test/fixtures/sinatra_app/views/mailers/sample/anniversary.erb
173
+ - test/fixtures/sinatra_app/views/mailers/sample/birthday.erb
174
+ - test/fixtures/sinatra_app/views/mailers/sample/foo_message.erb
175
+ - test/fixtures/views/mailers/alternate/foo.erb
176
+ - test/fixtures/views/mailers/bar.erb
177
+ - test/fixtures/views/mailers/i18n/hello.en.erb
178
+ - test/fixtures/views/mailers/i18n/hello.it.erb
179
+ - test/fixtures/views/mailers/layouts/sample.erb
180
+ - test/fixtures/views/mailers/multipart/basic.html.erb
181
+ - test/fixtures/views/mailers/multipart/basic.plain.erb
182
+ - test/fixtures/views/mailers/sample/foo.erb
144
183
  - test/helper.rb
145
- - test/test_base.rb
146
- - test/test_mail_object.rb
184
+ - test/test_email.rb
185
+ - test/test_message.rb
147
186
  - test/test_padrino_mailer.rb
187
+ - test/test_part.rb
148
188
  has_rdoc: true
149
189
  homepage: http://github.com/padrino/padrino-framework/tree/master/padrino-mailer
150
190
  licenses: []
@@ -155,6 +195,7 @@ rdoc_options:
155
195
  require_paths:
156
196
  - lib
157
197
  required_ruby_version: !ruby/object:Gem::Requirement
198
+ none: false
158
199
  requirements:
159
200
  - - ">="
160
201
  - !ruby/object:Gem::Version
@@ -162,16 +203,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
203
  - 0
163
204
  version: "0"
164
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
165
207
  requirements:
166
208
  - - ">="
167
209
  - !ruby/object:Gem::Version
168
210
  segments:
169
- - 0
170
- version: "0"
211
+ - 1
212
+ - 3
213
+ - 6
214
+ version: 1.3.6
171
215
  requirements: []
172
216
 
173
217
  rubyforge_project: padrino-mailer
174
- rubygems_version: 1.3.6
218
+ rubygems_version: 1.3.7
175
219
  signing_key:
176
220
  specification_version: 3
177
221
  summary: Mailer system for padrino
@@ -1,110 +0,0 @@
1
- require 'rubygems'
2
- require 'net/smtp'
3
- begin
4
- require 'smtp_tls'
5
- rescue LoadError
6
- end
7
- require 'base64'
8
- require 'tmail'
9
-
10
- module Padrino
11
- module Mailer
12
- module Delivery
13
-
14
- class << self
15
-
16
- def mail(options)
17
- raise(ArgumentError, ":to is required") unless options[:to]
18
- via = options.delete(:via)
19
- if via.nil?
20
- transport build_tmail(options)
21
- else
22
- if via_options.include?(via.to_s)
23
- send("transport_via_#{via}", build_tmail(options), options)
24
- else
25
- raise(ArgumentError, ":via must be either smtp or sendmail")
26
- end
27
- end
28
- end
29
-
30
- def build_tmail(options)
31
- mail = TMail::Mail.new
32
- mail.to = options[:to]
33
- mail.cc = options[:cc] || ''
34
- mail.bcc = options[:bcc] || ''
35
- mail.from = options[:from] || 'padrino@unknown'
36
- mail.reply_to = options[:reply_to]
37
- mail.subject = options[:subject]
38
-
39
- if options[:attachments]
40
- # If message has attachment, then body must be sent as a message part
41
- # or it will not be interpreted correctly by client.
42
- body = TMail::Mail.new
43
- body.body = options[:body] || ""
44
- body.content_type = options[:content_type] || "text/plain"
45
- mail.parts.push body
46
- (options[:attachments] || []).each do |name, body|
47
- attachment = TMail::Mail.new
48
- attachment.transfer_encoding = "base64"
49
- attachment.body = Base64.encode64(body)
50
- content_type = MIME::Types.type_for(name).to_s
51
- attachment.content_type = content_type unless content_type == ""
52
- attachment.set_content_disposition "attachment", "filename" => name
53
- mail.parts.push attachment
54
- end
55
- else
56
- mail.content_type = options[:content_type] || "text/plain"
57
- mail.body = options[:body] || ""
58
- end
59
- mail.charset = options[:charset] || "UTF-8" # charset must be set after setting content_type
60
- mail
61
- end
62
-
63
- def sendmail_binary
64
- @sendmail_binary ||= `which sendmail`.chomp
65
- end
66
-
67
- def transport(tmail)
68
- if File.executable? sendmail_binary
69
- transport_via_sendmail(tmail)
70
- else
71
- transport_via_smtp(tmail)
72
- end
73
- end
74
-
75
- def via_options
76
- %w(sendmail smtp)
77
- end
78
-
79
- def transport_via_sendmail(tmail, options={})
80
- logger.debug "Sending email via sendmail:\n#{tmail}" if Kernel.respond_to?(:logger)
81
- IO.popen('-', 'w+') do |pipe|
82
- if pipe
83
- pipe.write(tmail.to_s)
84
- else
85
- exec(sendmail_binary, *tmail.to)
86
- end
87
- end
88
- end
89
-
90
- def transport_via_smtp(tmail, options={:smtp => {}})
91
- logger.debug "Sending email via smtp:\n#{tmail}" if Kernel.respond_to?(:logger)
92
- o = { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }
93
- o.merge!(options[:smtp]) if options[:smtp].is_a?(Hash)
94
- smtp = Net::SMTP.new(o[:host], o[:port])
95
- if o[:tls]
96
- raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
97
- smtp.enable_starttls
98
- end
99
- if o.include?(:auth)
100
- smtp.start(o[:domain], o[:user], o[:pass] || o[:password], o[:auth])
101
- else
102
- smtp.start(o[:domain])
103
- end
104
- smtp.send_message tmail.to_s, tmail.from, tmail.to
105
- smtp.finish
106
- end
107
- end
108
- end # Delivery
109
- end # Mailer
110
- end # Padrino