def unquote_and_convert_to(text, to_charset, from_charset = "iso-8859-1", preserve_underscores=false)
return "" if text.nil?
if text =~ /^=\?(.*?)\?(.)\?(.*)\?=$/
from_charset = $1
quoting_method = $2
text = $3
case quoting_method.upcase
when "Q" then
unquote_quoted_printable_and_convert_to(text, to_charset, from_charset, preserve_underscores)
when "B" then
unquote_base64_and_convert_to(text, to_charset, from_charset)
else
raise "unknown quoting method #{quoting_method.inspect}"
end
else
convert_to(text, to_charset, from_charset)
end
end