sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 9efb32fd7177199c7af7c46c3a3bcd994ab80893
parent 48987e03145e6c889e1cd8ea4ad2a01d53331361
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Mon, 22 Jul 2013 16:32:52 +0200

Merge #107: Use fix_encoding and transcode in place of force_encoding

Diffstat:
M bin/sup | 4 ++--
M lib/sup/buffer.rb | 12 ++++++------
M lib/sup/crypto.rb | 4 ++--
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -290,7 +290,7 @@ begin
       b.mode.load_in_background if new
     when :search
       completions = LabelManager.all_labels.map { |l| "label:#{LabelManager.string_for l}" }
-      completions = completions.each { |l| l.force_encoding 'UTF-8' if l.respond_to?(:encoding) }
+      completions = completions.each { |l| l.fix_encoding }
       completions += Index::COMPL_PREFIXES
       query = BufferManager.ask_many_with_completions :search, "Search all messages (enter for saved searches): ", completions
       unless query.nil?
@@ -304,7 +304,7 @@ begin
       SearchResultsMode.spawn_from_query "is:unread"
     when :list_labels
       labels = LabelManager.all_labels.map { |l| LabelManager.string_for l }
-      labels = labels.each { |l| l.force_encoding 'UTF-8' if l.respond_to?(:encoding) }
+      labels = labels.each { |l| l.fix_encoding }
 
       user_label = bm.ask_with_completions :label, "Show threads with label (enter for listing): ", labels
       unless user_label.nil?
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -450,7 +450,7 @@ EOS
 
   def ask_with_completions domain, question, completions, default=nil
     ask domain, question, default do |s|
-      s.force_encoding 'UTF-8' if s.respond_to?(:encoding)
+      s.fix_encoding
       completions.select { |x| x =~ /^#{Regexp::escape s}/iu }.map { |x| [x, x] }
     end
   end
@@ -467,8 +467,8 @@ EOS
           raise "william screwed up completion: #{partial.inspect}"
         end
 
-      prefix.force_encoding 'UTF-8' if prefix.respond_to?(:encoding)
-      target.force_encoding 'UTF-8' if target.respond_to?(:encoding)
+      prefix.fix_encoding
+      target.fix_encoding
       completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
     end
   end
@@ -477,10 +477,10 @@ EOS
     ask domain, question, default do |partial|
       prefix, target = partial.split_on_commas_with_remainder
       target ||= prefix.pop || ""
-      target.force_encoding 'UTF-8' if target.respond_to?(:encoding)
+      target.fix_encoding
 
       prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
-      prefix.force_encoding 'UTF-8' if prefix.respond_to?(:encoding)
+      prefix.fix_encoding
 
       completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
     end
@@ -622,7 +622,7 @@ EOS
       tf.deactivate
       draw_screen :sync => false, :status => status, :title => title
     end
-    tf.value.tap { |x| x.force_encoding Encoding::UTF_8 if x && x.respond_to?(:encoding) }
+    tf.value.tap { |x| x.fix_encoding if x }
   end
 
   def ask_getch question, accept=nil
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -275,7 +275,7 @@ EOS
     end
     plain_data.seek(0, IO::SEEK_SET)
     output = plain_data.read
-    output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+    output.transcode(Encoding::ASCII_8BIT, output.encoding)
 
     ## TODO: test to see if it is still necessary to do a 2nd run if verify
     ## fails.
@@ -314,7 +314,7 @@ EOS
       msg = RMail::Parser.read output
       if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
         output = "MIME-Version: 1.0\n" + output
-        output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+        output.fix_encoding
         msg = RMail::Parser.read output
       end
     end