Skip to content

Commit

Permalink
Item9551: More fixes and debug messages
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/ImmediateNotifyPlugin@8769 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Aug 26, 2010
1 parent 67f12d0 commit 17caa18
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
33 changes: 25 additions & 8 deletions lib/Foswiki/Plugins/ImmediateNotifyPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,36 @@ sub afterSaveHandler {
return;
}

# SMELL: We should not have to parse out topic text. But the old preferences
# cache is still loaded in the afterSaveHandler. So we would miss changes made
# to the IMMEDIATENOTIFY setting in this save.
#my $nameString = Foswiki::Func::getPreferencesValue('IMMEDIATENOTIFY') || '';

my @names;
if ( $text =~ /^\t+\* Set IMMEDIATENOTIFY =(.*)\n[^\t]/sm ) {
@names = split /[\s\r\n]*[,\s][\s\r\n]*/, $1;
$IMREGEX = qr/$Foswiki::regex{setRegex}IMMEDIATENOTIFY\s*=\s*(.*?)$/sm;

if ( $text =~ /$IMREGEX/ ) {
debug("- $pluginName: Found ($2) ");
my $nameString = $2;
chomp $nameString;
@names = split /[\s,]+/, $nameString;
foreach $n (@names) {
debug("- $pluginName: ($n) found in IMMEDIATENOTIFY in topic text");
}
}

my $notifyTopic =
Foswiki::Func::readTopicText( $web, "WebImmediateNotify" );
$mainWeb = $Foswiki::cfg{UsersWebName};
debug("- $pluginName: no WebImmediateNotify topic found in $web") unless ($notifyTopic);

while ( $notifyTopic =~
/(\t+|( )+)\* (?:\%MAINWEB\%|$mainWeb)\.([^\r\n]+)/go )
/(\t+|( )+)\* (?:\%MAINWEB\%|$Foswiki::cfg{UsersWebName})\.([^\r\n]+)/go )
{
push @names, $3 if $3;
debug("- $pluginName: Adding $3") if ($3);
}

unless (@names) {
unless ( scalar @names) {
debug("- $pluginName: No names registered for notification.");
return;
}
Expand All @@ -217,11 +231,14 @@ sub afterSaveHandler {
/(\t+|( )+)\* Set IMMEDIATENOTIFYMETHOD = ([^\r\n]+)/ )
{
@methodList = split / *[, ] */, $3;
}
if (@methodList) {
} else {
@methodList = ("SMTP");
}
if ( scalar @methodList) {
debug("- $pluginName: User $user: @methodList");
}
elsif ( !exists( $group{$member} ) ) {
#elsif ( !exists( $group{$member} ) ) {
else {
debug(
"- $pluginName: User $user chosen no methods, defaulting to SMTP."
);
Expand Down
23 changes: 12 additions & 11 deletions lib/Foswiki/Plugins/ImmediateNotifyPlugin/SMTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub handleNotify {
my ($users) = @_;
my ($skin) = Foswiki::Func::getPreferencesValue("SKIN");
my ($template) = Foswiki::Func::readTemplate( 'smtp', 'immediatenotify' );
&$debug("- SMTP: template read $template");
# &$debug("- SMTP: template read $template");
my ($from) = Foswiki::Func::getPreferencesValue("WIKIWEBMASTER");

$template =~ s/%EMAILFROM%/$from/go;
Expand All @@ -43,22 +43,23 @@ sub handleNotify {
foreach my $userName ( keys %$users ) {

my ($to);

&$debug("- SMTP: userName $userName");
my @emails = Foswiki::Func::wikinameToEmails($userName);
foreach my $email (@emails) {
$to .= $email . ",";
}
if ($to) {
my $msg = $template;
$msg =~ s/%EMAILTO%/$to/go;
&$debug("- SMTP: Sending mail to $to ($userName)");
&$debug("- SMTP: MESSAGE ($msg)");

my $msg = $template;
$msg =~ s/%EMAILTO%/$to/go;
&$debug("- SMTP: Sending mail to $to ($userName)");
&$debug("- SMTP: MESSAGE ($msg)");

my $foswiki = new Foswiki( $Foswiki::cfg{DefaultUserLogin} );
my $foswikiNet = $foswiki->net();
my $error = $foswikiNet->sendEmail($msg);
my $foswiki = new Foswiki( $Foswiki::cfg{DefaultUserLogin} );
my $foswikiNet = $foswiki->net();
my $error = $foswikiNet->sendEmail($msg);

&$debug("- SMTP: Error ($error)") if ($error);
&$debug("- SMTP: Error ($error)") if ($error);
}

}
}
Expand Down
7 changes: 4 additions & 3 deletions templates/smtp.immediatenotify.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Content-Transfer-Encoding: 8bit
This is an automatically generated email.

%USER% has created or changed the topic
%WIKILOGOURL%foswiki/bin/view%SCRIPTSUFFIX%/%WEB%/%TOPICNAME%
%SCRIPTURL{"view"}%/%WEB%/%TOPICNAME%

--
This is an automated email from %SYSTEMWEB%.ImmediateNotifyPlugin.
To unsubscribe, remove yourself from:
%WIKILOGOURL%foswiki/bin/view%SCRIPTSUFFIX%/%WEB%/WebImmediateNotify
To unsubscribe, remove yourself from either or both:
* The IMMEDIATENOTIFY list in the modified topic
* The %SCRIPTURL{"view"}%/%WEB%/WebImmediateNotify topic

0 comments on commit 17caa18

Please sign in to comment.