sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 881fcd852599a07985cdff563edf375be5ec21a0
parent 8afc5c638ae4f07b2fbfea339022ad84b96a9f54
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sun, 11 Oct 2009 12:53:59 -0700

crypto: some stylistic tweaks to code

Diffstat:
M lib/sup/buffer.rb | 1 +
M lib/sup/crypto.rb | 83 +++++++++++++++++++++++++++++++++++++++----------------------------------------
2 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -755,6 +755,7 @@ EOS
   end
 
 private
+
   def default_status_bar buf
     " [#{buf.mode.name}] #{buf.title}   #{buf.mode.status}"
   end
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -15,15 +15,14 @@ class CryptoManager
     @mutex = Mutex.new
 
     bin = `which gpg`.chomp
-    @cmd =
-      case bin
-      when /\S/
-        debug "crypto: detected gpg binary in #{bin}"
-        "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent"
-      else
-        debug "crypto: no gpg binary detected"
-        nil
-      end
+    @cmd = case bin
+    when /\S/
+      debug "crypto: detected gpg binary in #{bin}"
+      "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent"
+    else
+      debug "crypto: no gpg binary detected"
+      nil
+    end
   end
 
   def have_crypto?; !@cmd.nil? end
@@ -122,44 +121,44 @@ class CryptoManager
 
     output = run_gpg "--decrypt #{payload_fn.path}"
 
-    if $?.success?
-      decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
-        [$1, $2]
-      else
-        [output, nil]
-      end
+    unless $?.success?
+      return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", output.split("\n"))
+    end
 
-      sig = if sig_lines # encrypted & signed
-        if sig_lines =~ /^gpg: (Good signature from .*$)/
-          Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
-        else
-          Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
-        end
+    decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
+      [$1, $2]
+    else
+      [output, nil]
+    end
+
+    sig = if sig_lines # encrypted & signed
+      if sig_lines =~ /^gpg: (Good signature from .*$)/
+        Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
+      else
+        Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
       end
+    end
 
-      # This is gross. This decrypted payload could very well be a multipart
-      # element itself, as opposed to a simple payload. For example, a
-      # multipart/signed element, like those generated by Mutt when encrypting
-      # and signing a message (instead of just clearsigning the body).
-      # Supposedly, decrypted_payload being a multipart element ought to work
-      # out nicely because Message::multipart_encrypted_to_chunks() runs the
-      # decrypted message through message_to_chunks() again to get any
-      # children. However, it does not work as intended because these inner
-      # payloads need not carry a MIME-Version header, yet they are fed to
-      # RMail as a top-level message, for which the MIME-Version header is
-      # required. This causes for the part not to be detected as multipart,
-      # hence being shown as an attachment. If we detect this is happening,
-      # we force the decrypted payload to be interpreted as MIME.
+    # This is gross. This decrypted payload could very well be a multipart
+    # element itself, as opposed to a simple payload. For example, a
+    # multipart/signed element, like those generated by Mutt when encrypting
+    # and signing a message (instead of just clearsigning the body).
+    # Supposedly, decrypted_payload being a multipart element ought to work
+    # out nicely because Message::multipart_encrypted_to_chunks() runs the
+    # decrypted message through message_to_chunks() again to get any
+    # children. However, it does not work as intended because these inner
+    # payloads need not carry a MIME-Version header, yet they are fed to
+    # RMail as a top-level message, for which the MIME-Version header is
+    # required. This causes for the part not to be detected as multipart,
+    # hence being shown as an attachment. If we detect this is happening,
+    # we force the decrypted payload to be interpreted as MIME.
+    msg = RMail::Parser.read(decrypted_payload)
+    if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
+      decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
       msg = RMail::Parser.read(decrypted_payload)
-      if msg.header.content_type =~ %r{^multipart/} and not msg.multipart?
-        decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
-        msg = RMail::Parser.read(decrypted_payload)
-      end
-      notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
-      [notice, sig, msg]
-    else
-      Chunk::CryptoNotice.new :invalid, "This message could not be decrypted", output.split("\n")
     end
+    notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
+    [notice, sig, msg]
   end
 
 private