diff options
author | Jamis Buck <jamis@37signals.com> | 2005-09-01 14:26:13 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-09-01 14:26:13 +0000 |
commit | ca410998abb8ed14bdc5edf0734eb8f83bf12317 (patch) | |
tree | 1cb45d607e4cdfa5f5ee2fa7d1050dea795f7143 /actionmailer/lib/action_mailer | |
parent | 2fed808ee4d572da5d86cb91c704e569589bd7cc (diff) | |
download | rails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.tar.gz rails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.tar.bz2 rails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.zip |
Encode multibyte characters correctly #1894
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2088 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/quoting.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/actionmailer/lib/action_mailer/quoting.rb b/actionmailer/lib/action_mailer/quoting.rb index af4e8462a1..d6e04e4d83 100644 --- a/actionmailer/lib/action_mailer/quoting.rb +++ b/actionmailer/lib/action_mailer/quoting.rb @@ -3,10 +3,19 @@ module ActionMailer # Convert the given text into quoted printable format, with an instruction # that the text be eventually interpreted in the given charset. def quoted_printable(text, charset) - text = text.gsub( /[^a-z ]/i ) { "=%02x" % $&[0] }.gsub( / /, "_" ) + text = text.gsub( /[^a-z ]/i ) { quoted_printable_encode($&) }. + gsub( / /, "_" ) "=?#{charset}?Q?#{text}?=" end + # Convert the given character to quoted printable format, taking into + # account multi-byte characters (if executing with $KCODE="u", for instance) + def quoted_printable_encode(character) + result = "" + character.each_byte { |b| result << "=%02x" % b } + result + end + # A quick-and-dirty regexp for determining whether a string contains any # characters that need escaping. if !defined?(CHARS_NEEDING_QUOTING) |