git-send-email: Do not make @-less message ID
When the original $from address fails to yield a valid-looking e-mail address, we created a bogus looking message ID, formatted like this: Message-Id: <11823357623688-git-send-email-> This commit fixes it by moving call to make_message_id() to where it matters, namely, before the $message_id is needed to be placed in the generated e-mail header; this has an important side effect of making it clear that $from is already available. Also throw in Sys::Hostname::hostname() just for fun, although I suspect that the code would never trigger due to the modified call sequence that makes sure $from is always available. This is based on a suggestion by Michael Hendricks. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 20, 2007 at 13:47 UTC
aeb59328453cd4f438345ea79ff04c96bccbbbb8
1 file changed
+12
-4
git-send-email.perl
+12
-4
@@ -412,13 +412,21 @@ sub extract_valid_address {
412
# 1 second since the last time we were called.
413
414
# We'll setup a template for the message id, using the "from" address:
415
-my $message_id_from = extract_valid_address($from);
416
-my $message_id_template = "<%s-git-send-email-$message_id_from>";
415
416
sub make_message_id
417
{
418
my $date = time;
419
my $pseudo_rand = int (rand(4200));
420
+ my $du_part;
421
+ for ($from, $committer, $author) {
422
+ $du_part = extract_valid_address($_);
423
+ last if ($du_part ne '');
424
+ }
425
+ if ($du_part eq '') {
426
+ use Sys::Hostname qw();
427
+ $du_part = 'user@' . Sys::Hostname::hostname();
428
+ }
429
+ my $message_id_template = "<%s-git-send-email-$du_part>";
430
$message_id = sprintf $message_id_template, "$date$pseudo_rand";
431
#print "new message id = $message_id\n"; # Was useful for debugging
432
}
@@ -467,6 +475,8 @@ sub send_message
475
$ccline = "\nCc: $cc";
476
}
477
$from = sanitize_address_rfc822($from);
478
+ make_message_id();
479
+
480
my $header = "From: $from
481
To: $to${ccline}
482
Subject: $subject
@@ -533,7 +543,6 @@ X-Mailer: git-send-email $gitversion
543
544
$reply_to = $initial_reply_to;
545
$references = $initial_reply_to || '';
536
-make_message_id();
546
$subject = $initial_subject;
547
548
foreach my $t (@files) {
@@ -627,7 +636,6 @@ foreach my $t (@files) {
636
$references = "$message_id";
637
}
638
}
630
- make_message_id();
639
}
640
641
if ($compose) {