sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit bf9690c64c9fde0c1da930e53d520579369938a8
parent e9b776f28b42d6a40a512d15c552c51cafbecb5c
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Tue, 12 Oct 2010 23:14:27 -0700

Merge branch 'master' into next

Diffstat:
M lib/sup.rb | 1 +
M lib/sup/crypto.rb | 2 +-
M lib/sup/maildir.rb | 1 -
M lib/sup/mbox.rb | 1 -
M lib/sup/modes/edit-message-mode.rb | 28 +++++++++++++++++++++++++---
M lib/sup/modes/thread-index-mode.rb | 2 +-
M lib/sup/util.rb | 15 ++++++++++++++-
7 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -5,6 +5,7 @@ require 'thread'
 require 'fileutils'
 require 'gettext'
 require 'curses'
+require 'rmail'
 begin
   require 'fastthread'
 rescue LoadError
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -207,7 +207,7 @@ private
   ## here's where we munge rmail output into the format that signed/encrypted
   ## PGP/GPG messages should be
   def format_payload payload
-    payload.to_s.gsub(/(^|[^\r])\n/, "\\1\r\n").gsub(/^MIME-Version: .*\r\n/, "")
+    payload.to_s.gsub(/(^|[^\r])\n/, "\\1\r\n")
   end
 
   # logic is:
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -1,4 +1,3 @@
-require 'rmail'
 require 'uri'
 
 module Redwood
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -1,4 +1,3 @@
-require 'rmail'
 require 'uri'
 require 'set'
 
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -1,7 +1,6 @@
 require 'tempfile'
 require 'socket' # just for gethostname!
 require 'pathname'
-require 'rmail'
 
 module Redwood
 
@@ -403,8 +402,11 @@ protected
     if @crypto_selector && @crypto_selector.val != :none
       from_email = Person.from_address(@header["From"]).email
       to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| Person.from_address(p).email }
-      m.header["Content-Transfer-Encoding"] = 'base64'
-      m.body = [m.body].pack('m')
+      if m.multipart?
+        m.each_part {|p| p = transfer_encode p}
+      else
+        m = transfer_encode m
+      end
 
       m = CryptoManager.send @crypto_selector.val, from_email, to_email, m
     end
@@ -425,6 +427,7 @@ protected
     m.header["Message-Id"] = @message_id
     m.header["User-Agent"] = "Sup/#{Redwood::VERSION}"
     m.header["Content-Transfer-Encoding"] ||= '8bit'
+    m.header["MIME-Version"] = "1.0" if m.multipart?
     m
   end
 
@@ -520,6 +523,25 @@ private
       []
     end
   end
+
+  def transfer_encode msg_part
+    ## return the message unchanged if it's already encoded
+    if (msg_part.header["Content-Transfer-Encoding"] == "base64" ||
+        msg_part.header["Content-Transfer-Encoding"] == "quoted-printable")
+      return msg_part
+    end
+
+    ## encode to quoted-printable for all text/* MIME types,
+    ## use base64 otherwise
+    if msg_part.header["Content-Type"] =~ /text\/.*/
+      msg_part.header["Content-Transfer-Encoding"] = 'quoted-printable'
+      msg_part.body = [msg_part.body].pack('M')
+    else
+      msg_part.header["Content-Transfer-Encoding"] = 'base64'
+      msg_part.body = [msg_part.body].pack('m')
+    end
+    msg_part
+  end
 end
 
 end
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -885,7 +885,7 @@ protected
     [ 
       [:tagged_color, @tags.tagged?(t) ? ">" : " "],
       [:date_color, date_widget_text],
-      (starred ? [:starred_color, "*"] : [:none, " "]),
+      [:starred_color, (starred ? "*" : " ")],
     ] +
       from +
       [
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -98,6 +98,19 @@ module RMail
       a
     end
   end
+
+  class Serialize
+    ## Don't add MIME-Version headers on serialization. Sup sometimes want's to serialize
+    ## message parts where these headers are not needed and messing with the message on
+    ## serialization breaks gpg signatures. The commented section shows the original RMail
+    ## code.
+    def calculate_boundaries(message)
+      calculate_boundaries_low(message, [])
+      # unless message.header['MIME-Version']
+      #   message.header['MIME-Version'] = "1.0"
+      # end
+    end
+  end
 end
 
 class Range
@@ -224,7 +237,7 @@ class String
   ## a very complicated regex found on teh internets to split on
   ## commas, unless they occurr within double quotes.
   def split_on_commas
-    split(/,\s*(?=(?:[^"]*"[^"]*")*(?![^"]*"))/)
+    normalize_whitespace().split(/,\s*(?=(?:[^"]*"[^"]*")*(?![^"]*"))/)
   end
 
   ## ok, here we do it the hard way. got to have a remainder for purposes of