Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
@ 2010-01-04 19:45 Rich Lane
  2010-01-05 22:05 ` William Morgan
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Lane @ 2010-01-04 19:45 UTC (permalink / raw)
  To: sup-devel

---
 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
  2010-01-04 19:45 [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9 Rich Lane
@ 2010-01-05 22:05 ` William Morgan
  2010-01-06 16:35   ` William Morgan
  0 siblings, 1 reply; 6+ messages in thread
From: William Morgan @ 2010-01-05 22:05 UTC (permalink / raw)
  To: sup-devel

Applied to ruby-1.9-encodings. I added another commit to make it pass
through any block, otherwise it was silently failing on my 1.8.7 setup.
Hope it still works for 1.9. :) Thanks!
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
  2010-01-05 22:05 ` William Morgan
@ 2010-01-06 16:35   ` William Morgan
  2010-01-17 23:12     ` William Morgan
  0 siblings, 1 reply; 6+ messages in thread
From: William Morgan @ 2010-01-06 16:35 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from William Morgan's message of 2010-01-05:
> Applied to ruby-1.9-encodings. I added another commit to make it pass
> through any block, otherwise it was silently failing on my 1.8.7 setup.
> Hope it still works for 1.9. :) Thanks!

The internet claims that using "rb" and "wb" works for both 1.8.5 and
1.9.1, but I haven't tried it.
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
  2010-01-06 16:35   ` William Morgan
@ 2010-01-17 23:12     ` William Morgan
  2010-01-18  8:38       ` Gaute Hope
  0 siblings, 1 reply; 6+ messages in thread
From: William Morgan @ 2010-01-17 23:12 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from William Morgan's message of 2010-01-06:
> The internet claims that using "rb" and "wb" works for both 1.8.5 and
> 1.9.1, but I haven't tried it.

I've done this in ruby-1.9-encodings and remerged into next.

Those of you tracking next with 1.9, please let me know if you
experience any weird encoding errors.

(And those with 1.8, as well, I suppose.)
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
  2010-01-17 23:12     ` William Morgan
@ 2010-01-18  8:38       ` Gaute Hope
  2010-01-18 13:05         ` William Morgan
  0 siblings, 1 reply; 6+ messages in thread
From: Gaute Hope @ 2010-01-18  8:38 UTC (permalink / raw)
  To: sup-devel

Excerpts from William Morgan's message of 2010-01-18 00:12:50 +0100:
> Reformatted excerpts from William Morgan's message of 2010-01-06:
> > The internet claims that using "rb" and "wb" works for both 1.8.5 and
> > 1.9.1, but I haven't tried it.
> 
> I've done this in ruby-1.9-encodings and remerged into next.
> 
> Those of you tracking next with 1.9, please let me know if you
> experience any weird encoding errors.
> 
> (And those with 1.8, as well, I suppose.)

See issue 36, its a bit big: problems with subjects, tab completion, and
recipients.

- gaute


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9
  2010-01-18  8:38       ` Gaute Hope
@ 2010-01-18 13:05         ` William Morgan
  0 siblings, 0 replies; 6+ messages in thread
From: William Morgan @ 2010-01-18 13:05 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Gaute Hope's message of 2010-01-18:
> See issue 36, its a bit big: problems with subjects, tab completion,
> and recipients.

This is an unrelated issue, though I agree it's important and should be
addressed.

Rich sent out a patch a while ago that added the special encoding pragma
to a bunch of source files. That might fix this, as might putting a "u"
at the end of every Regexp in the source. :(
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-01-18 13:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-04 19:45 [sup-devel] [PATCH] only open mail files in binary mode on Ruby 1.9 Rich Lane
2010-01-05 22:05 ` William Morgan
2010-01-06 16:35   ` William Morgan
2010-01-17 23:12     ` William Morgan
2010-01-18  8:38       ` Gaute Hope
2010-01-18 13:05         ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox