diff options
author | Jamis Buck <jamis@37signals.com> | 2005-06-03 10:57:06 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-06-03 10:57:06 +0000 |
commit | 100fd7269990d5ecb6dc0f9731cce6714d5ebf76 (patch) | |
tree | 482db8a714fbff36ded3c98547c544a41bdd10cf /actionmailer | |
parent | 887497b0bb8725018837ddce162363c5f0e3f0b9 (diff) | |
download | rails-100fd7269990d5ecb6dc0f9731cce6714d5ebf76.tar.gz rails-100fd7269990d5ecb6dc0f9731cce6714d5ebf76.tar.bz2 rails-100fd7269990d5ecb6dc0f9731cce6714d5ebf76.zip |
Added a "content_type" accessor to allow messages to explicitly specify a content-type other than "text/plain" (the default).
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1382 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 10 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 4 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 13 |
4 files changed, 24 insertions, 5 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index b884272feb..7eeed73fc7 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added 'content_type' accessor, to allow content type to be set on a per-message basis. content_type defaults to "text/plain". + * Silently ignore Iconv::IllegalSequence errors when converting text #1341 [lon@speedymac.com] * Support attachments and multipart messages. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 15f08caf40..59ee47a137 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -138,8 +138,11 @@ module ActionMailer #:nodoc: @@default_charset = "utf-8" cattr_accessor :default_charset + @@default_content_type = "text/plain" + cattr_accessor :default_content_type + adv_attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers, - :bcc, :cc, :charset + :bcc, :cc, :charset, :content_type attr_reader :mail @@ -156,6 +159,7 @@ module ActionMailer #:nodoc: def create!(method_name, *parameters) @bcc = @cc = @from = @recipients = @sent_on = @subject = nil @charset = @@default_charset.dup + @content_type = @@default_content_type.dup @parts = [] @headers = {} @body = {} @@ -255,13 +259,13 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } if @parts.empty? - m.set_content_type "text", "plain", { "charset" => charset } + m.set_content_type content_type, nil, { "charset" => charset } m.body = body else if String === body part = TMail::Mail.new part.body = body - part.set_content_type "text", "plain", { "charset" => charset } + part.set_content_type content_type, nil, { "charset" => charset } part.set_content_disposition "inline" m.parts << part end diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 9f95df0a16..cb3a3dc053 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -9,7 +9,7 @@ module ActionMailer adv_attr_accessor :filename, :transfer_encoding, :headers def initialize(params) - @content_type = params[:content_type] || "text/plain" + @content_type = params[:content_type] @content_disposition = params[:disposition] || "inline" @charset = params[:charset] @body = params[:body] @@ -20,7 +20,7 @@ module ActionMailer def to_mail(defaults) part = TMail::Mail.new - part.set_content_type(content_type, nil, + part.set_content_type(content_type || defaults.content_type, nil, "charset" => (content_disposition == "attachment" ? nil : (charset || defaults.charset)), "name" => filename) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 96f80773b3..8116d41ca5 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -98,6 +98,14 @@ class TestMailer < ActionMailer::Base @body = { "recipient" => recipient } end + def html_mail(recipient) + recipients recipient + subject "html mail" + from "test@example.com" + body "<em>Emphasize</em> <strong>this</strong>" + content_type "text/html" + end + class <<self attr_accessor :received_body end @@ -454,5 +462,10 @@ EOF assert_equal "text/plain", mail.parts[1].content_type end + def test_html_mail + mail = TestMailer.create_html_mail(@recipient) + assert_equal "text/html", mail.content_type + end + end |