diff options
author | Jamis Buck <jamis@37signals.com> | 2006-09-09 21:14:43 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-09-09 21:14:43 +0000 |
commit | 4d9ca4d9fbed86936b6a2cee792ea8509eef81b2 (patch) | |
tree | 261410c00df8de487b3fa3916a8f93720ad85df0 /actionmailer/lib/action_mailer/vendor | |
parent | 3e7aa0391fb0da5ea6c38ceb682c8634d3a1cb72 (diff) | |
download | rails-4d9ca4d9fbed86936b6a2cee792ea8509eef81b2.tar.gz rails-4d9ca4d9fbed86936b6a2cee792ea8509eef81b2.tar.bz2 rails-4d9ca4d9fbed86936b6a2cee792ea8509eef81b2.zip |
Make sure quoted-printable text is decoded correctly when only portions of the text are encoded. closes #3154.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5080 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer/vendor')
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail/quoting.rb | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb index 8fbb6e55de..694242349d 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb @@ -49,20 +49,25 @@ module TMail class << self def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores=false) return "" if text.nil? - if text =~ /^=\?(.*?)\?(.)\?(.*)\?=$/ - from_charset = $1 - quoting_method = $2 - text = $3 - case quoting_method.upcase - when "Q" then - unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores) - when "B" then - unquote_base64_and_convert_to(text, to_charset, from_charset) - else - raise "unknown quoting method #{quoting_method.inspect}" - end - else - convert_to(text, to_charset, from_charset) + text.gsub(/(.*?)(?:(?:=\?(.*?)\?(.)\?(.*?)\?=)|$)/) do + before = $1 + from_charset = $2 + quoting_method = $3 + text = $4 + + before = convert_to(before, to_charset, from_charset) if before.length > 0 + before + case quoting_method + when "q", "Q" then + unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores) + when "b", "B" then + unquote_base64_and_convert_to(text, to_charset, from_charset) + when nil then + # will be nil at the end of the string, due to the nature of + # the regex used. + "" + else + raise "unknown quoting method #{quoting_method.inspect}" + end end end |