X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-send-email.perl;h=a83c7e90948fc3fe1b1ac82335704d66d060edab;hb=9a1ae9ab03abaffc977421f182997f3e735e7098;hp=a7a77977787d1d1fcc98d9fa4dc745162d6fde04;hpb=c49b5a3c891e34f6fea9f73847322e9447db91df;p=git.git diff --git a/git-send-email.perl b/git-send-email.perl index a7a779777..a83c7e909 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -22,9 +22,55 @@ use Term::ReadLine; use Getopt::Long; use Data::Dumper; +package FakeTerm; +sub new { + my ($class, $reason) = @_; + return bless \$reason, shift; +} +sub readline { + my $self = shift; + die "Cannot use readline on FakeTerm: $$self"; +} +package main; + # most mail servers generate the Date: header, but not all... -$ENV{LC_ALL} = 'C'; -use POSIX qw/strftime/; +sub format_2822_time { + my ($time) = @_; + my @localtm = localtime($time); + my @gmttm = gmtime($time); + my $localmin = $localtm[1] + $localtm[2] * 60; + my $gmtmin = $gmttm[1] + $gmttm[2] * 60; + if ($localtm[0] != $gmttm[0]) { + die "local zone differs from GMT by a non-minute interval\n"; + } + if ((($gmttm[6] + 1) % 7) == $localtm[6]) { + $localmin += 1440; + } elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) { + $localmin -= 1440; + } elsif ($gmttm[6] != $localtm[6]) { + die "local time offset greater than or equal to 24 hours\n"; + } + my $offset = $localmin - $gmtmin; + my $offhour = $offset / 60; + my $offmin = abs($offset % 60); + if (abs($offhour) >= 24) { + die ("local time offset greater than or equal to 24 hours\n"); + } + + return sprintf("%s, %2d %s %d %02d:%02d:%02d %s%02d%02d", + qw(Sun Mon Tue Wed Thu Fri Sat)[$localtm[6]], + $localtm[3], + qw(Jan Feb Mar Apr May Jun + Jul Aug Sep Oct Nov Dec)[$localtm[4]], + $localtm[5]+1900, + $localtm[2], + $localtm[1], + $localtm[0], + ($offset >= 0) ? '+' : '-', + abs($offhour), + $offmin, + ); +} my $have_email_valid = eval { require Email::Valid; 1 }; my $smtp; @@ -46,7 +92,12 @@ my $smtp_server; # Example reply to: #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>'; -my $term = new Term::ReadLine 'git-send-email'; +my $term = eval { + new Term::ReadLine 'git-send-email'; +}; +if ($@) { + $term = new FakeTerm "$@: going non-interactive"; +} # Begin by accumulating all the variables (defined above), that we will end up # needing, first, from the command line: @@ -65,6 +116,20 @@ my $rc = GetOptions("from=s" => \$from, "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc, ); +# Verify the user input + +foreach my $entry (@to) { + die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/; +} + +foreach my $entry (@initial_cc) { + die "Comma in --cc entry: $entry'\n" unless $entry !~ m/,/; +} + +foreach my $entry (@bcclist) { + die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/; +} + # Now, let's fill any that aren't set in with defaults: sub gitvar { @@ -296,7 +361,7 @@ Options: --smtp-server If set, specifies the outgoing SMTP server to use. Defaults to localhost. - --suppress-from Supress sending emails to yourself if your address + --suppress-from Suppress sending emails to yourself if your address appears in a From: line. --quiet Make git-send-email less verbose. One line per email should be @@ -312,16 +377,18 @@ our ($message_id, $cc, %mail, $subject, $reply_to, $references, $message); sub extract_valid_address { my $address = shift; + my $local_part_regexp = '[^<>"\s@]+'; + my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+'; # check for a local address: - return $address if ($address =~ /^([\w\-.]+)$/); + return $address if ($address =~ /^($local_part_regexp)$/); if ($have_email_valid) { - return Email::Valid->address($address); + return scalar 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 - $address =~ /([\w\-.]+@[\w\-.]+)/; + $address =~ /($local_part_regexp\@$domain_regexp)/; return $1; } } @@ -355,7 +422,7 @@ sub send_message my @recipients = unique_email_list(@to); my $to = join (",\n\t", @recipients); @recipients = unique_email_list(@recipients,@cc,@bcclist); - my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++)); + my $date = format_2822_time($time++); my $gitversion = '@@GIT_VERSION@@'; if ($gitversion =~ m/..GIT_VERSION../) { $gitversion = `git --version`; @@ -368,7 +435,6 @@ sub send_message To: $to Cc: $cc Subject: $subject -Reply-To: $from Date: $date Message-Id: $message_id X-Mailer: git-send-email $gitversion @@ -384,7 +450,7 @@ X-Mailer: git-send-email $gitversion defined $pid or die $!; if (!$pid) { exec($smtp_server,'-i', - map { scalar extract_valid_address($_) } + map { extract_valid_address($_) } @recipients) or die $!; } print $sm "$header\n$message";