sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit ac321bd89a72dba74e9b2ff182be0b5fc89a61fc
parent 42149329b37af5e3fc0183367521999c479b7881
Author: Hamish Downer <dmishd@gmail.com>
Date:   Sun, 30 Jan 2011 23:37:45 +0000

Catch case where gpg-agent not running or key not available

GPGME does not raise an Error when the key is not available (say
gpg-agent is not running, or the key is on removable media and has
been removed). In these cases GPGME returns a zero length string.
This patch checks the returned string and raises an error if it has
zero length.

Diffstat:
M lib/sup/crypto.rb | 14 ++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -68,6 +68,13 @@ EOS
       raise Error, "GPG command failed. See log for details."
     end
 
+    # if the key (or gpg-agent) is not available GPGME does not complain 
+    # but just returns a zero length string. Let's catch that
+    if sig.length == 0
+      info "GPG failed to generate signature: check that gpg-agent is running and your key is available."
+      raise Error, "GPG command failed. See log for details."
+    end
+
     envelope = RMail::Message.new
     envelope.header["Content-Type"] = 'multipart/signed; protocol=application/pgp-signature'
 
@@ -96,6 +103,13 @@ EOS
       raise Error, "GPG command failed. See log for details."
     end
 
+    # if the key (or gpg-agent) is not available GPGME does not complain 
+    # but just returns a zero length string. Let's catch that
+    if cipher.length == 0
+      info "GPG failed to generate cipher text: check that gpg-agent is running and your key is available."
+      raise Error, "GPG command failed. See log for details."
+    end
+
     encrypted_payload = RMail::Message.new
     encrypted_payload.header["Content-Type"] = "application/octet-stream"
     encrypted_payload.header["Content-Disposition"] = 'inline; filename="msg.asc"'