lib/sup/message-chunks.rb in sup-0.11 vs lib/sup/message-chunks.rb in sup-0.12

- old
+ new

@@ -30,13 +30,29 @@ ## Independent of all that, a chunk can be quotable, in which case it's ## 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 +## 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 module Redwood @@ -147,10 +163,10 @@ :filename => path ret || view_default!(path) end def write_to_disk - file = Tempfile.new(@filename || "sup-attachment") + file = Tempfile.new(["sup", @filename.gsub("/", "_") || "sup-attachment"]) file.print @raw_content file.close file.path end