actionmailer 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionmailer might be problematic. Click here for more details.
- data/CHANGELOG +22 -0
- data/lib/action_mailer.rb +6 -3
- data/lib/action_mailer/base.rb +34 -7
- data/rakefile +3 -3
- data/test/mail_service_test.rb +90 -6
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
*0.7.0* (24th February, 2005)
|
2
|
+
|
3
|
+
* Added support for charsets for both subject and body. The default charset is now UTF-8 #673 [Jamis Buck]. Examples:
|
4
|
+
|
5
|
+
def iso_charset(recipient)
|
6
|
+
@recipients = recipient
|
7
|
+
@subject = "testing iso charsets"
|
8
|
+
@from = "system@loudthinking.com"
|
9
|
+
@body = "Nothing to see here."
|
10
|
+
@charset = "iso-8859-1"
|
11
|
+
end
|
12
|
+
|
13
|
+
def unencoded_subject(recipient)
|
14
|
+
@recipients = recipient
|
15
|
+
@subject = "testing unencoded subject"
|
16
|
+
@from = "system@loudthinking.com"
|
17
|
+
@body = "Nothing to see here."
|
18
|
+
@encode_subject = false
|
19
|
+
@charset = "iso-8859-1"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
1
23
|
*0.6.1* (January 18th, 2005)
|
2
24
|
|
3
25
|
* Fixed sending of emails to use Tmail#from not the deprecated Tmail#from_address
|
data/lib/action_mailer.rb
CHANGED
@@ -24,9 +24,12 @@
|
|
24
24
|
begin
|
25
25
|
require 'action_controller'
|
26
26
|
rescue LoadError
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
begin
|
28
|
+
require File.dirname(__FILE__) + '/../../actionpack/lib/action_controller'
|
29
|
+
rescue LoadError
|
30
|
+
require 'rubygems'
|
31
|
+
require_gem 'actionpack', '>= 0.9.0'
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
$:.unshift(File.dirname(__FILE__) + "/action_mailer/vendor/")
|
data/lib/action_mailer/base.rb
CHANGED
@@ -55,6 +55,11 @@ module ActionMailer #:nodoc:
|
|
55
55
|
#
|
56
56
|
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful
|
57
57
|
# for unit and functional testing.
|
58
|
+
#
|
59
|
+
# * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
|
60
|
+
# pick a different charset from inside a method with <tt>@encoding</tt>.
|
61
|
+
#
|
62
|
+
# * <tt>encode_subject</tt> - Whether or not to encode the subject with the active charset. Defaults to true.
|
58
63
|
class Base
|
59
64
|
private_class_method :new #:nodoc:
|
60
65
|
|
@@ -83,10 +88,18 @@ module ActionMailer #:nodoc:
|
|
83
88
|
@@deliveries = []
|
84
89
|
cattr_accessor :deliveries
|
85
90
|
|
86
|
-
|
91
|
+
@@default_charset = "utf-8"
|
92
|
+
cattr_accessor :default_charset
|
93
|
+
|
94
|
+
@@encode_subject = true
|
95
|
+
cattr_accessor :encode_subject
|
96
|
+
|
97
|
+
attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers, :bcc, :cc, :charset, :encode_subject
|
87
98
|
|
88
99
|
def initialize
|
89
100
|
@bcc = @cc = @from = @recipients = @sent_on = @subject = @body = nil
|
101
|
+
@charset = @@default_charset.dup
|
102
|
+
@encode_subject = @@encode_subject
|
90
103
|
@headers = {}
|
91
104
|
end
|
92
105
|
|
@@ -104,14 +117,22 @@ module ActionMailer #:nodoc:
|
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
107
|
-
def mail(to, subject, body, from, timestamp = nil, headers =
|
108
|
-
|
120
|
+
def mail(to, subject, body, from, timestamp = nil, headers = {},
|
121
|
+
encode = @@encode_subject, charset = @@default_charset
|
122
|
+
) #:nodoc:
|
123
|
+
deliver(create(to, subject, body, from, timestamp, headers, charset))
|
109
124
|
end
|
110
125
|
|
111
|
-
def create(to, subject, body, from, timestamp = nil, headers =
|
126
|
+
def create(to, subject, body, from, timestamp = nil, headers = {},
|
127
|
+
encode = @@encode_subject, charset = @@default_charset
|
128
|
+
) #:nodoc:
|
112
129
|
m = TMail::Mail.new
|
113
|
-
m.to, m.subject, m.body, m.from = to,
|
130
|
+
m.to, m.subject, m.body, m.from = to,
|
131
|
+
( encode ? quoted_printable(subject,charset) : subject ), body, from
|
114
132
|
m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
|
133
|
+
|
134
|
+
m.set_content_type "text", "plain", { "charset" => charset }
|
135
|
+
|
115
136
|
headers.each do |k, v|
|
116
137
|
m[k] = v
|
117
138
|
end
|
@@ -124,7 +145,12 @@ module ActionMailer #:nodoc:
|
|
124
145
|
send("perform_delivery_#{delivery_method}", mail) if perform_deliveries
|
125
146
|
end
|
126
147
|
|
127
|
-
|
148
|
+
def quoted_printable(text, charset)#:nodoc:
|
149
|
+
text = text.gsub( /[^a-z ]/i ) { "=%02x" % $&[0] }.gsub( / /, "_" )
|
150
|
+
"=?#{charset}?Q?#{text}?="
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
128
154
|
def perform_delivery_smtp(mail)
|
129
155
|
Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
|
130
156
|
server_settings[:user_name], server_settings[:password], server_settings[:authentication]) do |smtp|
|
@@ -153,7 +179,8 @@ module ActionMailer #:nodoc:
|
|
153
179
|
end
|
154
180
|
|
155
181
|
mail = create(mailer.recipients, mailer.subject, mailer.body,
|
156
|
-
mailer.from, mailer.sent_on, mailer.headers
|
182
|
+
mailer.from, mailer.sent_on, mailer.headers,
|
183
|
+
mailer.encode_subject, mailer.charset)
|
157
184
|
|
158
185
|
mail.bcc = mailer.bcc unless mailer.bcc.nil?
|
159
186
|
mail.cc = mailer.cc unless mailer.cc.nil?
|
data/rakefile
CHANGED
@@ -8,7 +8,7 @@ require 'rake/contrib/rubyforgepublisher'
|
|
8
8
|
|
9
9
|
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
10
10
|
PKG_NAME = 'actionmailer'
|
11
|
-
PKG_VERSION = '0.
|
11
|
+
PKG_VERSION = '0.7.0' + PKG_BUILD
|
12
12
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
13
13
|
|
14
14
|
desc "Default Task"
|
@@ -48,9 +48,9 @@ spec = Gem::Specification.new do |s|
|
|
48
48
|
s.author = "David Heinemeier Hansson"
|
49
49
|
s.email = "david@loudthinking.com"
|
50
50
|
s.rubyforge_project = "actionmailer"
|
51
|
-
s.homepage = "http://
|
51
|
+
s.homepage = "http://www.rubyonrails.org"
|
52
52
|
|
53
|
-
s.add_dependency('actionpack', '
|
53
|
+
s.add_dependency('actionpack', '= 1.5.0' + PKG_BUILD)
|
54
54
|
|
55
55
|
s.has_rdoc = true
|
56
56
|
s.requirements << 'none'
|
data/test/mail_service_test.rb
CHANGED
@@ -31,12 +31,46 @@ class TestMailer < ActionMailer::Base
|
|
31
31
|
@body = "Nothing to see here."
|
32
32
|
end
|
33
33
|
|
34
|
+
def iso_charset(recipient)
|
35
|
+
@recipients = recipient
|
36
|
+
@subject = "testing iso charsets"
|
37
|
+
@from = "system@loudthinking.com"
|
38
|
+
@sent_on = Time.local 2004, 12, 12
|
39
|
+
@cc = "nobody@loudthinking.com"
|
40
|
+
@bcc = "root@loudthinking.com"
|
41
|
+
@body = "Nothing to see here."
|
42
|
+
@charset = "iso-8859-1"
|
43
|
+
end
|
44
|
+
|
45
|
+
def unencoded_subject(recipient)
|
46
|
+
@recipients = recipient
|
47
|
+
@subject = "testing unencoded subject"
|
48
|
+
@from = "system@loudthinking.com"
|
49
|
+
@sent_on = Time.local 2004, 12, 12
|
50
|
+
@cc = "nobody@loudthinking.com"
|
51
|
+
@bcc = "root@loudthinking.com"
|
52
|
+
@body = "Nothing to see here."
|
53
|
+
@encode_subject = false
|
54
|
+
end
|
55
|
+
|
34
56
|
end
|
35
57
|
|
36
58
|
TestMailer.template_root = File.dirname(__FILE__) + "/fixtures"
|
37
59
|
|
38
60
|
class ActionMailerTest < Test::Unit::TestCase
|
39
61
|
|
62
|
+
def encode( text, charset="utf-8" )
|
63
|
+
ActionMailer::Base.quoted_printable( text, charset )
|
64
|
+
end
|
65
|
+
|
66
|
+
def new_mail( charset="utf-8" )
|
67
|
+
mail = TMail::Mail.new
|
68
|
+
if charset
|
69
|
+
mail.set_content_type "text", "plain", { "charset" => charset }
|
70
|
+
end
|
71
|
+
mail
|
72
|
+
end
|
73
|
+
|
40
74
|
def setup
|
41
75
|
ActionMailer::Base.delivery_method = :test
|
42
76
|
ActionMailer::Base.perform_deliveries = true
|
@@ -46,9 +80,9 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
46
80
|
end
|
47
81
|
|
48
82
|
def test_signed_up
|
49
|
-
expected =
|
83
|
+
expected = new_mail
|
50
84
|
expected.to = @recipient
|
51
|
-
expected.subject = "[Signed up] Welcome #{@recipient}"
|
85
|
+
expected.subject = encode "[Signed up] Welcome #{@recipient}"
|
52
86
|
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
53
87
|
expected.from = "system@loudthinking.com"
|
54
88
|
expected.date = Time.local(2004, 12, 12)
|
@@ -64,9 +98,9 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
64
98
|
end
|
65
99
|
|
66
100
|
def test_cancelled_account
|
67
|
-
expected =
|
101
|
+
expected = new_mail
|
68
102
|
expected.to = @recipient
|
69
|
-
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
103
|
+
expected.subject = encode "[Cancelled] Goodbye #{@recipient}"
|
70
104
|
expected.body = "Goodbye, Mr. #{@recipient}"
|
71
105
|
expected.from = "system@loudthinking.com"
|
72
106
|
expected.date = Time.local(2004, 12, 12)
|
@@ -82,9 +116,9 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
82
116
|
end
|
83
117
|
|
84
118
|
def test_cc_bcc
|
85
|
-
expected =
|
119
|
+
expected = new_mail
|
86
120
|
expected.to = @recipient
|
87
|
-
expected.subject = "testing bcc/cc"
|
121
|
+
expected.subject = encode "testing bcc/cc"
|
88
122
|
expected.body = "Nothing to see here."
|
89
123
|
expected.from = "system@loudthinking.com"
|
90
124
|
expected.cc = "nobody@loudthinking.com"
|
@@ -106,6 +140,56 @@ class ActionMailerTest < Test::Unit::TestCase
|
|
106
140
|
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
107
141
|
end
|
108
142
|
|
143
|
+
def test_iso_charset
|
144
|
+
expected = new_mail( "iso-8859-1" )
|
145
|
+
expected.to = @recipient
|
146
|
+
expected.subject = encode "testing iso charsets", "iso-8859-1"
|
147
|
+
expected.body = "Nothing to see here."
|
148
|
+
expected.from = "system@loudthinking.com"
|
149
|
+
expected.cc = "nobody@loudthinking.com"
|
150
|
+
expected.bcc = "root@loudthinking.com"
|
151
|
+
expected.date = Time.local 2004, 12, 12
|
152
|
+
|
153
|
+
created = nil
|
154
|
+
assert_nothing_raised do
|
155
|
+
created = TestMailer.create_iso_charset @recipient
|
156
|
+
end
|
157
|
+
assert_not_nil created
|
158
|
+
assert_equal expected.encoded, created.encoded
|
159
|
+
|
160
|
+
assert_nothing_raised do
|
161
|
+
TestMailer.deliver_iso_charset @recipient
|
162
|
+
end
|
163
|
+
|
164
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
165
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_unencoded_subject
|
169
|
+
expected = new_mail
|
170
|
+
expected.to = @recipient
|
171
|
+
expected.subject = "testing unencoded subject"
|
172
|
+
expected.body = "Nothing to see here."
|
173
|
+
expected.from = "system@loudthinking.com"
|
174
|
+
expected.cc = "nobody@loudthinking.com"
|
175
|
+
expected.bcc = "root@loudthinking.com"
|
176
|
+
expected.date = Time.local 2004, 12, 12
|
177
|
+
|
178
|
+
created = nil
|
179
|
+
assert_nothing_raised do
|
180
|
+
created = TestMailer.create_unencoded_subject @recipient
|
181
|
+
end
|
182
|
+
assert_not_nil created
|
183
|
+
assert_equal expected.encoded, created.encoded
|
184
|
+
|
185
|
+
assert_nothing_raised do
|
186
|
+
TestMailer.deliver_unencoded_subject @recipient
|
187
|
+
end
|
188
|
+
|
189
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
190
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
191
|
+
end
|
192
|
+
|
109
193
|
def test_instances_are_nil
|
110
194
|
assert_nil ActionMailer::Base.new
|
111
195
|
assert_nil TestMailer.new
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: actionmailer
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.7.0
|
7
|
+
date: 2005-02-24
|
8
8
|
summary: Service layer for easy email delivery and testing.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: david@loudthinking.com
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://www.rubyonrails.org
|
13
13
|
rubyforge_project: actionmailer
|
14
14
|
description: Makes it trivial to test and deliver emails sent from a single service layer.
|
15
15
|
autorequire: action_mailer
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
82
82
|
requirements:
|
83
83
|
-
|
84
|
-
- "
|
84
|
+
- "="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: 1.5.0
|
87
87
|
version:
|