135 lines
3.3 KiB
Perl
Executable File
135 lines
3.3 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 = "smtp.mozilla.org";
|
|
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 --fqdn`);
|
|
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;
|
|
$headers{'MIME-Version'} = '1.0';
|
|
$headers{'Content-Type'} = 'text/plain; charset=UTF-8'; # assume everything is UTF-8
|
|
$headers{'Content-Transfer-Encoding'} = '8bit';
|
|
$headers{'Content-Disposition'} = 'inline';
|
|
|
|
$mailer->open(\%headers);
|
|
print $mailer $message;
|
|
$mailer->close;
|