Skip to content

Commit 62e0069

Browse files
Krzysztof Mazurgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc01f88 commit 62e0069

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Documentation/git-send-email.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ The --to option must be repeated for each user you want on the to list.
126126
+
127127
Note that no attempts whatsoever are made to validate the encoding.
128128

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+
129133

130134
Sending
131135
~~~~~~~

git-send-email.perl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ sub usage {
5656
--in-reply-to <str> * Email "In-Reply-To:"
5757
--annotate * Review each patch that will be sent in an editor.
5858
--compose * Open an editor for introduction.
59+
--compose-encoding <str> * Encoding to assume for introduction.
5960
--8bit-encoding <str> * Encoding to assume 8bit mails if undeclared
6061
6162
Sending:
@@ -198,6 +199,7 @@ sub do_edit {
198199
my ($validate, $confirm);
199200
my (@suppress_cc);
200201
my ($auto_8bit_encoding);
202+
my ($compose_encoding);
201203

202204
my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
203205

@@ -231,6 +233,7 @@ sub do_edit {
231233
"confirm" => \$confirm,
232234
"from" => \$sender,
233235
"assume8bitencoding" => \$auto_8bit_encoding,
236+
"composeencoding" => \$compose_encoding,
234237
);
235238

236239
my %config_path_settings = (
@@ -315,6 +318,7 @@ sub signal_handler {
315318
"validate!" => \$validate,
316319
"format-patch!" => \$format_patch,
317320
"8bit-encoding=s" => \$auto_8bit_encoding,
321+
"compose-encoding=s" => \$compose_encoding,
318322
"force" => \$force,
319323
);
320324

@@ -638,10 +642,13 @@ sub get_patch_subject {
638642
$summary_empty = 0 unless (/^\n$/);
639643
} elsif (/^\n$/) {
640644
$in_body = 1;
645+
if (!defined $compose_encoding) {
646+
$compose_encoding = "UTF-8";
647+
}
641648
if ($need_8bit_cte) {
642649
print $c2 "MIME-Version: 1.0\n",
643650
"Content-Type: text/plain; ",
644-
"charset=UTF-8\n",
651+
"charset=$compose_encoding\n",
645652
"Content-Transfer-Encoding: 8bit\n";
646653
}
647654
} elsif (/^MIME-Version:/i) {

t/t9001-send-email.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,61 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '
854854
grep "^From: Füñný Nâmé <[email protected]>" msgtxt1
855855
'
856856

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 <[email protected]>" \
868+
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 <[email protected]>" \
886+
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 <[email protected]>" \
905+
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+
857912
test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
858913
echo master > master &&
859914
git add master &&

0 commit comments

Comments
 (0)