# File lib/sup/util.rb, line 685
  def self.easy_decode target, orig_charset, text
    if text.respond_to? :force_encoding
      text = text.dup
      text.force_encoding Encoding::BINARY
    end
    charset = case orig_charset
      when /UTF[-_ ]?8/i then "utf-8"
      when /(iso[-_ ])?latin[-_ ]?1$/i then "ISO-8859-1"
      when /iso[-_ ]?8859[-_ ]?15/i then 'ISO-8859-15'
      when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i then "utf-7"
      when /^euc$/i then 'EUC-JP' # XXX try them all?
      when /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i then 'ASCII'
      else orig_charset
    end

    begin
      returning(Iconv.iconv(target, charset, text + " ").join[0 .. -2]) { |str| str.check }
    rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::InvalidCharacter, Iconv::IllegalSequence, String::CheckError
      debug "couldn't transcode text from #{orig_charset} (#{charset}) to #{target}) (#{text[0 ... 20].inspect}...) (got #{$!.message} (#{$!.class}))"
      text.ascii
    end
  end