git-send-email: introduce compose-encoding

The introduction email (--compose option) have encoding hardcoded to UTF-8, but invoked editor may not use UTF-8 encoding. The encoding used by patches can be changed by the "8bit-encoding" option, but this option does not have effect on introduction email and equivalent for introduction email is missing. Added compose-encoding command line option and sendemail.composeencoding configuration option specify encoding of introduction email. Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Krzysztof Mazur committed Oct 10, 2012 at 01:02 UTC 62e0069056ed11294c29bae25df69b6518f6339e
3 files changed +67 -1
Documentation/git-send-email.txt
+4
@@ -126,6 +126,10 @@ The --to option must be repeated for each user you want on the to list.
126 +
127 Note that no attempts whatsoever are made to validate the encoding.
128
129 +--compose-encoding=<encoding>::
130 + Specify encoding of compose message. Default is the value of the
131 + 'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.
132 +
133
134 Sending
135 ~~~~~~~
git-send-email.perl
+8 -1
@@ -56,6 +56,7 @@ git send-email [options] <file | directory | rev-list options >
56 --in-reply-to <str> * Email "In-Reply-To:"
57 --annotate * Review each patch that will be sent in an editor.
58 --compose * Open an editor for introduction.
59 + --compose-encoding <str> * Encoding to assume for introduction.
60 --8bit-encoding <str> * Encoding to assume 8bit mails if undeclared
61
62 Sending:
@@ -198,6 +199,7 @@ my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
199 my ($validate, $confirm);
200 my (@suppress_cc);
201 my ($auto_8bit_encoding);
202 +my ($compose_encoding);
203
204 my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
205
@@ -231,6 +233,7 @@ my %config_settings = (
233 "confirm" => \$confirm,
234 "from" => \$sender,
235 "assume8bitencoding" => \$auto_8bit_encoding,
236 + "composeencoding" => \$compose_encoding,
237 );
238
239 my %config_path_settings = (
@@ -315,6 +318,7 @@ my $rc = GetOptions("h" => \$help,
318 "validate!" => \$validate,
319 "format-patch!" => \$format_patch,
320 "8bit-encoding=s" => \$auto_8bit_encoding,
321 + "compose-encoding=s" => \$compose_encoding,
322 "force" => \$force,
323 );
324
@@ -638,10 +642,13 @@ EOT
642 $summary_empty = 0 unless (/^\n$/);
643 } elsif (/^\n$/) {
644 $in_body = 1;
645 + if (!defined $compose_encoding) {
646 + $compose_encoding = "UTF-8";
647 + }
648 if ($need_8bit_cte) {
649 print $c2 "MIME-Version: 1.0\n",
650 "Content-Type: text/plain; ",
644 - "charset=UTF-8\n",
651 + "charset=$compose_encoding\n",
652 "Content-Transfer-Encoding: 8bit\n";
653 }
654 } elsif (/^MIME-Version:/i) {
t/t9001-send-email.sh
+55
@@ -854,6 +854,61 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '
854 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
855 '
856
857 +test_expect_success $PREREQ 'sendemail.composeencoding works' '
858 + clean_fake_sendmail &&
859 + git config sendemail.composeencoding iso-8859-1 &&
860 + (echo "#!$SHELL_PATH" &&
861 + echo "echo utf8 body: àéìöú >>\"\$1\""
862 + ) >fake-editor-utf8 &&
863 + chmod +x fake-editor-utf8 &&
864 + GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
865 + git send-email \
866 + --compose --subject foo \
867 + --from="Example <nobody@example.com>" \
868 + --to=nobody@example.com \
869 + --smtp-server="$(pwd)/fake.sendmail" \
870 + $patches &&
871 + grep "^utf8 body" msgtxt1 &&
872 + grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
873 +'
874 +
875 +test_expect_success $PREREQ '--compose-encoding works' '
876 + clean_fake_sendmail &&
877 + (echo "#!$SHELL_PATH" &&
878 + echo "echo utf8 body: àéìöú >>\"\$1\""
879 + ) >fake-editor-utf8 &&
880 + chmod +x fake-editor-utf8 &&
881 + GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
882 + git send-email \
883 + --compose-encoding iso-8859-1 \
884 + --compose --subject foo \
885 + --from="Example <nobody@example.com>" \
886 + --to=nobody@example.com \
887 + --smtp-server="$(pwd)/fake.sendmail" \
888 + $patches &&
889 + grep "^utf8 body" msgtxt1 &&
890 + grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
891 +'
892 +
893 +test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
894 + clean_fake_sendmail &&
895 + git config sendemail.composeencoding iso-8859-1 &&
896 + (echo "#!$SHELL_PATH" &&
897 + echo "echo utf8 body: àéìöú >>\"\$1\""
898 + ) >fake-editor-utf8 &&
899 + chmod +x fake-editor-utf8 &&
900 + GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
901 + git send-email \
902 + --compose-encoding iso-8859-2 \
903 + --compose --subject foo \
904 + --from="Example <nobody@example.com>" \
905 + --to=nobody@example.com \
906 + --smtp-server="$(pwd)/fake.sendmail" \
907 + $patches &&
908 + grep "^utf8 body" msgtxt1 &&
909 + grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
910 +'
911 +
912 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
913 echo master > master &&
914 git add master &&