@matheusbsbs / matheus-bagliano / commits / 0706bd19ef
Fork 0

send-email: specify content-type of --compose body

If the compose message contains non-ascii characters, then we assume it is in utf-8 and include the appropriate MIME headers. If the user has already included a MIME-Version header, then we assume they know what they are doing and don't add any headers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 28, 2008 at 17:28 UTC 0706bd19ef9b41e7519df2c73796ef93484272fd
2 files changed +68
git-send-email.perl
+24
@@ -518,8 +518,22 @@ EOT
518 open(C,"<",$compose_filename)
519 or die "Failed to open $compose_filename : " . $!;
520
521 + my $need_8bit_cte = file_has_nonascii($compose_filename);
522 + my $in_body = 0;
523 while(<C>) {
524 next if m/^GIT: /;
525 + if (!$in_body && /^\n$/) {
526 + $in_body = 1;
527 + if ($need_8bit_cte) {
528 + print C2 "MIME-Version: 1.0\n",
529 + "Content-Type: text/plain; ",
530 + "charset=utf-8\n",
531 + "Content-Transfer-Encoding: 8bit\n";
532 + }
533 + }
534 + if (!$in_body && /^MIME-Version:/i) {
535 + $need_8bit_cte = 0;
536 + }
537 print C2 $_;
538 }
539 close(C);
@@ -956,3 +970,13 @@ sub validate_patch {
970 }
971 return undef;
972 }
973 +
974 +sub file_has_nonascii {
975 + my $fn = shift;
976 + open(my $fh, '<', $fn)
977 + or die "unable to open $fn: $!\n";
978 + while (my $line = <$fh>) {
979 + return 1 if $line =~ /[^[:ascii:]]/;
980 + }
981 + return 0;
982 +}
t/t9001-send-email.sh
+44
@@ -166,4 +166,48 @@ test_expect_success 'second message is patch' '
166 grep "Subject:.*Second" msgtxt2
167 '
168
169 +test_expect_success '--compose adds MIME for utf8 body' '
170 + clean_fake_sendmail &&
171 + (echo "#!/bin/sh" &&
172 + echo "echo utf8 body: àéìöú >>\$1"
173 + ) >fake-editor-utf8 &&
174 + chmod +x fake-editor-utf8 &&
175 + echo y | \
176 + GIT_EDITOR=$(pwd)/fake-editor-utf8 \
177 + GIT_SEND_EMAIL_NOTTY=1 \
178 + git send-email \
179 + --compose --subject foo \
180 + --from="Example <nobody@example.com>" \
181 + --to=nobody@example.com \
182 + --smtp-server="$(pwd)/fake.sendmail" \
183 + $patches &&
184 + grep "^utf8 body" msgtxt1 &&
185 + grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
186 +'
187 +
188 +test_expect_success '--compose respects user mime type' '
189 + clean_fake_sendmail &&
190 + (echo "#!/bin/sh" &&
191 + echo "(echo MIME-Version: 1.0"
192 + echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
193 + echo " echo Content-Transfer-Encoding: 8bit"
194 + echo " echo Subject: foo"
195 + echo " echo "
196 + echo " echo utf8 body: àéìöú) >\$1"
197 + ) >fake-editor-utf8-mime &&
198 + chmod +x fake-editor-utf8-mime &&
199 + echo y | \
200 + GIT_EDITOR=$(pwd)/fake-editor-utf8-mime \
201 + GIT_SEND_EMAIL_NOTTY=1 \
202 + git send-email \
203 + --compose --subject foo \
204 + --from="Example <nobody@example.com>" \
205 + --to=nobody@example.com \
206 + --smtp-server="$(pwd)/fake.sendmail" \
207 + $patches &&
208 + grep "^utf8 body" msgtxt1 &&
209 + grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
210 + ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
211 +'
212 +
213 test_done