]> git.cworth.org Git - sup/blobdiff - lib/sup/message-chunks.rb
bugfix: attachment tempfile deletion
[sup] / lib / sup / message-chunks.rb
index fbd193ccd033b6debc72ef319fea14141e62f5db..7d097404a1daae8b842a6e7fbb5ccde42802e4ad 100644 (file)
@@ -1,4 +1,4 @@
-require 'tmpdir'
+require 'tempfile'
 
 ## Here we define all the "chunks" that a message is parsed
 ## into. Chunks are used by ThreadViewMode to render a message. Chunks
@@ -31,6 +31,14 @@ require 'tmpdir'
 ## included as quoted text during a reply. Text, Quotes, and mime-parsed
 ## attachments are quotable; Signatures are not.
 
+## monkey-patch time: make temp files have the right extension
+class Tempfile
+  def make_tmpname basename, n
+    sprintf '%d-%d-%s', $$, n, basename
+  end
+end
+
+
 module Redwood
 module Chunk
   class Attachment
@@ -103,13 +111,7 @@ EOS
     end
 
     def write_to_disk
-      file =
-        if @filename
-          File.open File.join(Dir::tmpdir, @filename), "w"
-        else
-          Tempfile.new "redwood.attachment"
-        end
-
+      file = Tempfile.new(@filename || "sup-attachment")
       file.print @raw_content
       file.close
       file.path