From f9d7a373f33754ee3f315faa87ff87221aa7711a Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 6 Jun 2017 18:38:46 -0700 Subject: [PATCH] Move setting of GPG_TTY to mutt_init(). (see #3948) This allows other programs mutt runs to use the ncurses pinentry if needed. --- init.c | 15 +++++++++++++++ pgp.c | 18 +++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/init.c b/init.c index f15a3719c..43102378d 100644 --- a/init.c +++ b/init.c @@ -3317,6 +3317,7 @@ void mutt_init (int skip_sys_rc, LIST *commands) char *domain = NULL; int i, need_pause = 0; BUFFER err; + char *tty; mutt_buffer_init (&err); err.dsize = STRING; @@ -3510,6 +3511,20 @@ void mutt_init (int skip_sys_rc, 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" diff --git a/pgp.c b/pgp.c index 653905f04..5c17e94a4 100644 --- a/pgp.c +++ b/pgp.c @@ -105,21 +105,13 @@ void pgp_forget_passphrase (void) mutt_message _("PGP passphrase forgotten."); } +/* 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(). + */ int pgp_use_gpg_agent (void) { - char *tty; - - /* GnuPG 2.1 no longer exports GPG_AGENT_INFO */ - if (!option (OPTUSEGPGAGENT)) - return 0; - - if ((tty = ttyname(0))) - { - setenv("GPG_TTY", tty, 0); - mutt_envlist_set ("GPG_TTY", tty, 0); - } - - return 1; + return option (OPTUSEGPGAGENT); } static pgp_key_t _pgp_parent(pgp_key_t k) -- 2.40.0