sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 745703f0c65d2f93d560a212d7b37cfefc6d2355
parent 5a45d6fe4e1f965313cb9ab0b5f68dc3e6d19bf5
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Fri,  4 Jun 2010 19:54:03 -0700

Merge branch 'master' into next

Diffstat:
M lib/sup/message.rb | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -494,19 +494,24 @@ private
 
       ## otherwise, it's body text
       else
-        ## if there's no charset, use the current encoding as the charset.
-        ## this ensures that the body is normalized to avoid non-displayable
-        ## characters
+        ## Decode the body, charset conversion will follow either in
+        ## inline_gpg_to_chunks (for inline GPG signed messages) or
+        ## a few lines below (messages without inline GPG)
+        body = m.body ? m.decode : ""
+
+        ## Check for inline-PGP
+        chunks = inline_gpg_to_chunks body, $encoding, (m.charset || $encoding)
+        return chunks if chunks
+
         if m.body
+          ## if there's no charset, use the current encoding as the charset.
+          ## this ensures that the body is normalized to avoid non-displayable
+          ## characters
           body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode)
         else
           body = ""
         end
 
-        ## Check for inline-PGP
-        chunks = inline_gpg_to_chunks body.split("\n")
-        return chunks if chunks
-
         text_to_chunks(body.normalize_whitespace.split("\n"), encrypted)
       end
     end
@@ -515,13 +520,15 @@ private
   ## looks for gpg signed (but not encrypted) inline  messages inside the
   ## message body (there is no extra header for inline GPG) or for encrypted
   ## (and possible signed) inline GPG messages
-  def inline_gpg_to_chunks lines
+  def inline_gpg_to_chunks body, encoding_to, encoding_from
+    lines = body.split("\n")
     gpg = lines.between(GPG_SIGNED_START, GPG_SIGNED_END)
     if !gpg.empty?
       msg = RMail::Message.new
       msg.body = gpg.join("\n")
 
-      sig = lines.between(GPG_SIGNED_START, GPG_SIG_END)
+      body = Iconv.easy_decode(encoding_to, encoding_from, body)
+      sig = body.split("\n").between(GPG_SIGNED_START, GPG_SIG_END)
       payload = RMail::Message.new
       payload.body = sig[1, sig.size-2].join("\n")
       return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact