Created
December 15, 2010 07:24
-
-
Save yuanying/741734 to your computer and use it in GitHub Desktop.
ちゃんとエンコード情報を利用してデコードしてやるように修正。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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