Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] use //IGNORE flag to Iconv
@ 2010-08-10 23:52 Alvaro Herrera
  0 siblings, 0 replies; only message in thread
From: Alvaro Herrera @ 2010-08-10 23:52 UTC (permalink / raw)
  To: sup-devel

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-11  0:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-10 23:52 [sup-devel] use //IGNORE flag to Iconv Alvaro Herrera

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