module TMail
class Unquoter
class << self
def convert_to(text, to, from)
return text unless to && from
from.gsub!(‘ISO88′,’ISO-88’) #we found some strange cases in which the encoding was lacking the dash
from.gsub!(‘ks_c_5601-1987′,’euc-kr’) # ks_c_5601-1987 and euc-kr are different encodings and the second one is the referred one for e-mails #http://lists.kde.org/?l=kde-i18n-doc&m=100396886120761&w=2
text ? Iconv.conv(“#{to}//IGNORE//TRANSLIT”, from, text) : ” #the encoding is done with ignore and translit to fix as much errors as possible
rescue Iconv::IllegalSequence, Errno::EINVAL
# the ‘from’ parameter specifies a charset other than what the text
# actually is…not much we can do in this case but just return the
# unconverted text
#
# Ditto if either parameter represents an unknown charset (i.e X-UNKNOWN),
# and if the //IGNORE didn’t work fine
text
end
end
end
end