Skip to content

Commit

Permalink
Item12149: Sync from trunk.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@15581 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Oct 13, 2012
1 parent 5ce98cf commit c05439c
Showing 1 changed file with 52 additions and 19 deletions.
71 changes: 52 additions & 19 deletions core/tools/develop/plague.pl
@@ -1,9 +1,27 @@
# Plague people who we are waiting for feedback from
# Analyses the Waiting for Feedback tasks, Waiting For field, extracts
# wikiname, maps to email address, sends mail.

# usage: plague.pl [--topics "Item123,Item456"] [--nomail]
# with no arguments, searches thru Item*
use strict;
use warnings;

my $itemTopics = "Item*";
my $sendMail = 1;

while (@ARGV) {
my $arg = shift @ARGV;
if ( $arg eq "--topics" ) {
$itemTopics = shift @ARGV;
}
elsif ( $arg eq '--nomail' ) {
$sendMail = undef;
}
}

#print "Searching items $itemTopics\n";

BEGIN {
require 'setlib.cfg';
}
Expand All @@ -17,45 +35,59 @@ BEGIN
$request->path_info('/Tasks/WebHome');
my $session = new Foswiki( $Foswiki::cfg{AdminUserLogin}, $request );

# Search for Waiting for Feedback, and load a struct with the results
my $details = '[' . Foswiki::Func::expandCommonVariables(<<'SEARCH') . ']';
%SEARCH{
"name~'Item*' AND CurrentState='Waiting for Feedback'"
my $sep = "JENNY8675309xyzzy";
my $data = Foswiki::Func::expandCommonVariables(<<"SEARCH");
\%SEARCH{
"CurrentState='Waiting for Feedback'"
type="query"
topic="$itemTopics"
web="Tasks"
nonoise="on"
format="$percntFORMAT{\"$percntENCODE{\"$formfield(WaitingFor)\"
old=\"Main.,Foswiki:,TWiki:\" new=\",,\"}$percnt\" type=\"string\"
format=\"{topic=>'$topic',who=>'$dollaritem'}\" separator=\",\"}$percnt"
separator=","}%
format="topic='\$topic' WaitingFor='\$formfield(WaitingFor)' Summary='\$formfield(Summary)'"
separator="$sep"}\%
SEARCH
my $data = eval($details);

# Process the struct, collating items according to the recipient email
# collate search results into %send, keyed by mail address to be notified.
my %send;
foreach my $entry (@$data) {
next unless $entry->{who};
my @emails = Foswiki::Func::wikinameToEmails( $entry->{who} );
for my $itemData ( split $sep, $data ) {
my ( $topic, $waitingFor, $summary ) =
$itemData =~ m/topic='(.*?)' WaitingFor='(.*?)' Summary='(.*)'/;
next unless $waitingFor;
$waitingFor =~ s/^\s+//;
$waitingFor =~ s/\s+$//;
my @emails;
foreach my $waitname ( split( /[,\s]/, $waitingFor ) ) {
$waitname =~ s/Foswiki://;
my @waitemails = Foswiki::Func::wikinameToEmails($waitname);
push @emails, @waitemails;
}
unless ( scalar(@emails) ) {
print STDERR
"$0: $entry->{topic}: $entry->{who} has no email address\n";
print STDERR "$0: $topic: $waitingFor has no email address\n";
next;
}
foreach my $email (@emails) {
push( @{ $send{$email} }, $entry->{topic} );
push( @{ $send{$email} }, { topic => $topic, summary => $summary } );
}
}

# Send mails by expanding the template
$/ = undef;
my $template = <DATA>;
while ( my ( $email, $items ) = each %send ) {
my $list = join( "\n", map { 'http://foswiki.org/Tasks/' . $_ } @$items );
my $list = join( "\n\n",
map { $_->{summary} . "\nhttp://foswiki.org/Tasks/" . $_->{topic} }
@$items );
my $mail = $template;
$mail =~ s/%EMAILTO%/$email/g;
$mail =~ s/%TASK_LIST%/$list/g;
$mail = Foswiki::Func::expandCommonVariables($mail);
my $e = Foswiki::Func::sendEmail($mail);
print STDERR "$0: error sending mail: $e\n" if $e;
if ($sendMail) {
my $e = Foswiki::Func::sendEmail($mail);
print STDERR "$0: error sending mail: $e\n" if $e;
}
else {
print "$mail\n";
}
}
1;
__DATA__
Expand All @@ -66,6 +98,7 @@ BEGIN
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
This is an automated e-mail from Foswiki.org
The following Tasks are waiting for feedback from you.
Expand Down

0 comments on commit c05439c

Please sign in to comment.