class Mail::Encodings::TransferEncoding

def self.lowest_cost(str, encodings)

def self.lowest_cost(str, encodings)
  best = nil
  best_cost = nil
  encodings.each do |enc|
    # If the current choice cannot be transported safely, give priority
    # to other choices but allow it to be used as a fallback.
    this_cost = enc.cost(str) if enc.compatible_input?(str)
    if !best_cost || (this_cost && this_cost < best_cost)
      best_cost = this_cost
      best = enc
    elsif this_cost == best_cost
      best = enc if enc::PRIORITY < best::PRIORITY
    end
  end
  best
end