]> git.cworth.org Git - sup/blobdiff - lib/sup/util.rb
alias ferret to index in index.rb for cuter console examples
[sup] / lib / sup / util.rb
index cf78dacd824de49a76730bed130204077b969535..c3d4ce6a18ba689aff73918c5e88b394abda9bc4 100644 (file)
@@ -63,13 +63,13 @@ module RMail
   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
@@ -85,6 +85,12 @@ module RMail
 
       add_part a
     end
+
+    def charset
+      if header.field?("content-type") && header.fetch("content-type") =~ /charset="?(.*?)"?(;|$)/
+        $1
+      end
+    end
   end
 end