git-send-email: show all headers when sending mail
PATCH 1/1 git-send-email: show all headers when sending mail
As a git newbie, it was confusing to set an In-Reply-To header but then not see it printed when the git-send-email command was run.
This patch prints all headers that would be sent to sendmail or an SMTP server instead of only printing From, Subject, Cc, To. It also removes the now-extraneous Date header after the "Log says" line.
Added test to t/t9001-send-email.sh.
---
I'd like to see this applied to the maint branch.
git-send-email.perl | 4 ++-- t/t9001-send-email.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-)
git-send-email.perl +2 -2
@@ -573,7 +573,7 @@ X-Mailer: git-send-email $gitversion if ($quiet) { printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject); } else { - print (($dry_run ? "Dry-" : "")."OK. Log says:\nDate: $date\n"); + print (($dry_run ? "Dry-" : "")."OK. Log says:\n"); if ($smtp_server !~ m#^/#) { print "Server: $smtp_server\n"; print "MAIL FROM:<$raw_from>\n";
@@ -581,7 +581,7 @@ X-Mailer: git-send-email $gitversion } else { print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n"; } - print "From: $sanitized_sender\nSubject: $subject\nCc: $cc\nTo: $to\n\n"; + print $header, "\n"; if ($smtp) { print "Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
t/t9001-send-email.sh +38 -0
@@ -41,4 +41,42 @@ test_expect_success \ 'Verify commandline' \ 'diff commandline expected' +cat >expected-show-all-headers <<\EOF +0001-Second.patch +(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>' +Dry-OK. Log says: +Server: relay.example.com +MAIL FROM:<[email protected]> +RCPT TO:<[email protected]>,<[email protected]>,<[email protected]>,<[email protected]> +From: Example <[email protected]> +To: [email protected] +Cc: [email protected], A <[email protected]> +Subject: [PATCH 1/1] Second. +Date: Mon, 12 Nov 2007 15:01:19 +0000 +Message-Id: <[email protected]> +X-Mailer: git-send-email 1.5.3.5.38.gb33cf-dirty +In-Reply-To: <[email protected]> +References: <[email protected]> + +Result: OK +EOF + +replace_header () { + EXPECTED=expected-show-all-headers && + ACTUAL=actual-show-all-headers && + REPLACEMENT=`cat ${ACTUAL} | grep "^$1:"` && + if [ ! -z "${REPLACEMENT}" ]; then \ + cat ${EXPECTED} | sed -e "s/^$1: .*\$/${REPLACEMENT}/" > ${EXPECTED}.$$ && \ + mv -f ${EXPECTED}.$$ ${EXPECTED} + fi +} + +test_expect_success 'Show all headers' ' + git send-email --dry-run --from="Example <[email protected]>" [email protected] [email protected] [email protected] --in-reply-to="<[email protected]>" --smtp-server relay.example.com $patches > actual-show-all-headers && + replace_header "Date" && + replace_header "Message-Id" && + replace_header "X-Mailer" && + diff -u expected-show-all-headers actual-show-all-headers +' + test_done
Signature · 1 line
1.5.3.4
t/t9001-send-email.sh test_expect_success \ · line 72
Quoted 9 lines · David D. Kilzer
t/t9001-send-email.sh +9
-0+replace_header () { + EXPECTED=expected-show-all-headers && + ACTUAL=actual-show-all-headers && + REPLACEMENT=`cat ${ACTUAL} | grep "^$1:"` && + if [ ! -z "${REPLACEMENT}" ]; then \ + cat ${EXPECTED} | sed -e "s/^$1: .*\$/${REPLACEMENT}/" > ${EXPECTED}.$$ && \ + mv -f ${EXPECTED}.$$ ${EXPECTED} + fi +}
If the actual output did not have an asked-for field, REPLACEMENT will be empty and the breakage will go unnoticed, won't it?
It would probably be better to write it this way:
test_expect_success 'Show all headers' '
git send-email \
--dry-run \
--from="Example <[email protected]>" \
[email protected] \
[email protected] \
[email protected] \
--in-reply-to="<[email protected]>" \
--smtp-sever relay.example.com \
$patches |
sed -e "s/^\(Date:\).*/1 DATE-STRING/" \
-e "s/^\(Message-Id:\).*/1 ID-STRING/" \
-e "s/^\(X-Mailer:\).*/1 X-MAILER-STRING/" \
>actual &&
diff -u expected actual
'and prepare the expected output with the varying field already replaced with the placeholder string.
Oh, by the way, do not cat a single file and pipe it to another command. There may still be a few such stupidity in our test scripts but let's not add even more of them...
PATCH v2 1/1 git-send-email: show all headers when sending mail
As a git newbie, it was confusing to set an In-Reply-To header but then not see it printed when the git-send-email command was run.
This patch prints all headers that would be sent to sendmail or an SMTP server instead of only printing From, Subject, Cc, To. It also removes the now-extraneous Date header after the "Log says" line.
Added test to t/t9001-send-email.sh.
---
Updated t/t9001-send-email.sh per feedback from Junio C Hamano.
git-send-email.perl | 4 ++-- t/t9001-send-email.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-)
git-send-email.perl +2 -2
@@ -575,7 +575,7 @@ X-Mailer: git-send-email $gitversion if ($quiet) { printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject); } else { - print (($dry_run ? "Dry-" : "")."OK. Log says:\nDate: $date\n"); + print (($dry_run ? "Dry-" : "")."OK. Log says:\n"); if ($smtp_server !~ m#^/#) { print "Server: $smtp_server\n"; print "MAIL FROM:<$raw_from>\n";
@@ -583,7 +583,7 @@ X-Mailer: git-send-email $gitversion } else { print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n"; } - print "From: $sanitized_sender\nSubject: $subject\nCc: $cc\nTo: $to\n\n"; + print $header, "\n"; if ($smtp) { print "Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
t/t9001-send-email.sh +37 -0
@@ -41,4 +41,41 @@ test_expect_success \ 'Verify commandline' \ 'diff commandline expected' +cat >expected-show-all-headers <<\EOF +0001-Second.patch +(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>' +Dry-OK. Log says: +Server: relay.example.com +MAIL FROM:<[email protected]> +RCPT TO:<[email protected]>,<[email protected]>,<[email protected]>,<[email protected]> +From: Example <[email protected]> +To: [email protected] +Cc: [email protected], A <[email protected]> +Subject: [PATCH 1/1] Second. +Date: DATE-STRING +Message-Id: MESSAGE-ID-STRING +X-Mailer: X-MAILER-STRING +In-Reply-To: <[email protected]> +References: <[email protected]> + +Result: OK +EOF + +test_expect_success 'Show all headers' ' + git send-email \ + --dry-run \ + --from="Example <[email protected]>" \ + [email protected] \ + [email protected] \ + [email protected] \ + --in-reply-to="<[email protected]>" \ + --smtp-server relay.example.com \ + $patches | + sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ + -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ + -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ + >actual-show-all-headers && + diff -u expected-show-all-headers actual-show-all-headers +' + test_done
Signature · 1 line
1.5.3.4
Thanks. Looks nice and obviously correct.
One thing that has been bugging me for a long time now stands out like a sore thumb much more: empty Cc: is shown.
$ git-send-email --dry-run [email protected] 0001-branch-contains.txt Who should the emails appear to be from? [Junio C Hamano <[email protected]>] Emails will be sent from: Junio C Hamano <[email protected]> Message-ID to be used as In-Reply-To for the first email? 0001-branch-contains.txt Dry-OK. Log says: Date: Mon, 19 Nov 2007 00:10:04 -0800 Server: my.isp.net MAIL FROM:<[email protected]> RCPT TO:<[email protected]> From: Junio C Hamano <[email protected]> Subject: [PATCH] branch --contains=<commit> Cc: To: [email protected]
Result: OK
PATCH 1/1 Don't print an empty Cc header in SMTP mode when there's no cc recipient defined
---
There's some duplicate code between "what we do for sendmail" and "what we do for SMTP" paths that should be fixed - this doesn't do that, it only makes the SMTP path skip empty Cc lines...
git-send-email.perl | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
git-send-email.perl +5 -1
@@ -651,7 +651,11 @@ X-Mailer: git-send-email $gitversion } else { print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n"; } - print "From: $sanitized_sender\nSubject: $subject\nCc: $cc\nTo: $to\n\n"; + print "From: $sanitized_sender\n" + . "Subject: $subject\n" + . ($cc ? "Cc: $cc\n" : "") + . "To: $to\n" + . "\n"; if ($smtp) { print "Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
Signature · 1 line
1.5.3.5.561.g140d
I can't seem to reproduce this. Could you send me (off-list) 0001-branch-contains.txt and any relevant config bits?
Dave
Quoted 22 lines · Junio C Hamano
Thanks. Looks nice and obviously correct.
One thing that has been bugging me for a long time now stands out like a sore thumb much more: empty Cc: is shown.
$ git-send-email --dry-run [email protected] 0001-branch-contains.txt Who should the emails appear to be from? [Junio C Hamano <[email protected]>] Emails will be sent from: Junio C Hamano <[email protected]> Message-ID to be used as In-Reply-To for the first email? 0001-branch-contains.txt Dry-OK. Log says: Date: Mon, 19 Nov 2007 00:10:04 -0800 Server: my.isp.net MAIL FROM:<[email protected]> RCPT TO:<[email protected]> From: Junio C Hamano <[email protected]> Subject: [PATCH] branch --contains=<commit> Cc: To: [email protected]Result: OK
Quoted 9 lines · David D. Kilzer
Quoted 4 lines · Junio C Hamano
Thanks. Looks nice and obviously correct.
One thing that has been bugging me for a long time now stands out like a sore thumb much more: empty Cc: is shown.
I can't seem to reproduce this. Could you send me (off-list) 0001-branch-contains.txt and any relevant config bits?
You need to make git-send-email not have an implicit Cc (from signed-off-by or some such), then it'll appear.
I sent a patch yesterday for it,
Subject: [PATCH] Don't print an empty Cc header in SMTP mode when there's no cc recipient defined
Message-Id: <[email protected]>
- ask
Signature · 1 line
http://develooper.com/ - http://askask.com/