class Mail::Utilities::BestEffortCharsetEncoder

def encode(string, charset)

def encode(string, charset)
  case charset
  when /utf-?7/i
    Mail::Utilities.decode_utf7(string)
  else
    string.force_encoding(pick_encoding(charset))
  end
end

def pick_encoding(charset)

def pick_encoding(charset)
  charset = case charset
  when /ansi_x3.110-1983/
    'ISO-8859-1'
  when /Windows-?1258/i # Windows-1258 is similar to 1252
    "Windows-1252"
  else
    charset
  end
  Mail::Utilities.pick_encoding(charset)
end