X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-send-email.perl;h=703dd1ff9ee641b58ad592cfc702de7f96c59eed;hb=afb4ff206967c6b3e481994cc6d0d86139792169;hp=e578aff7ae9c834d57bed84bb3658bafb78eb15e;hpb=4bc87a28be020a6bf7387161c65ea3d8e4a0228b;p=git.git diff --git a/git-send-email.perl b/git-send-email.perl index e578aff7..703dd1ff 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -22,12 +22,12 @@ use Term::ReadLine; use Getopt::Long; use Data::Dumper; use Net::SMTP; -use Email::Valid; # most mail servers generate the Date: header, but not all... $ENV{LC_ALL} = 'C'; use POSIX qw/strftime/; +my $have_email_valid = eval { require Email::Valid; 1 }; my $smtp; sub unique_email_list(@); @@ -37,7 +37,7 @@ sub cleanup_compose_files(); my $compose_filename = ".msg.$$"; # Variables we fill in automatically, or via prompting: -my (@to,@cc,@initial_cc,$initial_reply_to,$initial_subject,@files,$from,$compose); +my (@to,@cc,@initial_cc,$initial_reply_to,$initial_subject,@files,$from,$compose,$time); # Behavior modification variables my ($chain_reply_to, $smtp_server, $quiet, $suppress_from, $no_signed_off_cc) = (1, "localhost", 0, 0, 0); @@ -250,6 +250,16 @@ EOT # Variables we set as part of the loop over files our ($message_id, $cc, %mail, $subject, $reply_to, $message); +sub extract_valid_address { + my $address = shift; + if ($have_email_valid) { + return Email::Valid->address($address); + } else { + # less robust/correct than the monster regexp in Email::Valid, + # but still does a 99% job, and one less dependency + return ($address =~ /([^\"<>\s]+@[^<>\s]+)/); + } +} # Usually don't need to change anything below here. @@ -259,7 +269,7 @@ our ($message_id, $cc, %mail, $subject, $reply_to, $message); # 1 second since the last time we were called. # We'll setup a template for the message id, using the "from" address: -my $message_id_from = Email::Valid->address($from); +my $message_id_from = extract_valid_address($from); my $message_id_template = "<%s-git-send-email-$message_id_from>"; sub make_message_id @@ -273,13 +283,21 @@ sub make_message_id $cc = ""; +$time = time - scalar $#files; sub send_message { my @recipients = unique_email_list(@to); my $to = join (",\n\t", @recipients); @recipients = unique_email_list(@recipients,@cc); - my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime(time)); + my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++)); + my $gitversion = '@@GIT_VERSION@@'; + if ($gitversion =~ m/..GIT_VERSION../) { + $gitversion = `git --version`; + chomp $gitversion; + # keep only what's after the last space + $gitversion =~ s/^.* //; + } my $header = "From: $from To: $to @@ -288,7 +306,7 @@ Subject: $subject Reply-To: $from Date: $date Message-Id: $message_id -X-Mailer: git-send-email @@GIT_VERSION@@ +X-Mailer: git-send-email $gitversion "; $header .= "In-Reply-To: $reply_to\n" if $reply_to; @@ -412,7 +430,7 @@ sub unique_email_list(@) { my @emails; foreach my $entry (@_) { - my $clean = Email::Valid->address($entry); + my $clean = extract_valid_address($entry); next if $seen{$clean}++; push @emails, $entry; }