def Ruby19.q_value_decode(str)
match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
charset = match[1]
string = match[2].gsub(/_/, '=20')
string = string.sub(/\=$/, '')
str = Encodings::QuotedPrintable.decode(string)
str.force_encoding(pick_encoding(charset))
str.force_encoding('utf-8') if str.encoding == Encoding::ASCII_8BIT
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