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] pass //IGNORE to iconv
Date: Tue, 09 Nov 2010 12:27:06 -0300	[thread overview]
Message-ID: <1289316270-sup-7500@alvh.no-ip.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]


With the current code, an encoding failure means we see (and quote)
stuff like \xab\xbc\x07 in the text.  Using the //IGNORE flag allows the
code to ignore broken chars instead of displaying large amounts of junk.

I note that the text containing broken chars is coming from external
sources, so there's nothing that could be done locally to fix it.

-- 
Álvaro Herrera <alvherre@alvh.no-ip.org>

[-- Attachment #2: 0003-Make-encoding-conversion-pass-IGNORE-to-iconv.patch --]
[-- Type: application/octet-stream, Size: 1609 bytes --]

From 9f604264731745b30927ac6822739d94a3e4e492 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 9 Nov 2010 12:13:47 -0300
Subject: [PATCH 3/3] Make encoding conversion pass //IGNORE to iconv

This makes transcoding failure a bit more user-friendly 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 systems append a
disclaimer that's encoded in a different encoding than whatever the user
has set up in the MUA; or when broken remote MUAs fail to re-encode the
quoted part when they reply in a different encoding.
---
 lib/sup/util.rb |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 4a0e4e7..8b9c6a5 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -712,9 +712,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
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

             reply	other threads:[~2010-11-09 17:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09 15:27 Alvaro Herrera [this message]
2010-11-15  4:17 ` Rich Lane

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=1289316270-sup-7500@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