Skip to content

Commit

Permalink
git-send-email: ssh/login style password requests
Browse files Browse the repository at this point in the history
Whilst convenient, it is most unwise to record passwords
in any place but one's brain. Moreover, it is especially
foolish to store them in configuration files, even with
access permissions set accordingly.

git-send-email has been amended, so that if it detects
an smtp username without a password, it promptly prompts
for the password and masks the input for privacy.

Furthermore, the argument to --smtp-pass has been rendered
optional.

The documentation has been updated to reflect these changes.

Signed-off-by: Michael Witten <mfwitten@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Witten authored and Junio C Hamano committed Feb 5, 2008
1 parent 7a2078b commit 2363d74
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
39 changes: 34 additions & 5 deletions Documentation/git-send-email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,40 @@ The --cc option must be repeated for each user you want on the cc list.
servers typically listen to smtp port 25 and ssmtp port
465).

--smtp-user, --smtp-pass::
Username and password for SMTP-AUTH. Defaults are the values of
the configuration values 'sendemail.smtpuser' and
'sendemail.smtppass', but see also 'sendemail.identity'.
If not set, authentication is not attempted.
--smtp-user::
Username for SMTP-AUTH. In place of this option, the following
configuration variables can be specified:
+
--
* sendemail.smtpuser
* sendemail.<identity>.smtpuser (see sendemail.identity).
--
+
However, --smtp-user always overrides these variables.
+
If a username is not specified (with --smtp-user or a
configuration variable), then authentication is not attempted.

--smtp-pass::
Password for SMTP-AUTH. The argument is optional: If no
argument is specified, then the empty string is used as
the password.
+
In place of this option, the following configuration variables
can be specified:
+
--
* sendemail.smtppass
* sendemail.<identity>.smtppass (see sendemail.identity).
--
+
However, --smtp-pass always overrides these variables.
+
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 configuration variable), but no password has been
specified (with --smtp-pass or a configuration variable), then the
user is prompted for a password while the input is masked for privacy.

--smtp-ssl::
If set, connects to the SMTP server using SSL.
Expand Down
25 changes: 21 additions & 4 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ sub format_2822_time {

# Variables we fill in automatically, or via prompting:
my (@to,@cc,@initial_cc,@bcclist,@xh,
$initial_reply_to,$initial_subject,@files,$author,$sender,$compose,$time);
$initial_reply_to,$initial_subject,@files,$author,$sender,$smtp_authpass,$compose,$time);

my $envelope_sender;

Expand All @@ -177,7 +177,7 @@ sub format_2822_time {

# Variables with corresponding config settings
my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_ssl);
my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
my ($no_validate);

Expand Down Expand Up @@ -214,7 +214,7 @@ sub format_2822_time {
"smtp-server=s" => \$smtp_server,
"smtp-server-port=s" => \$smtp_server_port,
"smtp-user=s" => \$smtp_authuser,
"smtp-pass=s" => \$smtp_authpass,
"smtp-pass:s" => \$smtp_authpass,
"smtp-ssl!" => \$smtp_ssl,
"identity=s" => \$identity,
"compose" => \$compose,
Expand Down Expand Up @@ -647,9 +647,26 @@ sub send_message
die "Unable to initialize SMTP properly. Is there something wrong with your config?";
}

if ((defined $smtp_authuser) && (defined $smtp_authpass)) {
if (defined $smtp_authuser) {

if (!defined $smtp_authpass) {

system "stty -echo";

do {
print "Password: ";
$_ = <STDIN>;
print "\n";
} while (!defined $_);

chomp($smtp_authpass = $_);

system "stty echo";
}

$auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
}

$smtp->mail( $raw_from ) or die $smtp->message;
$smtp->to( @recipients ) or die $smtp->message;
$smtp->data or die $smtp->message;
Expand Down

0 comments on commit 2363d74

Please sign in to comment.