Merge branch 'jc/send-email-reconfirm' into maint
authorJunio C Hamano <gitster@pobox.com>
Sat, 15 Sep 2012 04:32:01 +0000 (21:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 15 Sep 2012 04:32:01 +0000 (21:32 -0700)
* jc/send-email-reconfirm:
send-email: validate & reconfirm interactive responses

1  2 
git-send-email.perl
diff --combined git-send-email.perl
index 664713709c0b6e6e4974faa8f0800df2f0beb8e5,e89729bf436ea42634378c966b900bb76485db07..607137b9aaf5e3ea1a7f7f8e4b412afae2f2c320
@@@ -681,6 -681,7 +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
                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 +752,15 @@@ my $prompting = 0
  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 +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*<?//;
@@@ -862,13 -872,11 +872,13 @@@ $time = time - scalar $#files
  sub unquote_rfc2047 {
        local ($_) = @_;
        my $encoding;
 -      if (s/=\?([^?]+)\?q\?(.*)\?=/$2/g) {
 +      s{=\?([^?]+)\?q\?(.*?)\?=}{
                $encoding = $1;
 -              s/_/ /g;
 -              s/=([0-9A-F]{2})/chr(hex($1))/eg;
 -      }
 +              my $e = $2;
 +              $e =~ s/_/ /g;
 +              $e =~ s/=([0-9A-F]{2})/chr(hex($1))/eg;
 +              $e;
 +      }eg;
        return wantarray ? ($_, $encoding) : $_;
  }