aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-19 21:51:16 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-19 21:51:16 +0000
commit3fad0cd06c2ff828dd9bb0bb18080572ee992f4f (patch)
tree30533e27412fc18074fcea15fe7577ff9e271baf /actionmailer/lib/action_mailer/base.rb
parent7d3d83e7b4996fa161ba4f276ca65edf3902c1a2 (diff)
downloadrails-3fad0cd06c2ff828dd9bb0bb18080572ee992f4f.tar.gz
rails-3fad0cd06c2ff828dd9bb0bb18080572ee992f4f.tar.bz2
rails-3fad0cd06c2ff828dd9bb0bb18080572ee992f4f.zip
Added support for charsets for both subject and body. The default charset is now UTF-8 #673 [Jamis Buck]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@699 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r--actionmailer/lib/action_mailer/base.rb35
1 files changed, 29 insertions, 6 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 61701d62b7..8b04c42ee0 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -83,10 +83,18 @@ module ActionMailer #:nodoc:
@@deliveries = []
cattr_accessor :deliveries
- attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers, :bcc, :cc
+ @@default_charset = "utf-8"
+ cattr_accessor :default_charset
+
+ @@encode_subject = true
+ cattr_accessor :encode_subject
+
+ attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers, :bcc, :cc, :charset, :encode_subject
def initialize
@bcc = @cc = @from = @recipients = @sent_on = @subject = @body = nil
+ @charset = @@default_charset.dup
+ @encode_subject = @@encode_subject
@headers = {}
end
@@ -104,14 +112,22 @@ module ActionMailer #:nodoc:
end
end
- def mail(to, subject, body, from, timestamp = nil, headers = nil) #:nodoc:
- deliver(create(to, subject, body, from, timestamp, headers))
+ def mail(to, subject, body, from, timestamp = nil, headers = {},
+ encode = @@encode_subject, charset = @@default_charset
+ ) #:nodoc:
+ deliver(create(to, subject, body, from, timestamp, headers, charset))
end
- def create(to, subject, body, from, timestamp = nil, headers = nil) #:nodoc:
+ def create(to, subject, body, from, timestamp = nil, headers = {},
+ encode = @@encode_subject, charset = @@default_charset
+ ) #:nodoc:
m = TMail::Mail.new
- m.to, m.subject, m.body, m.from = to, subject, body, from
+ m.to, m.subject, m.body, m.from = to,
+ ( encode ? quoted_printable(subject,charset) : subject ), body, from
m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
+
+ m.set_content_type "text", "plain", { "charset" => charset }
+
headers.each do |k, v|
m[k] = v
end
@@ -124,6 +140,12 @@ module ActionMailer #:nodoc:
send("perform_delivery_#{delivery_method}", mail) if perform_deliveries
end
+ def quoted_printable( text, charset )
+ text = text.gsub( /[^a-z ]/i ) { "=%02x" % $&[0] }.
+ gsub( / /, "_" )
+ "=?#{charset}?Q?#{text}?="
+ end
+
private
def perform_delivery_smtp(mail)
Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
@@ -153,7 +175,8 @@ module ActionMailer #:nodoc:
end
mail = create(mailer.recipients, mailer.subject, mailer.body,
- mailer.from, mailer.sent_on, mailer.headers)
+ mailer.from, mailer.sent_on, mailer.headers,
+ mailer.encode_subject, mailer.charset)
mail.bcc = mailer.bcc unless mailer.bcc.nil?
mail.cc = mailer.cc unless mailer.cc.nil?