From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.204.20.129 with SMTP id f1cs185923bkb; Fri, 8 Oct 2010 07:16:33 -0700 (PDT) Received: by 10.142.158.6 with SMTP id g6mr2048323wfe.96.1286547391664; Fri, 08 Oct 2010 07:16:31 -0700 (PDT) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id v20si3847623ibi.83.2010.10.08.07.16.31; Fri, 08 Oct 2010 07:16:31 -0700 (PDT) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id BD4BD19782D9; Fri, 8 Oct 2010 10:16:30 -0400 (EDT) Received: from zucker.schokokeks.org (zucker.schokokeks.org [78.46.69.5]) by rubyforge.org (Postfix) with ESMTP id C146B1858381 for ; Fri, 8 Oct 2010 10:04:51 -0400 (EDT) Received: from localhost (dslb-092-074-246-250.pools.arcor-ip.net [::ffff:92.74.246.250]) (AUTH: PLAIN michael@content-space.de, TLS: TLSv1/SSLv3, 128bits, AES128-SHA) by zucker.schokokeks.org with esmtp; Fri, 08 Oct 2010 16:04:50 +0200 id 000000000001C016.000000004CAF2502.00003516 From: Michael Hamann To: sup-devel@rubyforge.org Date: Fri, 8 Oct 2010 16:03:36 +0200 Message-Id: <1286546616-7072-1-git-send-email-michael@content-space.de> X-Mailer: git-send-email 1.7.3.1 Subject: [sup-devel] [PATCH] Fix monkey-patching of Tempfile X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org 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. --- lib/sup/message-chunks.rb | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb index c275f41..ba1834a 100644 --- 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 -- 1.7.3.1 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel