diff options
author | Jamis Buck <jamis@37signals.com> | 2006-03-18 23:53:07 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-03-18 23:53:07 +0000 |
commit | db0e8ff1c3496841d7a307794dacecd82e55ce6a (patch) | |
tree | 0d266f44bcdc87d47ce149856c6e1c8198f8a9a5 /actionmailer/lib | |
parent | 9c9069a67595f620f80eabc475181cb36a26cdde (diff) | |
download | rails-db0e8ff1c3496841d7a307794dacecd82e55ce6a.tar.gz rails-db0e8ff1c3496841d7a307794dacecd82e55ce6a.tar.bz2 rails-db0e8ff1c3496841d7a307794dacecd82e55ce6a.zip |
Parse content-type apart before using it so that sub-parts of the header can be set correctly (closes #2918)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3959 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 8 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 19 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part_container.rb | 9 |
3 files changed, 25 insertions, 11 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 237e56ed0c..42d48fd5a6 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -413,14 +413,16 @@ module ActionMailer m.date = sent_on.to_time rescue sent_on if sent_on headers.each { |k, v| m[k] = v } + real_content_type, ctype_attrs = parse_content_type + if @parts.empty? - m.set_content_type content_type, nil, { "charset" => charset } + m.set_content_type(real_content_type, nil, ctype_attrs) m.body = Utils.normalize_new_lines(body) else if String === body part = TMail::Mail.new part.body = Utils.normalize_new_lines(body) - part.set_content_type content_type, nil, { "charset" => charset } + part.set_content_type(real_content_type, nil, ctype_attrs) part.set_content_disposition "inline" m.parts << part end @@ -430,7 +432,7 @@ module ActionMailer m.parts << part end - m.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/ + m.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ end @mail = m diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 7bdbf5345d..31f5b441e3 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -56,6 +56,8 @@ module ActionMailer def to_mail(defaults) part = TMail::Mail.new + real_content_type, ctype_attrs = parse_content_type(defaults) + if @parts.empty? part.content_transfer_encoding = transfer_encoding || "quoted-printable" case (transfer_encoding || "").downcase @@ -71,20 +73,20 @@ module ActionMailer # Also don't set filename and name when there is none (like in # non-attachment parts) if content_disposition == "attachment" - part.set_content_type(content_type || defaults.content_type, nil, - squish("charset" => nil, "name" => filename)) + ctype_attrs.delete "charset" + part.set_content_type(real_content_type, nil, + squish("name" => filename).merge(ctype_attrs)) part.set_content_disposition(content_disposition, - squish("filename" => filename)) + squish("filename" => filename).merge(ctype_attrs)) else - part.set_content_type(content_type || defaults.content_type, nil, - "charset" => (charset || defaults.charset)) + part.set_content_type(real_content_type, nil, ctype_attrs) part.set_content_disposition(content_disposition) end else if String === body part = TMail::Mail.new part.body = body - part.set_content_type content_type, nil, { "charset" => charset } + part.set_content_type(real_content_type, nil, ctype_attrs) part.set_content_disposition "inline" m.parts << part end @@ -94,15 +96,16 @@ module ActionMailer part.parts << prt end - part.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/ + part.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ end - @headers.each { |k,v| part[k] = v } + headers.each { |k,v| part[k] = v } part end private + def squish(values={}) values.delete_if { |k,v| v.nil? } end diff --git a/actionmailer/lib/action_mailer/part_container.rb b/actionmailer/lib/action_mailer/part_container.rb index 6199fe0b6e..3e3d6b9d4f 100644 --- a/actionmailer/lib/action_mailer/part_container.rb +++ b/actionmailer/lib/action_mailer/part_container.rb @@ -38,5 +38,14 @@ module ActionMailer part(params, &block) end + private + + def parse_content_type(defaults=nil) + return [defaults && defaults.content_type, {}] if content_type.blank? + ctype, *attrs = content_type.split(/;\s*/) + attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h } + [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)] + end + end end |