*** /home/bradford/sw/TWiki20011201/bin/mailnotify Thu Nov 22 02:06:13 2001 --- mailnotify Thu May 23 07:51:24 2002 *************** *** 1,4 **** ! #!/usr/bin/perl -wT # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # --- 1,6 ---- ! #!/home/bradford/bin/perl -wT ! ##!/usr/local/bin/perl -wT ! ##!/usr/bin/perl -wT # # TWiki WikiClone (see wiki.pm for $wikiversion and other info) # *************** *** 78,84 **** my $before = ""; my $after = ""; ( $before, $text, $after) = split( /%REPEAT%/, $text ); ! $emailbody = &TWiki::getRenderedVersion( $before ); $after = &TWiki::getRenderedVersion( $after ); my $prevLastmodify = &TWiki::Store::readFile( "$dataDir/$webName/.mailnotify" ) || "0"; --- 80,87 ---- my $before = ""; my $after = ""; ( $before, $text, $after) = split( /%REPEAT%/, $text ); ! $before = &TWiki::getRenderedVersion( $before ); ! $emailbody = $before; $after = &TWiki::getRenderedVersion( $after ); my $prevLastmodify = &TWiki::Store::readFile( "$dataDir/$webName/.mailnotify" ) || "0"; *************** *** 140,145 **** --- 143,155 ---- $debug && print "$bar[0] "; + #check to see if there is a $bar[0]WebNotify page? + my $webNotifyTopic = $bar[0] . "WebNotify"; + if( &TWiki::Store::topicExists( $webName, $webNotifyTopic) ) { + my $body = $before . $foo . $after; + processTopic ( $web, $webNotifyTopic, $body ); + } + #add new item to topic list in email body $foo = "- $bar[0] ($wikiuser)\n $scriptUrl/view$scriptSuffix/$webName/$bar[0]\n"; $foo =~ s/Main\.//go; *************** *** 185,187 **** --- 195,255 ---- $debug && print "- End Twiki.$webName, mail notification sent\n"; } } + + sub processTopic + { + + my($webName, $webNotifyTopic, $foo) = @_; + + $debug && print "\n\n$webNotifyTopic exists\n\n"; + + my @topicNotifylist = &TWiki::getEmailNotifyList($webName, $webNotifyTopic); + unless ( scalar @topicNotifylist ) { + $debug && print "- Note: Notification list is empty for $webNotifyTopic\n"; + return; + } + + my $from = &TWiki::Prefs::getPreferencesValue("WIKIWEBMASTER"); + + my $scriptUrlPath = $TWiki::scriptUrlPath; + my $scriptUrl = "$TWiki::urlHost$scriptUrlPath"; + my $scriptSuffix = $TWiki::scriptSuffix; + + my $emailbody = $foo; + + my $topic = $webNotifyTopic; + $topic =~ s/WebNotify//go; + + my $topicText = " - $topic @ $scriptUrl/view$scriptSuffix/$webName/$topic\n"; + + my $topicNotifylist = join ', ', @topicNotifylist; + + my $text = &TWiki::Store::readTemplate( "mailnotify" ); + + $text =~ s/%EMAILFROM%/$from/go; + $text =~ s/%EMAILTO%/$topicNotifylist/go; + $text =~ s/%EMAILBODY%/$emailbody/go; + $text =~ s/%TOPICLIST%/$topicText/go; + $text =~ s/%LASTDATE%/&TWiki::formatGmTime( time )/geo; + $text =~ s/%NOTIFYTOPIC%/$webNotifyTopic/geo; + $text = &TWiki::handleCommonTags( $text, $topic ); + + # change absolute addresses to relative ones & do some cleanup + $text =~ s/(href=\")$scriptUrlPath/$1..\/../goi; + $text =~ s/(action=\")$scriptUrlPath/$1..\/../goi; + $text =~ s///goi; + + $debug && print "- Sending mail notification to: $topicNotifylist on $webNotifyTopic\n"; + + my $error = &TWiki::Net::sendEmail( $text ); + if( $error ) { + print STDERR "* $error\n"; + $debug && print "- End Twiki.$webName\n"; + } + + $debug && print "- End Twiki.$webName, mail notification sent for $webNotifyTopic\n"; + } + + + +