def Ruby19.q_value_decode(str)
match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
encoding = match[1]
string = match[2].gsub(/_/, '=20')
string = string.sub(/\=$/, '')
str = Encodings::QuotedPrintable.decode(string)
str.force_encoding(fix_encoding(encoding))
end
decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
rescue Encoding::UndefinedConversionError
str.dup.force_encoding("utf-8")
end