git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] send-email: Defines smtpPassCmd config option
@ 2020-05-01 10:51 Leonardo Bras
  2020-05-01 12:53 ` Carlo Marcelo Arenas Belón
  0 siblings, 1 reply; 13+ messages in thread
From: Leonardo Bras @ 2020-05-01 10:51 UTC (permalink / raw)
  To: git; +Cc: Leonardo Bras, Jan Viktorin, Michal Nazarewicz

Defines smtpPassCmd config option, to allow the user to pass a command
that is used to output the password.

Its useful for users that store the password encrypted on disk, and
want a easy way to send-email without typing it again.

Signed-off-by: Leonardo Bras <leobras.c@gmail.com>
---
 Documentation/config/sendemail.txt |  1 +
 Documentation/git-send-email.txt   |  5 +++--
 git-send-email.perl                | 11 +++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt
index 0006faf800..f71e58862d 100644
--- a/Documentation/config/sendemail.txt
+++ b/Documentation/config/sendemail.txt
@@ -34,6 +34,7 @@ sendemail.from::
 sendemail.multiEdit::
 sendemail.signedoffbycc::
 sendemail.smtpPass::
+sendemail.smtpPassCmd::
 sendemail.suppresscc::
 sendemail.suppressFrom::
 sendemail.to::
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 0a69810147..8e9da5ed64 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -203,8 +203,9 @@ independently of `--smtp-user`
 Furthermore, passwords need not be specified in configuration files
 or on the command line. If a username has been specified (with
 `--smtp-user` or a `sendemail.smtpUser`), but no password has been
-specified (with `--smtp-pass` or `sendemail.smtpPass`), then
-a password is obtained using 'git-credential'.
+specified (with `--smtp-pass` or `sendemail.smtpPass`, or as an output
+of `sendemail.smtpPassCmd`), then a password is obtained using
+'git-credential'.
 
 --no-smtp-auth::
 	Disable SMTP authentication. Short hand for `--smtp-auth=none`
diff --git a/git-send-email.perl b/git-send-email.perl
index dc95656f75..d953ebb058 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -170,6 +170,7 @@ sub format_2822_time {
 my $smtp;
 my $auth;
 my $num_sent = 0;
+my $smtp_authpass_cmd;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -271,6 +272,7 @@ sub do_edit {
     "smtpserveroption" => \@smtp_server_options,
     "smtpuser" => \$smtp_authuser,
     "smtppass" => \$smtp_authpass,
+    "smtppasscmd" => \$smtp_authpass_cmd,
     "smtpdomain" => \$smtp_domain,
     "smtpauth" => \$smtp_auth,
     "smtpbatchsize" => \$batch_size,
@@ -1303,6 +1305,15 @@ sub smtp_auth_maybe {
 		die "invalid smtp auth: '${smtp_auth}'";
 	}
 
+	# Check password command if password was not provided.
+	if(!defined $smtp_authpass && defined $smtp_authpass_cmd){
+		open my $pass, "$smtp_authpass_cmd |"
+			or die sprintf(__("Could not execute '%s'"), $smtp_authpass_cmd);
+		#Cut newline char
+		$smtp_authpass = substr <$pass>, 0, -1;
+		close($pass);
+	}
+
 	# TODO: Authentication may fail not because credentials were
 	# invalid but due to other reasons, in which we should not
 	# reject credentials.
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-05-04 21:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-01 10:51 [PATCH] send-email: Defines smtpPassCmd config option Leonardo Bras
2020-05-01 12:53 ` Carlo Marcelo Arenas Belón
2020-05-01 15:50   ` Junio C Hamano
2020-05-01 22:27     ` Taylor Blau
2020-05-01 23:59       ` brian m. carlson
2020-05-03  9:43         ` Jeff King
2020-05-03 16:27           ` brian m. carlson
2020-05-03 23:48             ` Carlo Marcelo Arenas Belón
2020-05-04 19:49         ` Leonardo Bras
2020-05-04 20:35           ` Jeff King
2020-05-04 21:29             ` Leonardo Bras
2020-05-04 19:09     ` Leonardo Bras
2020-05-04 19:02   ` Leonardo Bras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).