Skip to content

Commit

Permalink
send-email: validate & reconfirm interactive responses
Browse files Browse the repository at this point in the history
People answer 'y' to "Who should the emails appear to be from?"  and
'n' to "Message-ID to be used as In-Reply-To for the first email?"
for some unknown reason.  While it is possible that your local
username really is "y" and you are sending the mail to your local
colleagues, it is possible, and some might even say it is likely,
that it is a user error.

Fortunately, our interactive prompter already has input validation
mechanism built-in.  Enhance it so that we can optionally reconfirm
and allow the user to pass an input that does not validate, and
"softly" require input to the sender, in-reply-to, and recipient to
contain "@" and "." in this order, which would catch most cases of
mistakes.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Aug 14, 2012
1 parent 829a1c6 commit 51bbccf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ sub ask {
my ($prompt, %arg) = @_;
my $valid_re = $arg{valid_re};
my $default = $arg{default};
my $confirm_only = $arg{confirm_only};
my $resp;
my $i = 0;
return defined $default ? $default : undef
Expand All @@ -698,6 +699,12 @@ sub ask {
if (!defined $valid_re or $resp =~ /$valid_re/) {
return $resp;
}
if ($confirm_only) {
my $yesno = $term->readline("Are you sure you want to use <$resp> [y/N]? ");
if (defined $yesno && $yesno =~ /y/i) {
return $resp;
}
}
}
return undef;
}
Expand Down Expand Up @@ -745,13 +752,15 @@ sub file_declares_8bit_cte {
if (!defined $sender) {
$sender = $repoauthor || $repocommitter || '';
$sender = ask("Who should the emails appear to be from? [$sender] ",
default => $sender);
default => $sender,
valid_re => qr/\@.*\./, confirm_only => 1);
print "Emails will be sent from: ", $sender, "\n";
$prompting++;
}

if (!@initial_to && !defined $to_cmd) {
my $to = ask("Who should the emails be sent to? ");
my $to = ask("Who should the emails be sent to? ",
valid_re => qr/\@.*\./, confirm_only => 1);
push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later
$prompting++;
}
Expand All @@ -777,7 +786,8 @@ sub expand_one_alias {

if ($thread && !defined $initial_reply_to && $prompting) {
$initial_reply_to = ask(
"Message-ID to be used as In-Reply-To for the first email? ");
"Message-ID to be used as In-Reply-To for the first email? ",
valid_re => qr/\@.*\./, confirm_only => 1);
}
if (defined $initial_reply_to) {
$initial_reply_to =~ s/^\s*<?//;
Expand Down

0 comments on commit 51bbccf

Please sign in to comment.