Permalink
Browse files

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
  • Loading branch information...
jamis committed Jun 3, 2005
1 parent 32c0e89 commit 887497b0bb8725018837ddce162363c5f0e3f0b9
Showing with 6 additions and 44 deletions.
  1. +4 −44 actionmailer/lib/action_mailer/part.rb
  2. +2 −0 actionmailer/test/mail_service_test.rb
@@ -21,56 +21,16 @@ def initialize(params)
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
@@ -437,12 +437,14 @@ def test_explicitly_multipart_messages
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

0 comments on commit 887497b

Please sign in to comment.