Mozilla/CVSROOT/cvsmailfilter.pl
justdave%bugzilla.org 03a16944ac Update cvsmailfilter.pl to optionally show the name of the person who made the commit.
Adding the flag to activate that option to the loginfo entries for cvs-checkins@bugzilla.org and sysalerts@mozilla.org


git-svn-id: svn://10.0.0.236/trunk@156300 18797224-902f-48f8-a5cc-f745e15eee43
2004-05-12 16:33:34 +00:00

173 lines
4.0 KiB
Perl
Executable File

#!/usr/bin/perl
# -*- Mode: perl; indent-tabs-mode: nil -*-
# Arguments:
#
# -a Only send checkin messages which contain added files. All other checkin
# messages will be ignored.
# -u <url> Base URL for the Bonsai directory; "/cvsview2.cgi" will get
# appended to this with appropriate args.
# -h <hostname> Host whose SMTP server we will contact to send mail.
# -s <string> String specifying dir and filenames. As generated by "%s"
# in a CVSROOT/loginfo file
# -f <file> 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 = <S>;
# 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 $addsonly = 0;
my $showcommitter = 0;
my $mailhost = "127.0.0.1";
my $urlbase = "";
my $cvsargs = "";
my $cvsroot = "";
my @mailto;
my $fileregexp = "";
my $username = $ENV{"CVS_USER"} || getlogin || (getpwuid($<))[0] || "nobody";
while (@ARGV) {
my $arg = shift @ARGV;
if ($arg eq '-d') {
$debug = 1;
print STDERR "Debug turned on...\n";
} elsif ($arg eq '-c') {
$showcommitter = 1;
} 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;
} elsif ($arg eq '-a') {
$addsonly = 1;
} 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('%2B', @list);
}
my $message = "";
if ($showcommitter) {
$message .= "Changes committed by $username:\n\n";
}
my $filesadded = 0;
while (<>) {
my $line = $_;
if ($line =~ m@^ Tag: (.*)$@) {
if ($url ne "") {
$url .= "&branch=$1";
}
}
# if we see that files have been added on this checkin, remember that fact
#
if ($line =~ m@^Added Files:@) {
$filesadded = 1;
}
$message .= $line;
}
# bail out if this is an adds-only run and no files have been added
#
if ($addsonly == 1 && $filesadded == 0 ) {
exit 0;
}
if ($url ne "") {
if ($cvsroot ne "") {
$url .= "&root=$cvsroot";
}
$message = "Diffs: $url\n\n" . $message;
}
chop(my $hostname = `/bin/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);