Skip to content

Commit 5095fa6

Browse files
committed
Merge branch 'lh/send-email-hide-x-mailer'
"git send-email" normally identifies itself via X-Mailer: header in the message it sends out. A new command line flag allows the user to squelch the header. * lh/send-email-hide-x-mailer: test/send-email: --[no-]xmailer tests send-email: add --[no-]xmailer option
2 parents 948e814 + 2cf770f commit 5095fa6

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

Documentation/config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,7 @@ sendemail.smtpuser::
23292329
sendemail.thread::
23302330
sendemail.transferencoding::
23312331
sendemail.validate::
2332+
sendemail.xmailer::
23322333
See linkgit:git-send-email[1] for description.
23332334

23342335
sendemail.signedoffcc::

Documentation/git-send-email.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Note that no attempts whatsoever are made to validate the encoding.
141141
configuration value; if that is unspecified, git will use 8bit and not
142142
add a Content-Transfer-Encoding header.
143143

144+
--xmailer::
145+
--no-xmailer::
146+
Add (or prevent adding) the "X-Mailer:" header. By default,
147+
the header is added, but it can be turned off by setting the
148+
`sendemail.xmailer` configuration variable to `false`.
144149

145150
Sending
146151
~~~~~~~

git-send-email.perl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sub usage {
5454
--[no-]bcc <str> * Email Bcc:
5555
--subject <str> * Email "Subject:"
5656
--in-reply-to <str> * Email "In-Reply-To:"
57+
--[no-]xmailer * Add "X-Mailer:" header (default).
5758
--[no-]annotate * Review each patch that will be sent in an editor.
5859
--compose * Open an editor for introduction.
5960
--compose-encoding <str> * Encoding to assume for introduction.
@@ -154,7 +155,7 @@ sub format_2822_time {
154155
# Variables we fill in automatically, or via prompting:
155156
my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
156157
$initial_reply_to,$initial_subject,@files,
157-
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
158+
$author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time);
158159

159160
my $envelope_sender;
160161

@@ -226,7 +227,8 @@ sub do_edit {
226227
"signedoffcc" => [\$signed_off_by_cc, undef], # Deprecated
227228
"validate" => [\$validate, 1],
228229
"multiedit" => [\$multiedit, undef],
229-
"annotate" => [\$annotate, undef]
230+
"annotate" => [\$annotate, undef],
231+
"xmailer" => [\$use_xmailer, 1]
230232
);
231233

232234
my %config_settings = (
@@ -327,6 +329,7 @@ sub signal_handler {
327329
"8bit-encoding=s" => \$auto_8bit_encoding,
328330
"compose-encoding=s" => \$compose_encoding,
329331
"force" => \$force,
332+
"xmailer!" => \$use_xmailer,
330333
);
331334

332335
usage() if $help;
@@ -1181,8 +1184,10 @@ sub send_message {
11811184
Subject: $subject
11821185
Date: $date
11831186
Message-Id: $message_id
1184-
X-Mailer: git-send-email $gitversion
11851187
";
1188+
if ($use_xmailer) {
1189+
$header .= "X-Mailer: git-send-email $gitversion\n";
1190+
}
11861191
if ($reply_to) {
11871192

11881193
$header .= "In-Reply-To: $reply_to\n";

t/t9001-send-email.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,4 +1564,37 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
15641564
grep "^!someone@example\.org!$" commandline1
15651565
'
15661566

1567+
do_xmailer_test () {
1568+
expected=$1 params=$2 &&
1569+
git format-patch -1 &&
1570+
git send-email \
1571+
--from="Example <nobody@example.com>" \
1572+
--to=someone@example.com \
1573+
--smtp-server="$(pwd)/fake.sendmail" \
1574+
$params \
1575+
0001-*.patch \
1576+
2>errors >out &&
1577+
{ grep '^X-Mailer:' out || :; } >mailer &&
1578+
test_line_count = $expected mailer
1579+
}
1580+
1581+
test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1582+
do_xmailer_test 1 "--xmailer" &&
1583+
do_xmailer_test 0 "--no-xmailer"
1584+
'
1585+
1586+
test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1587+
test_config sendemail.xmailer true &&
1588+
do_xmailer_test 1 "" &&
1589+
do_xmailer_test 0 "--no-xmailer" &&
1590+
do_xmailer_test 1 "--xmailer"
1591+
'
1592+
1593+
test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1594+
test_config sendemail.xmailer false &&
1595+
do_xmailer_test 0 "" &&
1596+
do_xmailer_test 0 "--no-xmailer" &&
1597+
do_xmailer_test 1 "--xmailer"
1598+
'
1599+
15671600
test_done

0 commit comments

Comments
 (0)