class EncodingUnsupportedError < StandardError; end
class Message
- def add_attachment fn
+ def add_file_attachment fn
bfn = File.basename fn
a = Message.new
t = MIME::Types.type_for(bfn).first || MIME::Types.type_for("exe").first
- a.header.add "Content-Disposition", "attachment; filename=#{bfn}"
- a.header.add "Content-Type", "#{t.content_type}; name=#{bfn}"
+ a.header.add "Content-Disposition", "attachment; filename=#{bfn.to_s.inspect}"
+ a.header.add "Content-Type", "#{t.content_type}; name=#{bfn.to_s.inspect}"
a.header.add "Content-Transfer-Encoding", t.encoding
a.body =
case t.encoding
add_part a
end
+
+ def charset
+ if header.field?("content-type") && header.fetch("content-type") =~ /charset="?(.*?)"?(;|$)/
+ $1
+ end
+ end
end
end