Skip to content

Commit 51bbccf

Browse files
committed
send-email: validate & reconfirm interactive responses
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 <[email protected]>
1 parent 829a1c6 commit 51bbccf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

git-send-email.perl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ sub ask {
681681
my ($prompt, %arg) = @_;
682682
my $valid_re = $arg{valid_re};
683683
my $default = $arg{default};
684+
my $confirm_only = $arg{confirm_only};
684685
my $resp;
685686
my $i = 0;
686687
return defined $default ? $default : undef
@@ -698,6 +699,12 @@ sub ask {
698699
if (!defined $valid_re or $resp =~ /$valid_re/) {
699700
return $resp;
700701
}
702+
if ($confirm_only) {
703+
my $yesno = $term->readline("Are you sure you want to use <$resp> [y/N]? ");
704+
if (defined $yesno && $yesno =~ /y/i) {
705+
return $resp;
706+
}
707+
}
701708
}
702709
return undef;
703710
}
@@ -745,13 +752,15 @@ sub file_declares_8bit_cte {
745752
if (!defined $sender) {
746753
$sender = $repoauthor || $repocommitter || '';
747754
$sender = ask("Who should the emails appear to be from? [$sender] ",
748-
default => $sender);
755+
default => $sender,
756+
valid_re => qr/\@.*\./, confirm_only => 1);
749757
print "Emails will be sent from: ", $sender, "\n";
750758
$prompting++;
751759
}
752760

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

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

0 commit comments

Comments
 (0)