Skip to content

Commit

Permalink
send-email: automatically determine transfer-encoding
Browse files Browse the repository at this point in the history
git send-email, when invoked without a --transfer-encoding option, sends
8bit data without a MIME version or a transfer encoding.  This has
several downsides.

First, unless the transfer encoding is specified, it defaults to 7bit,
meaning that non-ASCII data isn't allowed.  Second, if lines longer than
998 bytes are used, we will send an message that is invalid according to
RFC 5322.  The --validate option, which is the default, catches this
issue, but it isn't clear to many people how to resolve this.

To solve these issues, default the transfer encoding to "auto", so that
we explicitly specify 8bit encoding when lines don't exceed 998 bytes
and quoted-printable otherwise.  This means that we now always emit
Content-Transfer-Encoding and MIME-Version headers, so remove the
conditionals from this portion of the code.

It is unlikely that the unconditional inclusion of these two headers
will affect the deliverability of messages in anything but a positive
way, since MIME is already widespread and well understood by most email
programs.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bk2204 authored and gitster committed Jul 9, 2018
1 parent f2d06fb commit e67a228
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Documentation/git-send-email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ Note that no attempts whatsoever are made to validate the encoding.
otherwise.
+
Default is the value of the `sendemail.transferEncoding` configuration
value; if that is unspecified, git will use 8bit and not add a
Content-Transfer-Encoding header.
value; if that is unspecified, default to `auto`.

--xmailer::
--no-xmailer::
Expand Down
18 changes: 6 additions & 12 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ sub do_edit {
my (@suppress_cc);
my ($auto_8bit_encoding);
my ($compose_encoding);
my ($target_xfer_encoding);
my $target_xfer_encoding = 'auto';

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

Expand Down Expand Up @@ -1737,17 +1737,11 @@ sub process_file {
}
}
}
if (defined $target_xfer_encoding) {
$xfer_encoding = '8bit' if not defined $xfer_encoding;
($message, $xfer_encoding) = apply_transfer_encoding(
$message, $xfer_encoding, $target_xfer_encoding);
}
if (defined $xfer_encoding) {
push @xh, "Content-Transfer-Encoding: $xfer_encoding";
}
if (defined $xfer_encoding or $has_content_type) {
unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
}
$xfer_encoding = '8bit' if not defined $xfer_encoding;
($message, $xfer_encoding) = apply_transfer_encoding(
$message, $xfer_encoding, $target_xfer_encoding);
push @xh, "Content-Transfer-Encoding: $xfer_encoding";
unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;

$needs_confirm = (
$confirm eq "always" or
Expand Down
21 changes: 21 additions & 0 deletions t/t9001-send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ X-Mailer: X-MAILER-STRING
In-Reply-To: <unique-message-id@example.com>
References: <unique-message-id@example.com>
Reply-To: Reply <reply@example.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -415,6 +417,7 @@ test_expect_success $PREREQ 'reject long lines' '
--from="Example <nobody@example.com>" \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
--transfer-encoding=8bit \
$patches longline.patch \
2>errors &&
grep longline.patch errors
Expand Down Expand Up @@ -609,6 +612,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -653,6 +658,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -688,6 +695,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand All @@ -714,6 +723,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -748,6 +759,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -779,6 +792,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -810,6 +825,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -845,6 +862,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down Expand Up @@ -873,6 +892,8 @@ Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: OK
EOF
Expand Down

0 comments on commit e67a228

Please sign in to comment.