class RMail::Message

Public Class Methods

make_attachment(payload, mime_type, encoding, filename) click to toggle source
# File lib/sup/util.rb, line 89
def self.make_attachment payload, mime_type, encoding, filename
  a = Message.new
  a.header.add "Content-Disposition", "attachment; filename=#{filename.inspect}"
  a.header.add "Content-Type", "#{mime_type}; name=#{filename.inspect}"
  a.header.add "Content-Transfer-Encoding", encoding if encoding
  a.body =
    case encoding
    when "base64"
      [payload].pack "m"
    when "quoted-printable"
      [payload].pack "M"
    when "7bit", "8bit", nil
      payload
    else
      raise EncodingUnsupportedError, encoding.inspect
    end
  a
end
make_file_attachment(fn) click to toggle source
# File lib/sup/util.rb, line 77
def self.make_file_attachment fn
  bfn = File.basename fn
  t = MIME::Types.type_for(bfn).first || MIME::Types.type_for("exe").first
  make_attachment IO.read(fn), t.content_type, t.encoding, bfn.to_s
end

Public Instance Methods

charset() click to toggle source
# File lib/sup/util.rb, line 83
def charset
  if header.field?("content-type") && header.fetch("content-type") =~ /charset\s*=\s*"?(.*?)"?(;|$)/i
    $1
  end
end