[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] use //IGNORE flag to Iconv



Hi sup-developers,

The following patch makes transcoding failure be nicer by discarding
broken chars and displaying what can be successfully transcoded, instead
of punting and displaying the ASCII representation.

This is particularly useful when corporate email appends a disclaimer
that's encoded in a different encoding than whatever the user has set up
in the MUA.  (I see it a lot.)

My iconv_open(3) manpage says that the //IGNORE flag is a GNU extension.
I'm not sure how would this be handled by other platforms, and I have no
way to test.


diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index d19caca..f7e8a80 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -699,9 +699,9 @@ class Iconv
     end
 
     begin
-      returning(Iconv.iconv(target, charset, text + " ").join[0 .. -2]) { |str| str.check }
+      returning(Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2]) { |str| str.check }
     rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::InvalidCharacter, Iconv::IllegalSequence, String::CheckError
-      debug "couldn't transcode text from #{orig_charset} (#{charset}) to #{target}) (#{text[0 ... 20].inspect}...) (got #{$!.message} (#{$!.class}))"
+      debug "couldn't transcode text from #{orig_charset} (#{charset}) to #{target} (#{text[0 ... 20].inspect}...): got #{$!.class} (#{$!.message})"
       text.ascii
     end
   end

-- 
Álvaro Herrera <alvherre@alvh.no-ip.org>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel