Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] use //IGNORE flag to Iconv
Date: Tue, 10 Aug 2010 19:52:05 -0400	[thread overview]
Message-ID: <1281483789-sup-7077@alvh.no-ip.org> (raw)

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

                 reply	other threads:[~2010-08-11  0:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1281483789-sup-7077@alvh.no-ip.org \
    --to=alvherre@alvh.no-ip.org \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox