sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 539b3f38d593e85d53e05b0b5c49285fee5cce3a
parent 3106f6d9f270bb3d1b115d6787be470b330f5fbc
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Mon,  7 Oct 2013 13:09:28 +0200

Merge #150: Fallback to fix_encoding! if gsub fails in message chunk

Diffstat:
M lib/sup/message_chunks.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/sup/message_chunks.rb b/lib/sup/message_chunks.rb
@@ -131,7 +131,13 @@ EOS
       @lines = nil
       if text
         text = text.transcode(encoded_content.charset || $encoding, text.encoding)
-        @lines = text.gsub("\r\n", "\n").gsub(/\t/, "        ").gsub(/\r/, "").split("\n")
+        begin
+          @lines = text.gsub("\r\n", "\n").gsub(/\t/, "        ").gsub(/\r/, "").split("\n")
+        rescue Encoding::CompatibilityError
+          @lines = text.fix_encoding!.gsub("\r\n", "\n").gsub(/\t/, "        ").gsub(/\r/, "").split("\n")
+          debug "error while decoding message text, falling back to default encoding, expect errors in encoding: #{text.fix_encoding!}"
+        end
+
         @quotable = true
       end
     end