Merge branch 'al/send-email-auto-cte-fixup'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:25 +0000 (22:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:25 +0000 (22:37 +0900)
"git send-email --transfer-encoding=..." in recent versions of Git
sometimes produced an empty "Content-Transfer-Encoding:" header,
which has been corrected.

* al/send-email-auto-cte-fixup:
send-email: avoid empty transfer encoding header

1  2 
git-send-email.perl
t/t9001-send-email.sh
diff --combined git-send-email.perl
index dc7e738e9ce462c85378b82b396dbda0728b971f,6b5d746bdef5a0aaf70a68ee03eb48aaaeefcbbf..4b9d3ad1bdc56881add391def6ed52645ddb89a7
@@@ -82,11 -82,8 +82,11 @@@ git send-email --dump-aliase
                                       Pass an empty string to disable certificate
                                       verification.
      --smtp-domain           <str>  * The domain name sent to HELO/EHLO handshake
 -    --smtp-auth             <str>  * Space-separated list of allowed AUTH mechanisms.
 +    --smtp-auth             <str>  * Space-separated list of allowed AUTH mechanisms, or
 +                                     "none" to disable authentication.
                                       This setting forces to use one of the listed mechanisms.
 +    --no-smtp-auth                   Disable SMTP authentication. Shorthand for
 +                                     `--smtp-auth=none`
      --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.
  
      --batch-size            <int>  * send max <int> message per connection.
@@@ -97,7 -94,7 +97,7 @@@
      --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.
@@@ -344,7 -341,6 +344,7 @@@ $rc = GetOptions
                    "smtp-debug:i" => \$debug_net_smtp,
                    "smtp-domain:s" => \$smtp_domain,
                    "smtp-auth=s" => \$smtp_auth,
 +                  "no-smtp-auth" => sub {$smtp_auth = 'none'},
                    "identity=s" => \$identity,
                    "annotate!" => \$annotate,
                    "no-annotate" => sub {$annotate = 0},
@@@ -458,13 -454,13 +458,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'};
@@@ -475,7 -471,7 +475,7 @@@ $suppress_cc{'self'} = $suppress_from i
  $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'};
@@@ -1245,7 -1241,7 +1245,7 @@@ sub smtp_host_string 
  # (smtp_user was not specified), and 0 otherwise.
  
  sub smtp_auth_maybe {
 -      if (!defined $smtp_authuser || $auth) {
 +      if (!defined $smtp_authuser || $auth || (defined $smtp_auth && $smtp_auth eq "none")) {
                return 1;
        }
  
@@@ -1483,7 -1479,7 +1483,7 @@@ EO
                                                         SSL => 1);
                        }
                }
 -              else {
 +              elsif (!$smtp) {
                        $smtp_server_port ||= 25;
                        $smtp ||= Net::SMTP->new($smtp_server,
                                                 Hello => $smtp_domain,
                                        $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);
@@@ -1685,7 -1682,7 +1685,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:
                        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"),
@@@ -1848,7 -1835,7 +1848,7 @@@ sub apply_transfer_encoding 
        my $from = shift;
        my $to = shift;
  
-       return $message if ($from eq $to and $from ne '7bit');
+       return ($message, $to) if ($from eq $to and $from ne '7bit');
  
        require MIME::QuotedPrint;
        require MIME::Base64;
diff --combined t/t9001-send-email.sh
index 1ef1a19003db5c9be94197e9d6cb25110591705b,8e36a67b3ac5329426da3c093fbf4655b3978bd9..ee1efcc59dcddfdb7e1b448999531e2c1937444a
@@@ -253,9 -253,10 +253,9 @@@ test_suppress_self () 
  
        mv msgtxt1 msgtxt1-$3 &&
        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
 -      >"expected-no-cc-$3" &&
  
        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
 -       test_cmp expected-no-cc-$3 actual-no-cc-$3)
 +       test_must_be_empty actual-no-cc-$3)
  }
  
  test_suppress_self_unquoted () {
@@@ -331,7 -332,7 +331,7 @@@ test_expect_success $PREREQ 'Show all h
  
  test_expect_success $PREREQ 'Prompting works' '
        clean_fake_sendmail &&
 -      (echo "to@example.com"
 +      (echo "to@example.com" &&
         echo ""
        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
                        --validate \
                        $patches longline.patch
        '
+ done
+ for enc in 7bit 8bit quoted-printable base64
+ do
+       test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
+               clean_fake_sendmail &&
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/fake.sendmail" \
+                       --transfer-encoding=$enc \
+                       $patches &&
+               grep "Content-Transfer-Encoding: $enc" msgtxt1
+       '
  done
  
  test_expect_success $PREREQ 'Invalid In-Reply-To' '
  
  test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
        clean_fake_sendmail &&
 -      (echo "From Example <from@example.com>"
 -       echo "To Example <to@example.com>"
 +      (echo "From Example <from@example.com>" &&
 +       echo "To Example <to@example.com>" &&
         echo ""
        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
@@@ -2022,11 -2038,11 +2037,11 @@@ test_expect_success $PREREQ 'invoke hoo
  
                # Verify error message when a patch is rejected by the hook
                sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
 -              git send-email \
 +              test_must_fail git send-email \
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
                        --smtp-server="$(pwd)/../fake.sendmail" \
 -                      ../another.patch 2>err
 +                      ../another.patch 2>err &&
                test_i18ngrep "rejected by sendemail-validate hook" err
        )
  '