Merge branch 'mw/send-email'

* mw/send-email:
  git-send-email: Better handling of EOF
  git-send-email: SIG{TERM,INT} handlers
  git-send-email: ssh/login style password requests
This commit is contained in:
Junio C Hamano 2008-02-11 16:46:36 -08:00
commit e3560df69d
2 changed files with 106 additions and 27 deletions

View file

@ -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 servers typically listen to smtp port 25 and ssmtp port
465). 465).
--smtp-user, --smtp-pass:: --smtp-user::
Username and password for SMTP-AUTH. Defaults are the values of Username for SMTP-AUTH. In place of this option, the following
the configuration values 'sendemail.smtpuser' and configuration variables can be specified:
'sendemail.smtppass', but see also 'sendemail.identity'. +
If not set, authentication is not attempted. --
* 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:: --smtp-ssl::
If set, connects to the SMTP server using SSL. If set, connects to the SMTP server using SSL.

View file

@ -24,8 +24,6 @@
use Term::ANSIColor; use Term::ANSIColor;
use Git; use Git;
$SIG{INT} = sub { print color("reset"), "\n"; exit };
package FakeTerm; package FakeTerm;
sub new { sub new {
my ($class, $reason) = @_; my ($class, $reason) = @_;
@ -163,7 +161,7 @@ sub format_2822_time {
# Variables we fill in automatically, or via prompting: # Variables we fill in automatically, or via prompting:
my (@to,@cc,@initial_cc,@bcclist,@xh, 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; my $envelope_sender;
@ -183,7 +181,7 @@ sub format_2822_time {
# Variables with corresponding config settings # Variables with corresponding config settings
my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd); 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 ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
my ($no_validate); my ($no_validate);
my (@suppress_cc); my (@suppress_cc);
@ -209,6 +207,29 @@ sub format_2822_time {
"suppresscc" => \@suppress_cc, "suppresscc" => \@suppress_cc,
); );
# Handle Uncouth Termination
sub signal_handler {
# Make text normal
print color("reset"), "\n";
# SMTP password masked
system "stty echo";
# tmp files from --compose
if (-e $compose_filename) {
print "'$compose_filename' contains an intermediate version of the email you were composing.\n";
}
if (-e ($compose_filename . ".final")) {
print "'$compose_filename.final' contains the composed email.\n"
}
exit;
};
$SIG{TERM} = \&signal_handler;
$SIG{INT} = \&signal_handler;
# Begin by accumulating all the variables (defined above), that we will end up # Begin by accumulating all the variables (defined above), that we will end up
# needing, first, from the command line: # needing, first, from the command line:
@ -222,7 +243,7 @@ sub format_2822_time {
"smtp-server=s" => \$smtp_server, "smtp-server=s" => \$smtp_server,
"smtp-server-port=s" => \$smtp_server_port, "smtp-server-port=s" => \$smtp_server_port,
"smtp-user=s" => \$smtp_authuser, "smtp-user=s" => \$smtp_authuser,
"smtp-pass=s" => \$smtp_authpass, "smtp-pass:s" => \$smtp_authpass,
"smtp-ssl!" => \$smtp_ssl, "smtp-ssl!" => \$smtp_ssl,
"identity=s" => \$identity, "identity=s" => \$identity,
"compose" => \$compose, "compose" => \$compose,
@ -393,9 +414,12 @@ sub read_config {
my $prompting = 0; my $prompting = 0;
if (!defined $sender) { if (!defined $sender) {
$sender = $repoauthor || $repocommitter; $sender = $repoauthor || $repocommitter;
do {
while (1) {
$_ = $term->readline("Who should the emails appear to be from? [$sender] "); $_ = $term->readline("Who should the emails appear to be from? [$sender] ");
} while (!defined $_); last if defined $_;
print "\n";
}
$sender = $_ if ($_); $sender = $_ if ($_);
print "Emails will be sent from: ", $sender, "\n"; print "Emails will be sent from: ", $sender, "\n";
@ -403,10 +427,14 @@ sub read_config {
} }
if (!@to) { if (!@to) {
do {
$_ = $term->readline("Who should the emails be sent to? ",
""); while (1) {
} while (!defined $_); $_ = $term->readline("Who should the emails be sent to? ", "");
last if defined $_;
print "\n";
}
my $to = $_; my $to = $_;
push @to, split /,/, $to; push @to, split /,/, $to;
$prompting++; $prompting++;
@ -428,19 +456,22 @@ sub expand_aliases {
@bcclist = expand_aliases(@bcclist); @bcclist = expand_aliases(@bcclist);
if (!defined $initial_subject && $compose) { if (!defined $initial_subject && $compose) {
do { while (1) {
$_ = $term->readline("What subject should the initial email start with? ", $_ = $term->readline("What subject should the initial email start with? ", $initial_subject);
$initial_subject); last if defined $_;
} while (!defined $_); print "\n";
}
$initial_subject = $_; $initial_subject = $_;
$prompting++; $prompting++;
} }
if ($thread && !defined $initial_reply_to && $prompting) { if ($thread && !defined $initial_reply_to && $prompting) {
do { while (1) {
$_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ", $_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ", $initial_reply_to);
$initial_reply_to); last if defined $_;
} while (!defined $_); print "\n";
}
$initial_reply_to = $_; $initial_reply_to = $_;
} }
@ -491,9 +522,11 @@ sub expand_aliases {
close(C); close(C);
close(C2); close(C2);
do { while (1) {
$_ = $term->readline("Send this email? (y|n) "); $_ = $term->readline("Send this email? (y|n) ");
} while (!defined $_); last if defined $_;
print "\n";
}
if (uc substr($_,0,1) ne 'Y') { if (uc substr($_,0,1) ne 'Y') {
cleanup_compose_files(); cleanup_compose_files();
@ -685,9 +718,26 @@ sub send_message
die "Unable to initialize SMTP properly. Is there something wrong with your config?"; 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; $auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
} }
$smtp->mail( $raw_from ) or die $smtp->message; $smtp->mail( $raw_from ) or die $smtp->message;
$smtp->to( @recipients ) or die $smtp->message; $smtp->to( @recipients ) or die $smtp->message;
$smtp->data or die $smtp->message; $smtp->data or die $smtp->message;