Skip to content

Commit

Permalink
git-send-email: introduce compose-encoding
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Krzysztof Mazur authored and Junio C Hamano committed Oct 10, 2012
1 parent dc01f88 commit 62e0069
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Documentation/git-send-email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ The --to option must be repeated for each user you want on the to list.
+
Note that no attempts whatsoever are made to validate the encoding.

--compose-encoding=<encoding>::
Specify encoding of compose message. Default is the value of the
'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.


Sending
~~~~~~~
Expand Down
9 changes: 8 additions & 1 deletion git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sub usage {
--in-reply-to <str> * Email "In-Reply-To:"
--annotate * Review each patch that will be sent in an editor.
--compose * Open an editor for introduction.
--compose-encoding <str> * Encoding to assume for introduction.
--8bit-encoding <str> * Encoding to assume 8bit mails if undeclared
Sending:
Expand Down Expand Up @@ -198,6 +199,7 @@ sub do_edit {
my ($validate, $confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
my ($compose_encoding);

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

Expand Down Expand Up @@ -231,6 +233,7 @@ sub do_edit {
"confirm" => \$confirm,
"from" => \$sender,
"assume8bitencoding" => \$auto_8bit_encoding,
"composeencoding" => \$compose_encoding,
);

my %config_path_settings = (
Expand Down Expand Up @@ -315,6 +318,7 @@ sub signal_handler {
"validate!" => \$validate,
"format-patch!" => \$format_patch,
"8bit-encoding=s" => \$auto_8bit_encoding,
"compose-encoding=s" => \$compose_encoding,
"force" => \$force,
);

Expand Down Expand Up @@ -638,10 +642,13 @@ sub get_patch_subject {
$summary_empty = 0 unless (/^\n$/);
} elsif (/^\n$/) {
$in_body = 1;
if (!defined $compose_encoding) {
$compose_encoding = "UTF-8";
}
if ($need_8bit_cte) {
print $c2 "MIME-Version: 1.0\n",
"Content-Type: text/plain; ",
"charset=UTF-8\n",
"charset=$compose_encoding\n",
"Content-Transfer-Encoding: 8bit\n";
}
} elsif (/^MIME-Version:/i) {
Expand Down
55 changes: 55 additions & 0 deletions t/t9001-send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,61 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '
grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
'

test_expect_success $PREREQ 'sendemail.composeencoding works' '
clean_fake_sendmail &&
git config sendemail.composeencoding iso-8859-1 &&
(echo "#!$SHELL_PATH" &&
echo "echo utf8 body: àéìöú >>\"\$1\""
) >fake-editor-utf8 &&
chmod +x fake-editor-utf8 &&
GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
git send-email \
--compose --subject foo \
--from="Example <nobody@example.com>" \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
$patches &&
grep "^utf8 body" msgtxt1 &&
grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
'

test_expect_success $PREREQ '--compose-encoding works' '
clean_fake_sendmail &&
(echo "#!$SHELL_PATH" &&
echo "echo utf8 body: àéìöú >>\"\$1\""
) >fake-editor-utf8 &&
chmod +x fake-editor-utf8 &&
GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
git send-email \
--compose-encoding iso-8859-1 \
--compose --subject foo \
--from="Example <nobody@example.com>" \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
$patches &&
grep "^utf8 body" msgtxt1 &&
grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
'

test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
clean_fake_sendmail &&
git config sendemail.composeencoding iso-8859-1 &&
(echo "#!$SHELL_PATH" &&
echo "echo utf8 body: àéìöú >>\"\$1\""
) >fake-editor-utf8 &&
chmod +x fake-editor-utf8 &&
GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
git send-email \
--compose-encoding iso-8859-2 \
--compose --subject foo \
--from="Example <nobody@example.com>" \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
$patches &&
grep "^utf8 body" msgtxt1 &&
grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
'

test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
echo master > master &&
git add master &&
Expand Down

0 comments on commit 62e0069

Please sign in to comment.