diff options
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-x | git-send-email.perl | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/git-send-email.perl b/git-send-email.perl index 8ec70e58ed..58c6aa9d0e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -94,7 +94,7 @@ git send-email --dump-aliases --identity <str> * Use the sendemail.<id> options. --to-cmd <str> * Email To: via `<str> \$patch_path` --cc-cmd <str> * Email Cc: via `<str> \$patch_path` - --suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, all. + --suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, misc-by, all. --[no-]cc-cover * Email Cc: addresses in the cover letter. --[no-]to-cover * Email To: addresses in the cover letter. --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on. @@ -231,7 +231,7 @@ my ($validate, $confirm); my (@suppress_cc); my ($auto_8bit_encoding); my ($compose_encoding); -my ($target_xfer_encoding); +my $target_xfer_encoding = 'auto'; my ($debug_net_smtp) = 0; # Net::SMTP, see send_message() @@ -454,13 +454,13 @@ my(%suppress_cc); if (@suppress_cc) { foreach my $entry (@suppress_cc) { die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry) - unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc)$/; + unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/; $suppress_cc{$entry} = 1; } } if ($suppress_cc{'all'}) { - foreach my $entry (qw (cccmd cc author self sob body bodycc)) { + foreach my $entry (qw (cccmd cc author self sob body bodycc misc-by)) { $suppress_cc{$entry} = 1; } delete $suppress_cc{'all'}; @@ -471,7 +471,7 @@ $suppress_cc{'self'} = $suppress_from if defined $suppress_from; $suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc; if ($suppress_cc{'body'}) { - foreach my $entry (qw (sob bodycc)) { + foreach my $entry (qw (sob bodycc misc-by)) { $suppress_cc{$entry} = 1; } delete $suppress_cc{'body'}; @@ -645,7 +645,7 @@ if (@rev_list_opts) { if ($validate) { foreach my $f (@files) { unless (-p $f) { - my $error = validate_patch($f); + my $error = validate_patch($f, $target_xfer_encoding); $error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"), $f, $error); } @@ -1479,7 +1479,7 @@ EOF SSL => 1); } } - else { + elsif (!$smtp) { $smtp_server_port ||= 25; $smtp ||= Net::SMTP->new($smtp_server, Hello => $smtp_domain, @@ -1501,7 +1501,6 @@ EOF $smtp->starttls(ssl_verify_params()) or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr()); } - $smtp_encryption = ''; # Send EHLO again to receive fresh # supported commands $smtp->hello($smtp_domain); @@ -1682,7 +1681,7 @@ sub process_file { # Now parse the message body while(<$fh>) { $message .= $_; - if (/^(Signed-off-by|Cc): (.*)/i) { + if (/^([a-z-]*-by|Cc): (.*)/i) { chomp; my ($what, $c) = ($1, $2); # strip garbage for the address we'll use: @@ -1692,8 +1691,18 @@ sub process_file { if ($sc eq $sender) { next if ($suppress_cc{'self'}); } else { - next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i; - next if $suppress_cc{'bodycc'} and $what =~ /Cc/i; + if ($what =~ /^Signed-off-by$/i) { + next if $suppress_cc{'sob'}; + } elsif ($what =~ /-by$/i) { + next if $suppress_cc{'misc-by'}; + } elsif ($what =~ /Cc/i) { + next if $suppress_cc{'bodycc'}; + } + } + if ($c !~ /.+@.+|<.+>/) { + printf("(body) Ignoring %s from line '%s'\n", + $what, $_) unless $quiet; + next; } push @cc, $c; printf(__("(body) Adding cc: %s from line '%s'\n"), @@ -1737,18 +1746,11 @@ sub process_file { } } } - if (defined $target_xfer_encoding) { - $xfer_encoding = '8bit' if not defined $xfer_encoding; - $message = apply_transfer_encoding( - $message, $xfer_encoding, $target_xfer_encoding); - $xfer_encoding = $target_xfer_encoding; - } - if (defined $xfer_encoding) { - push @xh, "Content-Transfer-Encoding: $xfer_encoding"; - } - if (defined $xfer_encoding or $has_content_type) { - unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version; - } + $xfer_encoding = '8bit' if not defined $xfer_encoding; + ($message, $xfer_encoding) = apply_transfer_encoding( + $message, $xfer_encoding, $target_xfer_encoding); + push @xh, "Content-Transfer-Encoding: $xfer_encoding"; + unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version; $needs_confirm = ( $confirm eq "always" or @@ -1852,13 +1854,16 @@ sub apply_transfer_encoding { $message = MIME::Base64::decode($message) if ($from eq 'base64'); + $to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit' + if $to eq 'auto'; + die __("cannot send message as 7bit") if ($to eq '7bit' and $message =~ /[^[:ascii:]]/); - return $message + return ($message, $to) if ($to eq '7bit' or $to eq '8bit'); - return MIME::QuotedPrint::encode($message, "\n", 0) + return (MIME::QuotedPrint::encode($message, "\n", 0), $to) if ($to eq 'quoted-printable'); - return MIME::Base64::encode($message, "\n") + return (MIME::Base64::encode($message, "\n"), $to) if ($to eq 'base64'); die __("invalid transfer encoding"); } @@ -1877,7 +1882,7 @@ sub unique_email_list { } sub validate_patch { - my $fn = shift; + my ($fn, $xfer_encoding) = @_; if ($repo) { my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'), @@ -1897,11 +1902,15 @@ sub validate_patch { return $hook_error if $hook_error; } - open(my $fh, '<', $fn) - or die sprintf(__("unable to open %s: %s\n"), $fn, $!); - while (my $line = <$fh>) { - if (length($line) > 998) { - return sprintf(__("%s: patch contains a line longer than 998 characters"), $.); + # Any long lines will be automatically fixed if we use a suitable transfer + # encoding. + unless ($xfer_encoding =~ /^(?:auto|quoted-printable|base64)$/) { + open(my $fh, '<', $fn) + or die sprintf(__("unable to open %s: %s\n"), $fn, $!); + while (my $line = <$fh>) { + if (length($line) > 998) { + return sprintf(__("%s: patch contains a line longer than 998 characters"), $.); + } } } return; |