NOTE: This checkin introduces a dependency on the Mail::Mailer perl module within the cvs chroot jail. In our case this shouldn't be a problem because dolog.pl from bonsai already has the same requirement. Patch by Reed Loden <reed@reedloden.com>, r=justdave. git-svn-id: svn://10.0.0.236/trunk@222331 18797224-902f-48f8-a5cc-f745e15eee43
130 lines
3.1 KiB
Perl
Executable File
130 lines
3.1 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 strict;
|
|
use Mail::Mailer;
|
|
|
|
my $debug = 0;
|
|
my $addsonly = 0;
|
|
my $showcommitter = 0;
|
|
|
|
# Set use_sendmail = 0 to send mail via $mailhost using SMTP
|
|
my $use_sendmail = 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(':', @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 = `hostname`);
|
|
my $mailer;
|
|
if ($use_sendmail) {
|
|
$mailer = Mail::Mailer->new("sendmail");
|
|
} else {
|
|
$mailer = Mail::Mailer->new("smtp", Server => $mailhost);
|
|
}
|
|
die("Failed to send mail notification\n") if !defined($mailer);
|
|
my %headers;
|
|
|
|
$headers{'From'} = "$username <cvsmailfilter\@$hostname>";
|
|
$headers{'To'} = \@mailto;
|
|
$headers{'Subject'} = $cvsargs;
|
|
$mailer->open(\%headers);
|
|
print $mailer $message;
|
|
$mailer->close;
|