From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.13.12 with SMTP id z12cs1223180ebz; Mon, 4 Jan 2010 11:45:53 -0800 (PST) Received: by 10.224.70.208 with SMTP id e16mr838616qaj.311.1262634352201; Mon, 04 Jan 2010 11:45:52 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 26si32140949qyk.4.2010.01.04.11.45.51; Mon, 04 Jan 2010 11:45:52 -0800 (PST) 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 A511F1779943; Mon, 4 Jan 2010 14:45:51 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 5A88818582CE for ; Mon, 4 Jan 2010 14:45:49 -0500 (EST) Received: (qmail 31465 invoked from network); 4 Jan 2010 19:45:46 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 4 Jan 2010 19:45:46 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Mon, 4 Jan 2010 11:45:42 -0800 Message-Id: <1262634342-7029-1-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 Subject: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9 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 --- lib/sup/maildir.rb | 4 ++-- lib/sup/mbox/loader.rb | 4 ++-- lib/sup/util.rb | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb index 0852576..b2c5847 100644 --- a/lib/sup/maildir.rb +++ b/lib/sup/maildir.rb @@ -59,7 +59,7 @@ class Maildir < Source File.stat(tmp_path) rescue Errno::ENOENT #this is what we want. begin - File.open(tmp_path, 'wb:BINARY') do |f| + File.open_binary(tmp_path, 'w') do |f| yield f #provide a writable interface for the caller f.fsync end @@ -207,7 +207,7 @@ private def with_file_for id fn = @ids_to_fns[id] or raise OutOfSyncSourceError, "No such id: #{id.inspect}." begin - File.open(fn, 'rb:BINARY') { |f| yield f } + File.open_binary(fn, 'r') { |f| yield f } rescue SystemCallError, IOError => e raise FatalSourceError, "Problem reading file for id #{id.inspect}: #{fn.inspect}: #{e.message}." end diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb index ec28d3b..557c13b 100644 --- a/lib/sup/mbox/loader.rb +++ b/lib/sup/mbox/loader.rb @@ -22,7 +22,7 @@ class Loader < Source raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox" raise ArgumentError, "mbox URI ('#{uri}') cannot have a host: #{uri.host}" if uri.host raise ArgumentError, "mbox URI must have a path component" unless uri.path - @f = File.open uri.path, 'rb:BINARY' + @f = File.open_binary uri.path, 'r' @path = uri.path else @f = uri_or_fp @@ -114,7 +114,7 @@ class Loader < Source def store_message date, from_email, &block need_blank = File.exists?(@filename) && !File.zero?(@filename) - File.open(@filename, "ab:BINARY") do |f| + File.open_binary(@filename, "a") do |f| f.puts if need_blank f.puts "From #{from_email} #{date.rfc2822}" yield f diff --git a/lib/sup/util.rb b/lib/sup/util.rb index c27e527..e8f3289 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -691,3 +691,10 @@ class Iconv end end end + +class File + def self.open_binary filename, mode + mode += 'b:BINARY' if String.method_defined? :encoding + open filename, mode + end +end -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel