summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorKrzysztof Mazur <krzysiek@podlesie.net>2012-11-22 18:12:10 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-11-26 23:49:05 (GMT)
commite43122556912b02ec00746c4b528d7408da9a70f (patch)
treefb3999f205b6f0ecf0f9432adfc7ee592921997c /git-send-email.perl
parent95c0d4b68a0fcba3adf45ce3a8f1edf99a9030a1 (diff)
downloadgit-e43122556912b02ec00746c4b528d7408da9a70f.zip
git-e43122556912b02ec00746c4b528d7408da9a70f.tar.gz
git-e43122556912b02ec00746c4b528d7408da9a70f.tar.bz2
git-send-email: remove invalid addresses earlier
Some addresses are passed twice to unique_email_list() and invalid addresses may be reported twice per send_message. Now we warn about them earlier and we also remove invalid addresses. This also removes using of undefined values for string comparison for invalid addresses in cc list processing. Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl52
1 files changed, 39 insertions, 13 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 356f99d..5a783ac 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -786,9 +786,11 @@ sub expand_one_alias {
}
@initial_to = expand_aliases(@initial_to);
-@initial_to = (map { sanitize_address($_) } @initial_to);
+@initial_to = validate_address_list(sanitize_address_list(@initial_to));
@initial_cc = expand_aliases(@initial_cc);
+@initial_cc = validate_address_list(sanitize_address_list(@initial_cc));
@bcclist = expand_aliases(@bcclist);
+@bcclist = validate_address_list(sanitize_address_list(@bcclist));
if ($thread && !defined $initial_reply_to && $prompting) {
$initial_reply_to = ask(
@@ -839,6 +841,28 @@ sub extract_valid_address {
return undef;
}
+sub extract_valid_address_or_die {
+ my $address = shift;
+ $address = extract_valid_address($address);
+ die "error: unable to extract a valid address from: $address\n"
+ if !$address;
+ return $address;
+}
+
+sub validate_address {
+ my $address = shift;
+ if (!extract_valid_address($address)) {
+ print STDERR "W: unable to extract a valid address from: $address\n";
+ return undef;
+ }
+ return $address;
+}
+
+sub validate_address_list {
+ return (grep { defined $_ }
+ map { validate_address($_) } @_);
+}
+
# Usually don't need to change anything below here.
# we make a "fake" message id by taking the current number
@@ -955,6 +979,10 @@ sub sanitize_address {
}
+sub sanitize_address_list {
+ return (map { sanitize_address($_) } @_);
+}
+
# Returns the local Fully Qualified Domain Name (FQDN) if available.
#
# Tightly configured MTAa require that a caller sends a real DNS
@@ -1017,14 +1045,13 @@ sub maildomain {
sub send_message {
my @recipients = unique_email_list(@to);
- @cc = (grep { my $cc = extract_valid_address($_);
+ @cc = (grep { my $cc = extract_valid_address_or_die($_);
not grep { $cc eq $_ || $_ =~ /<\Q${cc}\E>$/ } @recipients
}
- map { sanitize_address($_) }
@cc);
my $to = join (",\n\t", @recipients);
@recipients = unique_email_list(@recipients,@cc,@bcclist);
- @recipients = (map { extract_valid_address($_) } @recipients);
+ @recipients = (map { extract_valid_address_or_die($_) } @recipients);
my $date = format_2822_time($time++);
my $gitversion = '@@GIT_VERSION@@';
if ($gitversion =~ m/..GIT_VERSION../) {
@@ -1267,7 +1294,7 @@ foreach my $t (@files) {
foreach my $addr (parse_address_line($1)) {
printf("(mbox) Adding to: %s from line '%s'\n",
$addr, $_) unless $quiet;
- push @to, sanitize_address($addr);
+ push @to, $addr;
}
}
elsif (/^Cc:\s+(.*)$/) {
@@ -1376,6 +1403,9 @@ foreach my $t (@files) {
($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
+ @to = validate_address_list(sanitize_address_list(@to));
+ @cc = validate_address_list(sanitize_address_list(@cc));
+
@to = (@initial_to, @to);
@cc = (@initial_cc, @cc);
@@ -1431,14 +1461,10 @@ sub unique_email_list {
my @emails;
foreach my $entry (@_) {
- if (my $clean = extract_valid_address($entry)) {
- $seen{$clean} ||= 0;
- next if $seen{$clean}++;
- push @emails, $entry;
- } else {
- print STDERR "W: unable to extract a valid address",
- " from: $entry\n";
- }
+ my $clean = extract_valid_address_or_die($entry);
+ $seen{$clean} ||= 0;
+ next if $seen{$clean}++;
+ push @emails, $entry;
}
return @emails;
}