From ac1596a684a44144efa2d52d9104b0d627e6d9a1 Mon Sep 17 00:00:00 2001 From: Luis Henriques Date: Mon, 24 Mar 2014 21:38:27 +0000 Subject: [PATCH 1/2] send-email: add --[no-]xmailer option Add --[no-]xmailer that allows a user to disable adding the 'X-Mailer:' header to the email being sent. Signed-off-by: Luis Henriques Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/config.txt | 1 + Documentation/git-send-email.txt | 5 +++++ git-send-email.perl | 11 ++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 6ae4d90708..82b1d3d922 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2260,6 +2260,7 @@ sendemail.smtpserveroption:: sendemail.smtpuser:: sendemail.thread:: sendemail.validate:: +sendemail.xmailer:: See linkgit:git-send-email[1] for description. sendemail.signedoffcc:: diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index a60776eb57..a0bd806cfe 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -131,6 +131,11 @@ Note that no attempts whatsoever are made to validate the encoding. Specify encoding of compose message. Default is the value of the 'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed. +--xmailer:: +--no-xmailer:: + Add (or prevent adding) the "X-Mailer:" header. By default, + the header is added, but it can be turned off by setting the + `sendemail.xmailer` configuration variable to `false`. Sending ~~~~~~~ diff --git a/git-send-email.perl b/git-send-email.perl index 9949db01e1..ecd8d6fc12 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -54,6 +54,7 @@ sub usage { --[no-]bcc * Email Bcc: --subject * Email "Subject:" --in-reply-to * Email "In-Reply-To:" + --[no-]xmailer * Add "X-Mailer:" header (default). --[no-]annotate * Review each patch that will be sent in an editor. --compose * Open an editor for introduction. --compose-encoding * Encoding to assume for introduction. @@ -148,7 +149,7 @@ sub format_2822_time { # Variables we fill in automatically, or via prompting: my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh, $initial_reply_to,$initial_subject,@files, - $author,$sender,$smtp_authpass,$annotate,$compose,$time); + $author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time); my $envelope_sender; @@ -219,7 +220,8 @@ sub do_edit { "signedoffcc" => [\$signed_off_by_cc, undef], # Deprecated "validate" => [\$validate, 1], "multiedit" => [\$multiedit, undef], - "annotate" => [\$annotate, undef] + "annotate" => [\$annotate, undef], + "xmailer" => [\$use_xmailer, 1] ); my %config_settings = ( @@ -318,6 +320,7 @@ sub signal_handler { "8bit-encoding=s" => \$auto_8bit_encoding, "compose-encoding=s" => \$compose_encoding, "force" => \$force, + "xmailer!" => \$use_xmailer, ); usage() if $help; @@ -1163,8 +1166,10 @@ sub send_message { Subject: $subject Date: $date Message-Id: $message_id -X-Mailer: git-send-email $gitversion "; + if ($use_xmailer) { + $header .= "X-Mailer: git-send-email $gitversion\n"; + } if ($reply_to) { $header .= "In-Reply-To: $reply_to\n"; From 2cf770f50185fc7a1e3aaa0463eb452d32517f83 Mon Sep 17 00:00:00 2001 From: Luis Henriques Date: Thu, 4 Dec 2014 19:11:30 +0000 Subject: [PATCH 2/2] test/send-email: --[no-]xmailer tests Add tests for the --[no-]xmailer option. Signed-off-by: Luis Henriques Signed-off-by: Junio C Hamano --- t/t9001-send-email.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 19a3ced600..aa6137bfe1 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1407,4 +1407,37 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' grep "^!someone@example\.org!$" commandline1 ' +do_xmailer_test () { + expected=$1 params=$2 && + git format-patch -1 && + git send-email \ + --from="Example " \ + --to=someone@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + $params \ + 0001-*.patch \ + 2>errors >out && + { grep '^X-Mailer:' out || :; } >mailer && + test_line_count = $expected mailer +} + +test_expect_success $PREREQ '--[no-]xmailer without any configuration' ' + do_xmailer_test 1 "--xmailer" && + do_xmailer_test 0 "--no-xmailer" +' + +test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' ' + test_config sendemail.xmailer true && + do_xmailer_test 1 "" && + do_xmailer_test 0 "--no-xmailer" && + do_xmailer_test 1 "--xmailer" +' + +test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' + test_config sendemail.xmailer false && + do_xmailer_test 0 "" && + do_xmailer_test 0 "--no-xmailer" && + do_xmailer_test 1 "--xmailer" +' + test_done