Skip to content

Commit 448e370

Browse files
committed
Merge branch 'jc/send-email-reconfirm' into maint
* jc/send-email-reconfirm: send-email: validate & reconfirm interactive responses
2 parents 78ed88d + 51bbccf commit 448e370

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)