commit 60573298a2258c101a85b3de8121f73d7aec2d51
parent 07f0be019f60901594b6a1c0e0d042bea52367d7
Author: Michael Hamann <michael@content-space.de>
Date: Fri, 8 Oct 2010 10:03:36 -0400
Fix monkey-patching of Tempfile
In Ruby 1.9.2 the interal function make_tmpname has changed it's
parameters and the second parameter can be nil now. This breaks the
monkey-patched Tempfile class in sup. Additionally, monkey-patching is
not really necessary as the Tempfile class supports an array as basename
instead of a string containing prefix and a suffix since Ruby version
1.8.7. The only place I've found where the suffix might matter is
directly in message-chunks.rb where I've changed the basename to an
array. Additionally the new make_tmpname function from Ruby 1.9.2 is
monkey-patched for Ruby versions lower than 1.8.7 now.
NOTE: As I don't have a working Ruby 1.8 setup for sup I haven't tested
this with older versions, but the code works here when the version check
is changed to 1.9.3 and I can't see anything that shouldn't work with
Ruby 1.8.6 and below.
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