commit 1bafcf6c8f710c3625260e425b899cebb7247c3d
parent bf9690c64c9fde0c1da930e53d520579369938a8
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Tue, 12 Oct 2010 23:30:01 -0700
Merge branch 'master' into next
Diffstat:
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -32,9 +32,25 @@ require 'tempfile'
## 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
+## Backport from Ruby 1.9.2 for versions lower than 1.8.7
+if RUBY_VERSION < '1.8.7'
+ class Tempfile
+ def make_tmpname(prefix_suffix, n)
+ case prefix_suffix
+ when String
+ prefix = prefix_suffix
+ suffix = ""
+ when Array
+ prefix = prefix_suffix[0]
+ suffix = prefix_suffix[1]
+ else
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
+ end
+ t = Time.now.strftime("%Y%m%d")
+ path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
+ path << "-#{n}" if n
+ path << suffix
+ end
end
end
@@ -149,7 +165,7 @@ EOS
end
def write_to_disk
- file = Tempfile.new(@filename || "sup-attachment")
+ file = Tempfile.new(["sup", @filename || "sup-attachment"])
file.print @raw_content
file.close
file.path