Skip to content

Commit aeb5932

Browse files
committed
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 <[email protected]>
1 parent 0d351e9 commit aeb5932

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

git-send-email.perl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,21 @@ sub extract_valid_address {
412412
# 1 second since the last time we were called.
413413

414414
# 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>";
417415

418416
sub make_message_id
419417
{
420418
my $date = time;
421419
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>";
422430
$message_id = sprintf $message_id_template, "$date$pseudo_rand";
423431
#print "new message id = $message_id\n"; # Was useful for debugging
424432
}
@@ -467,6 +475,8 @@ sub send_message
467475
$ccline = "\nCc: $cc";
468476
}
469477
$from = sanitize_address_rfc822($from);
478+
make_message_id();
479+
470480
my $header = "From: $from
471481
To: $to${ccline}
472482
Subject: $subject
@@ -533,7 +543,6 @@ sub send_message
533543

534544
$reply_to = $initial_reply_to;
535545
$references = $initial_reply_to || '';
536-
make_message_id();
537546
$subject = $initial_subject;
538547

539548
foreach my $t (@files) {
@@ -627,7 +636,6 @@ sub send_message
627636
$references = "$message_id";
628637
}
629638
}
630-
make_message_id();
631639
}
632640

633641
if ($compose) {

0 commit comments

Comments
 (0)