diff options
author | Jamis Buck <jamis@37signals.com> | 2005-06-03 09:05:06 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-06-03 09:05:06 +0000 |
commit | 887497b0bb8725018837ddce162363c5f0e3f0b9 (patch) | |
tree | 7e06300ef938d98b0139932ac140d320c899dac4 | |
parent | 32c0e895bfa521acdc5c7031a2285a3b8dd53130 (diff) | |
download | rails-887497b0bb8725018837ddce162363c5f0e3f0b9.tar.gz rails-887497b0bb8725018837ddce162363c5f0e3f0b9.tar.bz2 rails-887497b0bb8725018837ddce162363c5f0e3f0b9.zip |
Don't apply a charset to attachments. Wrap base64-encoded lines.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1381 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 48 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 2 |
2 files changed, 6 insertions, 44 deletions
diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index e26742816a..9f95df0a16 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -21,56 +21,16 @@ module ActionMailer def to_mail(defaults) part = TMail::Mail.new part.set_content_type(content_type, nil, - "charset" => charset || defaults.charset, "name" => filename) + "charset" => (content_disposition == "attachment" ? + nil : (charset || defaults.charset)), + "name" => filename) part.set_content_disposition(content_disposition, "filename" => filename) part.content_transfer_encoding = transfer_encoding || "quoted-printable" case (transfer_encoding || "").downcase when "base64" then - part.body = TMail::Base64.encode(body) - when "quoted-printable" - part.body = [body].pack("M*") - else - part.body = body - end - - part - end - end - -end -require 'action_mailer/adv_attr_accessor' - -module ActionMailer - - class Part #:nodoc: - include ActionMailer::AdvAttrAccessor - - adv_attr_accessor :content_type, :content_disposition, :charset, :body - adv_attr_accessor :filename, :transfer_encoding, :headers - - def initialize(params) - @content_type = params[:content_type] || "text/plain" - @content_disposition = params[:disposition] || "inline" - @charset = params[:charset] - @body = params[:body] - @filename = params[:filename] - @transfer_encoding = params[:transfer_encoding] || "quoted-printable" - @headers = params[:headers] || {} - end - - def to_mail(defaults) - part = TMail::Mail.new - part.set_content_type(content_type, nil, - "charset" => charset || defaults.charset, "name" => filename) - part.set_content_disposition(content_disposition, - "filename" => filename) - - part.content_transfer_encoding = transfer_encoding || "quoted-printable" - case (transfer_encoding || "").downcase - when "base64" then - part.body = TMail::Base64.encode(body) + part.body = TMail::Base64.folding_encode(body) when "quoted-printable" part.body = [body].pack("M*") else diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index d715b88b10..96f80773b3 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -437,12 +437,14 @@ EOF assert_equal "text/plain", mail.parts[0].content_type assert_equal "text/html", mail.parts[1].content_type + assert_equal "iso-8859-1", mail.parts[1].sub_header("content-type", "charset") assert_equal "inline", mail.parts[1].content_disposition assert_equal "image/jpeg", mail.parts[2].content_type assert_equal "attachment", mail.parts[2].content_disposition assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename") assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name") + assert_nil mail.parts[2].sub_header("content-type", "charset") end def test_implicitly_multipart_messages |