]> granicus.if.org Git - neomutt/commitdiff
Move setting of GPG_TTY to mutt_init(). (see #3948)
authorKevin McCarthy <kevin@8t8.us>
Wed, 7 Jun 2017 01:38:46 +0000 (18:38 -0700)
committerRichard Russon <rich@flatcap.org>
Wed, 7 Jun 2017 21:53:18 +0000 (22:53 +0100)
This allows other programs mutt runs to use the ncurses pinentry if needed.

init.c
ncrypt/pgp.c

diff --git a/init.c b/init.c
index 049f4d6546b6354dc607b3602021a5d4444b6856..49c0c7e617e61bf8bfb932ed72fa2993e930be0e 100644 (file)
--- a/init.c
+++ b/init.c
@@ -3924,6 +3924,7 @@ void mutt_init(int skip_sys_rc, struct List *commands)
   char *p, buffer[STRING];
   int need_pause = 0;
   struct Buffer err;
+  char *tty;
 
   mutt_buffer_init(&err);
   err.dsize = STRING;
@@ -4142,6 +4143,20 @@ void mutt_init(int skip_sys_rc, struct List *commands)
     unset_option(OPTSUSPEND);
 #endif
 
+  /* GPG_TTY is used by the ncurses pinentry program for GPG.  GPG is
+   * sometimes also used to decrypt passwords in programs launched by
+   * mutt, such as using msmtp as $sendmail, so we set it here as
+   * opposed to inside pgp.c
+   *
+   * We also call setenv() because send_msg() is not converted to use
+   * the mutt envlist.
+   */
+  if ((tty = ttyname(0)))
+  {
+    setenv("GPG_TTY", tty, 0);
+    mutt_envlist_set("GPG_TTY", tty, 0);
+  }
+
   mutt_init_history();
 
   /* RFC2368, "4. Unsafe headers"
index 5e3ac1fe98f9d21c5fb195c6f66607fed0dd1b29..4837025587e9c608841b6a71fffa172450f20006 100644 (file)
@@ -96,21 +96,13 @@ int pgp_valid_passphrase(void)
   return 0;
 }
 
+/* This function used to do more: check GPG_AGENT_INFO,
+ * set GPG_TTY.  GPG_AGENT_INFO is no longer exported, and GPG_TTY
+ * is now set in mutt_init().
+ */
 bool pgp_use_gpg_agent(void)
 {
-  char *tty = NULL;
-
-  /* GnuPG 2.1 no longer exports GPG_AGENT_INFO */
-  if (!option(OPTUSEGPGAGENT))
-    return false;
-
-  if ((tty = ttyname(0)))
-  {
-    setenv("GPG_TTY", tty, 0);
-    mutt_envlist_set("GPG_TTY", tty, false);
-  }
-
-  return true;
+  return option (OPTUSEGPGAGENT);
 }
 
 static struct PgpKeyInfo *_pgp_parent(struct PgpKeyInfo *k)