Skip to content

Instantly share code, notes, and snippets.

@yuanying
Created December 15, 2010 07:24
Show Gist options
  • Save yuanying/741734 to your computer and use it in GitHub Desktop.
Save yuanying/741734 to your computer and use it in GitHub Desktop.
ちゃんとエンコード情報を利用してデコードしてやるように修正。
module Mail
require 'iconv'
class Ruby18
def Ruby18.b_value_decode(str)
match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Ruby18.decode_base64(match[2])
str = Ruby18.force_encode_to_default str, encoding
end
str
end
def Ruby18.q_value_decode(str)
match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Encodings::QuotedPrintable.decode(match[2])
str = Ruby18.force_encode_to_default str, encoding
end
str
end
def Ruby18.force_encode_to_default str, encoding
encode = $KCODE == 'NONE' ? 'UTF8' : $KCODE
Iconv.new(encode, encoding).iconv(str)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment