Git 2.3.0 (February 2015) will propose another new option: --transfer-encoding
in order to specify the transfer encoding to use (quoted-printable, 8bit, base64), instead of relying only on --keep-cr
.
git send-email
man page.
git am
man page.
See commit 8d81408 by Paolo Bonzini (bonzini
):
git-send-email
: add --transfer-encoding
option
The mailing-list thread details problems when applying patches with "git am
" in a repository with CRLF line endings.
In the example in the thread, the repository originated from "git-svn
" so it is not possible to use core.eol
and friends on it.
Right now, the best option is to use "git am --keep-cr
".
However, when a patch create new files, the patch application process will reject the new file because it finds a "/dev/null\r
" string instead of "/dev/null
".
The problem is that SMTP transport is CRLF-unsafe.
Sending a patch by email is the same as passing it through "dos2unix | unix2dos
".
The newly introduced CRLFs are normally transparent because git-am
strips them. The keepcr=true
setting preserves them, but it is mostly working by chance and it would be very problematic to have a "git am
" workflow in a repository with mixed LF and CRLF line endings.
The MIME solution to this is the quoted-printable transfer enconding.
This is not something that we want to enable by default, since it makes received emails horrible to look at.
However, it is a very good match for projects that store CRLF line endings in the repository.
The only disadvantage of quoted-printable is that quoted-printable
patches fail to apply if the maintainer uses "git am --keep-cr
".
This is because the decoded patch will have two carriage returns at the end
of the line.
Therefore, add support for base64 transfer encoding too, which makes received emails downright impossible to look at outside a MUA (Mail User Agent), but really just works.
The patch covers all bases, including users that still live in the late 80s, by also providing a 7bit content transfer encoding that refuses to send emails with non-ASCII character in them.
And finally, "8bit" will add a Content-Transfer-Encoding header but otherwise do nothing.
The doc for git send-email will now include:
--transfer-encoding=(7bit|8bit|quoted-printable|base64)
Specify the transfer encoding to be used to send the message over SMTP.
7bit will fail upon encountering a non-ASCII message.
Quoted-printable can be useful when the repository contains files that contain carriage returns, but makes the raw patch email file (as saved from a MUA) much harder to inspect manually.
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.
With Git 2.32 (Q2 2021), "git mailinfo
"(man) (hence "git am
"(man)) learned the "--quoted-cr
" option to control how lines ending with CRLF wrapped in base64 or qp are handled.
See commit 59b519a, commit 133a4fd, commit f1aa299, commit 0b68956 (10 May 2021), and commit dd9323b, commit d582992 (06 May 2021) by Đoàn Trần Công Danh (sgn
).
(Merged by Junio C Hamano -- gitster
-- in commit 483932a, 16 May 2021)
mailinfo
: warn if CRLF found in decoded base64/QP email
Signed-off-by: Đoàn Trần Công Danh
When SMTP servers receive 8-bit email messages, possibly with only LF as line ending, some of them decide to change said LF to CRLF.
Some mailing list softwares, when receive 8-bit email messages, decide to encode those messages in base64 or quoted-printable.
If an email is transfered through above mail servers, then distributed by such mailing list softwares, the recipients will receive an email contains a patch mungled with CRLF encoded inside another encoding.
Thus, such CR (in CRLF) couldn't be dropped by "mailsplit
".
Hence, the mailed patch couldn't be applied cleanly.
Such accidents have been observed in the wild.
Instead of silently rejecting those messages, let's give our users some warnings if such CR (as part of CRLF) is found.
The warning will be:
warning: quoted CRLF detected