sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 385c5e85852e1a2c81ce3672e90fa1d021f7bd3f
parent e8e365f1820a714b3ebb6e08ed0ee3bd3625d2cc
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Tue,  8 Jan 2008 10:42:58 -0800

bugfix: attachment tempfile deletion

attachment temp files (used for Attachment#view!) now use (a
monkey-patched) Tempfile, so they should be deleted upon program exit or
gc or however it works.

Diffstat:
M lib/sup/message-chunks.rb | 18 ++++++++++--------
M lib/sup/message.rb | 1 -
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -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
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -1,4 +1,3 @@
-require 'tempfile'
 require 'time'
 require 'iconv'