75
--[no-]thread * Use In-Reply-To: field. Default on.
76
77
Administering:
78
+ --confirm <str> * Confirm recipients before sending;
79
+ auto, cc, compose, always, or never.
80
--quiet * Output one line of info per email.
81
--dry-run * Don't actually send the emails.
82
--[no-]validate * Perform patch sanity checks. Default on.
183
my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
184
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
185
my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
184
-my ($validate);
186
+my ($validate, $confirm);
187
my (@suppress_cc);
188
189
my %config_bool_settings = (
209
"suppresscc" => \@suppress_cc,
210
"envelopesender" => \$envelope_sender,
211
"multiedit" => \$multiedit,
212
+ "confirm" => \$confirm,
213
);
214
215
# Handle Uncouth Termination
261
"suppress-from!" => \$suppress_from,
262
"suppress-cc=s" => \@suppress_cc,
263
"signed-off-cc|signed-off-by-cc!" => \$signed_off_by_cc,
264
+ "confirm=s" => \$confirm,
265
"dry-run" => \$dry_run,
266
"envelope-sender=s" => \$envelope_sender,
267
"thread!" => \$thread,
350
delete $suppress_cc{'body'};
351
}
352
353
+# Set confirm's default value
354
+my $confirm_unconfigured = !defined $confirm;
355
+if ($confirm_unconfigured) {
356
+ $confirm = scalar %suppress_cc ? 'compose' : 'auto';
357
+};
358
+die "Unknown --confirm setting: '$confirm'\n"
359
+ unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
360
+
361
# Debugging, print out the suppressions.
362
if (0) {
363
print "suppressions:\n";
675
$smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*
676
}
677
666
-if ($compose) {
667
- while (1) {
668
- $_ = $term->readline("Send this email? (y|n) ");
669
- last if defined $_;
670
- print "\n";
671
- }
672
-
673
- if (uc substr($_,0,1) ne 'Y') {
674
- cleanup_compose_files();
675
- exit(0);
676
- }
677
-
678
- if ($compose > 0) {
679
- @files = ($compose_filename . ".final", @files);
680
- }
678
+if ($compose && $compose > 0) {
679
+ @files = ($compose_filename . ".final", @files);
680
}
681
682
# Variables we set as part of the loop over files
684
-our ($message_id, %mail, $subject, $reply_to, $references, $message);
683
+our ($message_id, %mail, $subject, $reply_to, $references, $message,
684
+ $needs_confirm, $message_num);
685
686
sub extract_valid_address {
687
my $address = shift;
837
unshift (@sendmail_parameters,
838
'-f', $raw_from) if(defined $envelope_sender);
839
840
+ if ($needs_confirm && !$dry_run) {
841
+ print "\n$header\n";
842
+ if ($needs_confirm eq "inform") {
843
+ $confirm_unconfigured = 0; # squelch this message for the rest of this run
844
+ print " The Cc list above has been expanded by additional\n";
845
+ print " addresses found in the patch commit message. By default\n";
846
+ print " send-email prompts before sending whenever this occurs.\n";
847
+ print " This behavior is controlled by the sendemail.confirm\n";
848
+ print " configuration setting.\n";
849
+ print "\n";
850
+ print " For additional information, run 'git send-email --help'.\n";
851
+ print " To retain the current behavior, but squelch this message,\n";
852
+ print " run 'git config --global sendemail.confirm auto'.\n\n";
853
+ }
854
+ while (1) {
855
+ chomp ($_ = $term->readline(
856
+ "Send this email? ([y]es|[n]o|[q]uit|[a]ll): "
857
+ ));
858
+ last if /^(?:yes|y|no|n|quit|q|all|a)/i;
859
+ print "\n";
860
+ }
861
+ if (/^n/i) {
862
+ return;
863
+ } elsif (/^q/i) {
864
+ cleanup_compose_files();
865
+ exit(0);
866
+ } elsif (/^a/i) {
867
+ $confirm = 'never';
868
+ }
869
+ }
870
+
871
if ($dry_run) {
872
# We don't want to send the email.
873
} elsif ($smtp_server =~ m#^/#) {
966
$reply_to = $initial_reply_to;
967
$references = $initial_reply_to || '';
968
$subject = $initial_subject;
969
+$message_num = 0;
970
971
foreach my $t (@files) {
972
open(F,"<",$t) or die "can't open file $t";
975
my $author_encoding;
976
my $has_content_type;
977
my $body_encoding;
946
- @cc = @initial_cc;
978
+ @cc = ();
979
@xh = ();
980
my $input_format = undef;
981
my @header = ();
982
$message = "";
983
+ $message_num++;
984
# First unfold multiline header fields
985
while(<F>) {
986
last if /^\s*$/;
1113
}
1114
}
1115
1116
+ $needs_confirm = (
1117
+ $confirm eq "always" or
1118
+ ($confirm =~ /^(?:auto|cc)$/ && @cc) or
1119
+ ($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
1120
+ $needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
1121
+
1122
+ @cc = (@initial_cc, @cc);
1123
+
1124
send_message();
1125
1126
# set up for the next message
1135
$message_id = undef;
1136
}
1137
1097
-if ($compose) {
1098
- cleanup_compose_files();
1099
-}
1138
+cleanup_compose_files();
1139
1140
sub cleanup_compose_files() {
1102
- unlink($compose_filename, $compose_filename . ".final");
1103
-
1141
+ unlink($compose_filename, $compose_filename . ".final") if $compose;
1142
}
1143
1144
$smtp->quit if $smtp;