#!/opt/local/bin/perl5.6.0 -w # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # # Copyright (C) 1999-2000 Peter Thoeny, peter@thoeny.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html use strict; use lib ( '.' ); use lib ( '/local/twiki/megatwiki/lib' ); use TWiki; use TWiki::Net; $| = 1; # no buffering my $debug = 1; &main(); sub main { if ($#ARGV<1) { print "Arguments: web topic\n" . "This will mail the last change to the notify list\n"; exit; } processTopic(@ARGV); } sub processTopic() { my ( $web, $topic) = @_; $web =~ s/\//\./g; my( $topicName, $webName, $dummy, $userName ) = &TWiki::initialize( "/".$web, "nobody", $topic); $webName =~ s/\./\//g; my @notifylist = &TWiki::getEmailNotifyList($webName); unless ( scalar @notifylist ) { $debug && print "- Note: Notification list is empty\n"; return; } my $notifylist = join ', ', @notifylist; my ( $date, $user, $rev, $comment ) = &TWiki::Store::getRevisionInfo( $webName, $topicName, "" ); my ($change, $text); if ($rev > 1) { $change = &TWiki::Store::getRevisionDiff( $webName, $topicName, "1.".($rev-1),"1.".$rev ); # Remove unified header $change =~ s/^---.*\n\+\+\+ .*\n//m; # Remove META:TOPIC tag $change =~ s/\n.%META:TOPIC[^\n]*//mg; # Remove empty change sections $change =~ s/\n@@[^\n]*\n( [^\n]*\n)+@@/@@/mg; $change =~ s/^@@[^\n]*\n( [^\n]*\n)+@@/@@/m; $change =~ s/\n@@[^\n]*\n( [^\n]*\n)+$//m; $change =~ s/^@@[^\n]*\n( [^\n]*\n)+$//m; $text = &TWiki::Store::readTemplate( "mailchange" ); } else { $change = &TWiki::Store::_readVersionNoMeta( $webName, $topicName, "1"); # Remove META:TOPIC tag $change =~ s/\n%META:TOPIC[^\n]*//mg; $text = &TWiki::Store::readTemplate( "mailcreate" ); } # Change tabs to spaces $change =~ s/\t/ /g; # Prepare the mail my $from = &TWiki::Prefs::getPreferencesValue("WIKIWEBMASTER"); $text =~ s/%EMAILFROM%/$TWiki::notifyFrom/go; $text =~ s/%EMAILTO%/$notifylist/go; $text =~ s/%CHANGEDATE%/$date/go; $text =~ s/%CHANGEUSER%/$user/go; $text = &TWiki::handleCommonTags( $text, $topicName, $webName ); # Add topic change afterwards to get raw text $text =~ s/%CHANGES%/$change/go; $debug && print "- Sending mail notification to: $notifylist\n"; my $error = &TWiki::Net::sendEmail( $text ); if( $error ) { print STDERR "* $error\n"; } }