From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>,
Stephen Boyd <bebarino@gmail.com>
Subject: [PATCH] send-email: validate & reconfirm interactive responses
Date: Tue, 14 Aug 2012 15:25:32 -0700 [thread overview]
Message-ID: <1344983132-22578-1-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <CAOeW2eGZm7PLRaktjQQdDJm2BqAihS0pzsY2GUNFUO83s8qBPQ@mail.gmail.com>
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 really have "y"
as your local username and sending the mail to your local colleagues,
it is plausible that it could be an 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>
---
git-send-email.perl | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index ef30c55..e89729b 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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
@@ -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;
}
@@ -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++;
}
@@ -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*<?//;
--
1.7.12.rc2.18.g61b472e
next prev parent reply other threads:[~2012-08-14 22:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-13 23:50 send-email and in-reply-to = n Stephen Boyd
2012-08-13 23:53 ` Junio C Hamano
2012-08-14 20:51 ` Martin von Zweigbergk
2012-08-14 22:25 ` Junio C Hamano [this message]
2012-08-14 22:33 ` [PATCH] send-email: validate & reconfirm interactive responses Martin von Zweigbergk
2012-08-14 22:57 ` Junio C Hamano
2012-09-05 19:24 ` Stephen Boyd
2012-09-06 3:29 ` Junio C Hamano
2012-09-06 18:31 ` Stephen Boyd
2012-09-06 20:03 ` Junio C Hamano
2012-09-06 21:21 ` [PATCH] send-email: initial_to and initial_reply_to are both optional Junio C Hamano
2012-09-06 21:49 ` Stephen Boyd
2012-09-06 21:47 ` [PATCH] send-email: validate & reconfirm interactive responses Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344983132-22578-1-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=martin.von.zweigbergk@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).