#! /tools/ns/bin/perl5.004 # -*- Mode: perl; indent-tabs-mode: nil -*- # Arguments: # # -u Base URL for the Bonsai directory; "/cvsview2.cgi" will get # appended to this with appropriate args. # -h Host whose SMTP server we will contact to send mail. # -s String specifying dir and filenames. As generated by "%s" # in a CVSROOT/loginfo file # -f A regexp. If present, then only checkins to files whose # name (without the directory) matches the regexp will generate mail. # # The remaining args are email addresses of people who should get notified. use Socket; sub get_response_code { my ($expecting) = @_; # if ($flag_debug) { # print STDERR "SMTP: Waiting for code $expecting\n"; # } while (1) { my $line = ; # if ($flag_debug) { # print STDERR "SMTP: $line"; # } if ($line =~ /^[0-9]*-/) { next; } if ($line =~ /(^[0-9]*) /) { my $code = $1; if ($code == $expecting) { # if ($flag_debug) { # print STDERR "SMTP: got it.\n"; # } return; } die "Bad response from SMTP -- $line"; } } } my $debug = 0; my $mailhost = "127.0.0.1"; my $urlbase = ""; my $cvsargs = ""; my $cvsroot = ""; my @mailto; my $fileregexp = ""; while (@ARGV) { my $arg = shift @ARGV; if ($arg eq '-d') { $debug = 1; print STDERR "Debug turned on...\n"; } elsif ($arg eq '-r') { $cvsroot = shift @ARGV; } elsif ($arg eq '-h') { $mailhost = shift @ARGV; } elsif ($arg eq '-u') { $urlbase = shift @ARGV; } elsif ($arg eq '-s') { $cvsargs = shift @ARGV; } elsif ($arg eq '-f') { $fileregexp = shift @ARGV; } else { push(@mailto, $arg); } } my $url = ""; if ($urlbase ne "" && $cvsargs ne "") { my @list = split(/ /, $cvsargs); my $dir = shift @list; if ($fileregexp ne "") { if (grep(m/$fileregexp/, @list) <= 0) { exit; } } $url = $urlbase . "/cvsview2.cgi?command=DIRECTORY&subdir=$dir&files=" . join('+', @list); } my $message = ""; while (<>) { my $line = $_; if ($line =~ m@^Revision/Branch: (.*)$@) { if ($url ne "") { $url .= "&branch=$1"; } } $message .= $line; } if ($url ne "") { if ($cvsroot ne "") { $url .= "&root=$cvsroot"; } $message = "Diffs: $url\n\n" . $message; } chop(my $hostname = `hostname`); my ($remote,$port, $iaddr, $paddr, $proto, $line); $remote = $mailhost; $port = 25; if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(S, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(S, $paddr) || die "connect: $!"; select(S); $| = 1; select(STDOUT); get_response_code(220); print S "EHLO $hostname\n"; get_response_code(250); print S "MAIL FROM: cvsmailfilter@$hostname\n"; get_response_code(250); foreach $i (@mailto) { print S "RCPT TO: $i\n"; get_response_code(250); } print S "DATA\n"; get_response_code(354); print S "Subject: $cvsargs\n"; print S "\n"; print S $message . "\n"; print S ".\n"; get_response_code(250); print S "QUIT\n"; close(S);