Code

send-email: specify content-type of --compose body
[git.git] / git-send-email.perl
index 29b1105c4c3c83258ebdf53c8885f767baa0ace0..71ba44d69d24bebe26efeada8ec45e23c8b4ee4e 100755 (executable)
@@ -317,7 +317,7 @@ if ($suppress_cc{'all'}) {
 
 # If explicit old-style ones are specified, they trump --suppress-cc.
 $suppress_cc{'self'} = $suppress_from if defined $suppress_from;
-$suppress_cc{'sob'} = $signed_off_cc if defined $signed_off_cc;
+$suppress_cc{'sob'} = !$signed_off_cc if defined $signed_off_cc;
 
 # Debugging, print out the suppressions.
 if (0) {
@@ -518,8 +518,22 @@ EOT
        open(C,"<",$compose_filename)
                or die "Failed to open $compose_filename : " . $!;
 
+       my $need_8bit_cte = file_has_nonascii($compose_filename);
+       my $in_body = 0;
        while(<C>) {
                next if m/^GIT: /;
+               if (!$in_body && /^\n$/) {
+                       $in_body = 1;
+                       if ($need_8bit_cte) {
+                               print C2 "MIME-Version: 1.0\n",
+                                        "Content-Type: text/plain; ",
+                                          "charset=utf-8\n",
+                                        "Content-Transfer-Encoding: 8bit\n";
+                       }
+               }
+               if (!$in_body && /^MIME-Version:/i) {
+                       $need_8bit_cte = 0;
+               }
                print C2 $_;
        }
        close(C);
@@ -855,6 +869,7 @@ foreach my $t (@files) {
                        $message .=  $_;
                        if (/^(Signed-off-by|Cc): (.*)$/i) {
                                next if ($suppress_cc{'sob'});
+                               chomp;
                                my $c = $2;
                                chomp $c;
                                next if ($c eq $sender and $suppress_cc{'self'});
@@ -955,3 +970,13 @@ sub validate_patch {
        }
        return undef;
 }
+
+sub file_has_nonascii {
+       my $fn = shift;
+       open(my $fh, '<', $fn)
+               or die "unable to open $fn: $!\n";
+       while (my $line = <$fh>) {
+               return 1 if $line =~ /[^[:ascii:]]/;
+       }
+       return 0;
+}