From 26f3e2d48fe6ae26d5bdb8d6afb195b1d46b3ead Mon Sep 17 00:00:00 2001 From: CrawfordCurrie Date: Tue, 26 Jul 2011 07:09:55 +0000 Subject: [PATCH] Item9459: Item10980: synch with trunk git-svn-id: http://svn.foswiki.org/branches/Release01x01@12241 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- MailerContrib/data/System/MailerContrib.txt | 54 ++--------- .../lib/Foswiki/Contrib/MailerContrib.pm | 79 ++++++++++------ .../Foswiki/Contrib/MailerContrib/Change.pm | 64 ++++++++++++- .../Contrib/MailerContrib/Constants.pm | 41 --------- .../Foswiki/Contrib/MailerContrib/MANIFEST | 1 - .../Contrib/MailerContrib/Subscription.pm | 23 +++-- .../Contrib/MailerContrib/WebNotify.pm | 27 +++--- MailerContrib/templates/mailnotify.tmpl | 17 +++- .../unit/MailerContrib/MailerContribSuite.pm | 91 ++++++++++++++++--- 9 files changed, 237 insertions(+), 160 deletions(-) delete mode 100644 MailerContrib/lib/Foswiki/Contrib/MailerContrib/Constants.pm diff --git a/MailerContrib/data/System/MailerContrib.txt b/MailerContrib/data/System/MailerContrib.txt index 44e4fe4c0a..106f020106 100644 --- a/MailerContrib/data/System/MailerContrib.txt +++ b/MailerContrib/data/System/MailerContrib.txt @@ -191,7 +191,10 @@ The changes emails sent to subscribers are based on a Foswiki template called =m | =PLAIN:before= | Section of a plain text email before the changes | | =PLAIN:middle= | Repeated in a plain text email for each changes | | =PLAIN:after= | Section of a plain text email after the changes | -| =MailNotifyBody= | All the above are embedded in this. %HTML_TEXT% expands to the HTML obtained by expanding the =HTML:*= templates, and %PLAIN_TEXT% from the =PLAIN:*= templates. | +| =DIFF:before= | Section of a plain text email before the changes | +| =DIFF:middle= | Repeated in a plain text email for each changes | +| =DIFF:after= | Section of a plain text email after the changes | +| =MailNotifyBody= | All the above are embedded in this. %HTML_TEXT% expands to the HTML obtained by expanding the =HTML:*= templates, %PLAIN_TEXT% from the =PLAIN:*= templates, and %DIFF_TEXT from the =DIFF:*= templates%. | The default template sends multipart emails containing both HTML and plaintext versions.
%X% Avoid editing the distributed =mailnotify.tmpl= file, or you will regret it later when it gets overwritten when you upgrade Foswiki. Instead, you should either use a skin setting to choose the template file, or use the web part of the [[%SYSTEMWEB%.SkinTemplates#FindingTemplates][template search path rules]]. @@ -250,6 +253,8 @@ Many thanks to the following sponsors for supporting this work: | Version: | %$VERSION% | | Release: | %$RELEASE% | | Change History: | | +| 2.5.1 (25 Jul 2011) | Foswiki:Tasks/Item10980: fix case where interaction with SubscribePlugin could potentially break cached CGI (fcgid/mod_perl) | +| 2.5.0 (5 Apr 2011) | Foswiki:Tasks/Item9459: add DIFF template for improved change presentation | | 2.4.4 (5 Apr 2011) | Foswiki:Tasks/Item10545: Fix overriding rules | | 2.4.3 (30 Sep 2010) | Foswikitask:Item6011: document =-user= parameter and update examples in order to make fully functional on versions of Foswiki through 1.0.10; other documentation cleanup -- Foswiki:Main.WillNorris | | 2.4.2 (31 Jul 2010) | Foswikitask:Item9415: Documentation updates | @@ -262,53 +267,6 @@ Many thanks to the following sponsors for supporting this work: | 2.0.2 (20 Sep 2009) | Small documentation update for Foswiki 1.0.7 release (RELEASE and adding parent) | | 2.0.1 (23 Apr 2009) | Foswikitask:Item1501: Minor bug in logfile output fixed | | 2.0.0 (03 Dec 2008) | Re-released for the Foswiki project | -| 15 Oct 2008 | TWikibug:Item: generalised code to enable Foswiki:Extensions.SubscribePlugin to delegate parsing to %TOPIC% - Foswiki:Main.SvenDowideit | -| 14 Oct 2008 | TWikibug:Item6066: fixed issue for user mappings where cuid != login - Foswiki:Main.SvenDowideit | -| 27 Aug 2008 | TWikibug:Item5949: fixed problem with unsubscribe that should result in an empty subscription | -| 03 Aug 2008 | TWiki 4.2.1 release version | -| 27 Jul 2008 | TWikibug:Item5776: Foswiki:Main.KennethLavrsen added note to warn against running multiple instances of mailnotify at the same time. | -| 15 May 2008 | TWikibug:Item5232: Foswiki:Main.CrawfordCurrie added support for non-ascii alphanumerics in topic names to WebNotify. TWikibug:Item5630: Foswiki:Main.SvenDowideit fixed some spelling errors | -| 25 Jan 2008 | TWikibug:Item4812: added TWiki:Main.BobGoldstein's noexpand patch for groups | -| 2 Nov 2007 | TWikibug:Item4818: added quotes to support non-alphabetic and other wierd group names TWikibug:Item4887: corrected minor rendering error TWikibug:Item4917: removed dependence on symbolic web names | -| 9 Sep 2007 | TWikibug:Item4326 workaround for possible error in !WebNotify API in old releases, Should not affect most users. | -| 6 Sep 2007 | TWikibug:Item4488 doc tweaks | -| 14550 | TWikibug:Item4461 - 'Changed' link now points to most recent changes, not the entire history | -| 22 Jun 2007 | TWikibug:Item4284 - added access control checks and email filter | -| 21 May 2007 | TWikibug:Item3969 - 8bit email fix (Foswiki:Main.WillNorris) | -| 13623 | TWikibug:Item4014 no changes was resetting the notify time to 0. Thanks to TWiki:Main.JeffCrawford for nailing this down. | -| 12496 | TWikibug:Item3415 mailnotify did not send notifications to intranet users because of wrong call to findUser. | -| 11672 | Added newsletter support, after much harassment from Foswiki:Main.LynnwoodBrown | -| 11534 | TWikibug:Item2153 Clarified docs. TWikibug:Item2698 Improved error reporting. | -| 8808 | TWikibug:Item1654 mailnotify must enter the command_line context | -| 8625 | TWikibug:Item1508 Making the dashes in the separatator clearer | -| 8606 | TWikibug:Item1508 MailerContrib: Brushing up HTML mailnotify template | -| 8602 | TWikibug:Item1508 MailerContrib: Cleaning up plaintext email template, removing TEXTAREA | -| 8522 | TWikibug:Item1511 arguments to getScriptUrl in wrong order :-( | -| 8434 | TWikibug:Item1465 Fix 'TWiki.' to '%TWIKIEB%.' | -| 8398 | TWikibug:Item1460 polished up the comment a bit | -| 8308 | TWikibug:Item1362 moving mailnotify cron script | -| 7848 | TWikibug:Item1167 forced all mail operations to generate absolute URLs | -| 7568 | TWikibug:tem910 use SCRIPTURL{view} instead of complex url expr | -| 6864 | TWikibug:tem624 mailer templates moved the the right places | -| 6861 | TWikibug:tem624 Added proper templates support for plain text mails | -| 6809 | TWikibug:tem623 don't print anything if verbosity is switched off. | -| 6659 | TWikibug:tem528 Updated MailerContrib. it's working and the sendmail parameter is used. | -| 6474 | TWikibug:tem420 removed spurious remove_obsolete_locks from MailerContrib | -| 5924 | TWikibug:tem153 fix mail URL-fixing scheme | -| 5269 | Minor doc fixes | -| 5266 | Doc tidy-ups, added filtering of _ webs, added obsolete lock script | -| 5264 | Changed default to add web name to user name (I hope) | -| 5263 | Minor doc tidyups | -| 5261 | Documentation changes, and fixed to scan all webs. | -| 5253 | runnable as CGI script, minor bugfixes, removed dependency on DBCacheContrib | -| 5234 | Minor doc changes | -| 5231 | Made a change an object, added unit tests to CVS, lots of testing. | -| 4 March 2005 | 1.010 Dakar release ready. | -| 12 Oct 2004 | 1.004 Added support for anti-subscriptions. Doc fixes from TWiki:Main.PeterThoeny. Bug fixes to permissions code. Back-off and retry if the mailer can't be reached (should really be in Net::sendEmail) | -| 6 Oct 2004 | 1.003 Excluded _ webs from processing, added =bin/remove_obsolete_locks= for full reverse-compatibility | -| 1 Oct 2004 | 1.002 PeterThoeny provided additional documentation | -| 27 Sep 2004 | 1.001 runnable as CGI script, minor bugfixes, removed dependency on DBCacheContrib | -| 8 Sep 2004 | 1.000 Initial version | | Home: | http://foswiki.org/Extensions/%TOPIC% | | Support: | http://foswiki.org/Support/%TOPIC% | diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm b/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm index b4f5c8e1a9..ace11730eb 100644 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm +++ b/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm @@ -27,7 +27,7 @@ use Foswiki::Contrib::MailerContrib::Change (); use Foswiki::Contrib::MailerContrib::UpData (); our $VERSION = '$Rev$'; -our $RELEASE = '2.4.4'; +our $RELEASE = '2.5.1'; our $SHORTDESCRIPTION = 'Supports email notification of changes'; our $verbose = 0; @@ -353,19 +353,10 @@ sub _sendChangesMails { my $template = Foswiki::Func::readTemplate( 'mailnotify', $skin ); Foswiki::Func::popTopicContext(); - my $homeTopic = $Foswiki::cfg{HomeTopicName}; - - my $before_html = Foswiki::Func::expandTemplate('HTML:before'); - my $middle_html = Foswiki::Func::expandTemplate('HTML:middle'); - my $after_html = Foswiki::Func::expandTemplate('HTML:after'); - - my $before_plain = Foswiki::Func::expandTemplate('PLAIN:before'); - my $middle_plain = Foswiki::Func::expandTemplate('PLAIN:middle'); - my $after_plain = Foswiki::Func::expandTemplate('PLAIN:after'); - my $mailtmpl = Foswiki::Func::expandTemplate('MailNotifyBody'); $mailtmpl = - Foswiki::Func::expandCommonVariables( $mailtmpl, $homeTopic, $web ); + Foswiki::Func::expandCommonVariables( + $mailtmpl, $Foswiki::cfg{HomeTopicName}, $web ); if ( $Foswiki::cfg{RemoveImgInMailnotify} ) { # change images to [alt] text if there, else remove image @@ -376,25 +367,13 @@ sub _sendChangesMails { my $sentMails = 0; foreach my $email ( keys %{$changeset} ) { - my $html = ''; - my $plain = ''; - foreach my $change ( sort { $a->{TIME} cmp $b->{TIME} } - @{ $changeset->{$email} } ) - { - - $html .= $change->expandHTML($middle_html); - $plain .= $change->expandPlain($middle_plain); - } - - $plain =~ s/\($Foswiki::cfg{UsersWebName}\./\(/go; my $mail = $mailtmpl; - $mail =~ s/%EMAILTO%/$email/go; - $mail =~ s/%HTML_TEXT%/$before_html$html$after_html/go; - $mail =~ s/%PLAIN_TEXT%/$before_plain$plain$after_plain/go; - $mail =~ s/%LASTDATE%/$lastTime/geo; - $mail = Foswiki::Func::expandCommonVariables( $mail, $homeTopic, $web ); + $mail =~ s/%EMAILTO%/$email/g; + $mail =~ s/%(HTML|PLAIN|DIFF)_TEXT%/ + _generateChangeDetail($email, $changeset, $1, $web)/ge; + $mail =~ s/%LASTDATE%/$lastTime/ge; my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; $mail =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; @@ -406,7 +385,7 @@ sub _sendChangesMails { my $error = Foswiki::Func::sendEmail( $mail, 5 ); if ($error) { - print STDERR "Error sending mail forf $web: $error\n"; + print STDERR "Error sending mail for $web: $error\n"; $report .= $error . "\n"; } else { @@ -419,6 +398,48 @@ sub _sendChangesMails { return $report; } +sub _generateChangeDetail { + my ($email, $changeset, $style, $web) = @_; + + my @wns = Foswiki::Func::emailToWikiNames($email); + my @ep = ($Foswiki::cfg{HomeTopicName}, $web); + + # If there is only one user with this email, we can load preferences + # for them by expanding preferences in the context of their home + # topic. + if ( scalar(@wns) == 1 && Foswiki::Func::topicExists( + $Foswiki::cfg{UsersWebName}, $wns[0]) + && defined &Foswiki::Meta::load ) { + my ($ww, $wt) = Foswiki::Func::normalizeWebTopicName(undef, $wns[0]); + my $userTopic = Foswiki::Meta->load( + $Foswiki::Plugins::SESSION, $ww, $wt); + my $uStyle = $userTopic->getPreference('PREFERRED_MAIL_CHANGE_FORMAT'); + $style = $uStyle if $uStyle && $uStyle =~ /^(HTML|PLAIN|DIFF)$/; + } + + my $template = Foswiki::Func::expandTemplate($style.':middle'); + my $text = ''; + foreach my $change ( sort { $a->{TIME} cmp $b->{TIME} } + @{ $changeset->{$email} } ) { + if ($style eq 'HTML') { + $text .= Foswiki::Func::expandCommonVariables( + $change->expandHTML($template), @ep); + } elsif ($style eq 'PLAIN') { + $text .= Foswiki::Func::expandCommonVariables( + $change->expandPlain($template), @ep); + } elsif ($style eq 'DIFF') { + # Note: no macro expansion; this is a verbatim format + $text .= $change->expandDiff($template); + } + } + return + Foswiki::Func::expandCommonVariables( + Foswiki::Func::expandTemplate($style.':before'), @ep) + . $text + . Foswiki::Func::expandCommonVariables( + Foswiki::Func::expandTemplate($style.':after'), @ep); +} + sub relativeURL { my ( $base, $link ) = @_; return URI->new_abs( $link, URI->new($base) )->as_string; diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Change.pm b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Change.pm index d8bd862d01..b981c21903 100644 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Change.pm +++ b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Change.pm @@ -40,7 +40,7 @@ sub new { $this->{AUTHOR} = Foswiki::Func::getWikiName($author); $this->{TIME} = $time; - ASSERT($rev) if DEBUG; + ASSERT(defined $rev) if DEBUG; # rev at this change $this->{CURR_REV} = $rev; @@ -192,6 +192,68 @@ sub expandPlain { $template =~ s/%REVISION%/$frev/g; $template =~ s/%TEXTHEAD%/$this->{TEXT_SUMMARY}/g; + + $template =~ s/\($Foswiki::cfg{UsersWebName}\./\(/go; + + return $template; +} + +=begin TML + +---++ expandDiff() -> string +Generate a unified diff version of this change. + +=cut + +sub expandDiff { + my ($this, $template) = @_; + + unless ($this->{TEXT_DIFF}) { + my $b = Foswiki::Meta->load( + $Foswiki::Plugins::SESSION, + $this->{WEB}, $this->{TOPIC}, $this->{CURR_REV}); + return '' unless ( $b->haveAccess('VIEW') ); + my $btext = $b->getEmbeddedStoreForm(); + $btext =~ s/^%META:TOPICINFO{.*}%$//; + + return $btext if ($this->{BASE_REV} < 1); + + my $a = Foswiki::Meta->load( + $Foswiki::Plugins::SESSION, + $this->{WEB}, $this->{TOPIC}, $this->{BASE_REV}); + return '' unless ( $a->haveAccess('VIEW') ); + my $atext = $a->getEmbeddedStoreForm(); + $atext =~ s/^%META:TOPICINFO{.*}%$//; + + require Foswiki::Merge; + my $blocks = Foswiki::Merge::simpleMerge( + $atext, $btext, qr/[\r\n]+/ ); + $this->{TEXT_DIFF} = ''.join("\n", @$blocks).''; + } + + my $tim = Foswiki::Time::formatTime( $this->{TIME} ); + + $template =~ s/%AUTHOR%/$this->{AUTHOR}/g; + $template =~ s/%TIME%/$tim/g; + $template =~ s/%CUR_REV%/$this->{CURR_REV}/g; + $template =~ s/%BASE_REV%/$this->{BASE_REV}/g; + $template =~ s/%TOPICNAME%/$this->{TOPIC}/g; # deprecated DO NOT USE! + $template =~ s/%TOPIC%/$this->{TOPIC}/g; + my $frev = ''; + if ( $this->{CURR_REV} ) { + if ( $this->{CURR_REV} > 1 ) { + $frev = 'r' . $this->{BASE_REV} . '->r' . $this->{CURR_REV}; + } + else { + + # new _since the last notification_ + $frev = 'NEW'; + } + } + $template =~ s/%REVISION%/$frev/g; + + $template =~ s/%TEXTHEAD%/$this->{TEXT_DIFF}/g; + return $template; } diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Constants.pm b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Constants.pm deleted file mode 100644 index 3f0c86b84b..0000000000 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Constants.pm +++ /dev/null @@ -1,41 +0,0 @@ -# See bottom of file for license and copyright information - -=pod - ----+ package Foswiki::Contrib::MailerContrib::Constants - -$ALWAYS - always send, even if there are no changes -$FULL_TOPIC - send the full topic rather than just changes - -=cut - -package Foswiki::Contrib::MailerContrib::Constants; - -use strict; -use warnings; - -our $ALWAYS = 1; -our $FULL_TOPIC = 2; - -# ? = FULL_TOPIC -# ! = FULL_TOPIC | ALWAYS - -1; -__END__ -Foswiki - The Free and Open Source Wiki, http://foswiki.org/ - -Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors -are listed in the AUTHORS file in the root of this distribution. -NOTE: Please extend that file, not this notice. - -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. For -more details read LICENSE in the root of this distribution. - -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. - -As per the GPL, removal of this notice is prohibited. diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/MANIFEST b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/MANIFEST index f4b695d7d4..62753b86fb 100644 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/MANIFEST +++ b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/MANIFEST @@ -4,7 +4,6 @@ lib/Foswiki/Contrib/MailerContrib/WebNotify.pm 0444 lib/Foswiki/Contrib/MailerContrib/Subscriber.pm 0444 lib/Foswiki/Contrib/MailerContrib/Subscription.pm 0444 lib/Foswiki/Contrib/MailerContrib/Change.pm 0444 -lib/Foswiki/Contrib/MailerContrib/Constants.pm 0444 lib/Foswiki/Contrib/MailerContrib/UpData.pm 0444 lib/Foswiki/Configure/Checkers/Plugins/MailerContribPlugin/Module.pm 0444 lib/Foswiki/Configure/Checkers/Plugins/MailerContribPlugin/Enabled.pm 0444 diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm index 771c354b75..7d398a1277 100644 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm +++ b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm @@ -16,7 +16,12 @@ use strict; use warnings; use Assert; -use Foswiki::Contrib::MailerContrib::Constants; +# Always mail out this subscription, even if there have been no changes +use constant ALWAYS => 1; +# Always mail out the full topic, not just the changes +use constant FULL_TOPIC => 2; +# ? = FULL_TOPIC +# ! = FULL_TOPIC | ALWAYS =begin TML @@ -24,7 +29,7 @@ use Foswiki::Contrib::MailerContrib::Constants; * =$pages= - Wildcarded expression matching subscribed pages * =$childDepth= - Depth of children of $topic to notify changes for. Defaults to 0 - * =$options= - bitmask of Foswiki::Contrib::MailerContrib::Constants options + * =$options= - bitmask of Foswiki::Contrib::MailerContrib::Subscription options Create a new subscription. =cut @@ -120,11 +125,11 @@ sub covers { my ( $this, $tother, $db ) = @_; # Does the mode cover the other subscription? - return 0 - unless ( - ( $this->{options} & $tother->{options} ) == $tother->{options} ); + # ALWAYS covers (ALWAYS and not ALWAYS). + # FULL_TOPIC covers (FULL_TOPIC and not FULL_TOPIC) + return 0 unless ( $this->{options} & $tother->{options} ) == $tother->{options}; - #* should win always. + # A * always covers if the options match return 1 if ( $this->{topics} eq '*' ); # do they match without taking into account the depth? @@ -154,12 +159,10 @@ specified in WebNotify. sub getMode { my $this = shift; - if ( $this->{options} & - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ) + if ( $this->{options} & FULL_TOPIC ) { return '!' - if ( $this->{options} & - $Foswiki::Contrib::MailerContrib::Constants::ALWAYS ); + if ( $this->{options} & ALWAYS ); return '?'; } return ''; diff --git a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm index 669e711592..173a325c23 100644 --- a/MailerContrib/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm +++ b/MailerContrib/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm @@ -28,9 +28,10 @@ use Foswiki::Contrib::MailerContrib::Subscription (); ---++ new($web, $topic) * =$web= - web name * =$topic= - topic name - * =$noexpandgroups= - True will prevent expansion of group subscriptions - (False is best for checking subscriptions, but True is best for - writing results back to $topic) + * =$noexpandgroups= - True will prevent expansion of group subscriptions + (False is best for checking subscriptions, but True is best for + writing results back to $topic) + Create a new object by parsing the content of the given topic in the given web. This is the normal way to load a %NOTIFYTOPIC% topic. If the topic does not exist, it will create an empty object. @@ -187,9 +188,9 @@ sub unsubscribe { ---++ stringify() -> string Return a string representation of this object, in %NOTIFYTOPIC% format. -Optional $subscribersOnly parameter to only print the parsed subscription list. +Optional =$subscribersOnly= parameter to only print the parsed subscription list. Used when running a mailnotify, where printing out the entire WebNotify topic is confusing, -as its different from the actual topic contents, but doesn't inform the user why. +as it's different from the actual topic contents, but doesn't inform the user why. =cut @@ -253,13 +254,13 @@ sub processChange { if ( !( $subs->{options} & - $Foswiki::Contrib::MailerContrib::Constants::ALWAYS + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ) && $authors{$email} ); if ( $subs->{options} & - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ) { push( @{ $allSet->{$topic} }, $email ); @@ -301,7 +302,7 @@ sub processCompulsory { next unless $subs; next unless ( $subs->{options} & - $Foswiki::Contrib::MailerContrib::Constants::ALWAYS ); + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); unless ( $subscriber->isUnsubscribedFrom( $topic, $db ) ) { my $emails = $subscriber->getEmailAddresses(); if ($emails) { @@ -338,7 +339,7 @@ sub _load { # join \ terminated lines $text =~ s/\\\r?\n//gs; - my $webRE = qr/(?:$Foswiki::cfg{UsersWebName}\.)?/o; + my $webRE = qr/(?:$Foswiki::cfg{UsersWebName}\.)?/; foreach my $baseline ( split( /\r?\n/, $text ) ) { my $line = Foswiki::Func::expandCommonVariables( $baseline, $this->{topic}, @@ -349,7 +350,7 @@ sub _load { ($Foswiki::regex{wikiWordRegex}) \s+\-\s+ ($Foswiki::cfg{MailerContrib}{EmailFilterIn}+) - \s*$}xo + \s*$}x && $1 ne $Foswiki::cfg{DefaultUserWikiName} ) { @@ -368,7 +369,7 @@ sub _load { | $Foswiki::cfg{MailerContrib}{EmailFilterIn} ) \s*(:.*)?$ - }xo + }x && $1 ne $Foswiki::cfg{DefaultUserWikiName} ) { @@ -432,9 +433,9 @@ sub _subscribeTopic { #print STDERR "_subscribeTopic($topic)\n"; my $opts = 0; if ($options) { - $opts |= $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC; + $opts |= Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC; if ( $options =~ /!/ ) { - $opts |= $Foswiki::Contrib::MailerContrib::Constants::ALWAYS; + $opts |= Foswiki::Contrib::MailerContrib::Subscription::ALWAYS; } } my $kids = $childDepth or 0; diff --git a/MailerContrib/templates/mailnotify.tmpl b/MailerContrib/templates/mailnotify.tmpl index cebd4ced5a..947b400f0a 100644 --- a/MailerContrib/templates/mailnotify.tmpl +++ b/MailerContrib/templates/mailnotify.tmpl @@ -57,14 +57,23 @@ -------------------------------- %TMPL:DEF{PLAIN:after}%%TMPL:END% -------------------------------- +%TMPL:DEF{DIFF:before}%%TMPL:END% +-------------------------------- +%TMPL:DEF{DIFF:middle}%- %TOPIC% (%AUTHOR%, %TIME%) %REVISION% +%SCRIPTURL{"view"}%/%ENCODE{%WEB%}%/%ENCODE{%TOPIC%}% +%TEXTHEAD% +%TMPL:END% +-------------------------------- +%TMPL:DEF{DIFF:after}%%TMPL:END% +-------------------------------- %TMPL:DEF{MailNotifyBody}%From: %WIKIWEBMASTERNAME% <%WIKIWEBMASTER%> To: %EMAILTO% Subject: %WIKITOOLNAME%.%WEB% - %MAKETEXT{"Automated notification of topic changes"}% MIME-Version: 1.0 -Content-Type: multipart/alternative; boundary="=_=0i0k0i0w0tXuOi0E0A" +Content-Type: multipart/alternative; boundary="=_=0i0k0i0w0s0o0fXuOi0E0A" This is a multi-part message in MIME format. ---=_=0i0k0i0w0tXuOi0E0A +--=_=0i0k0i0w0s0o0fXuOi0E0A Content-Type: text/plain; charset=%CHARSET%; format=flowed Content-Transfer-Encoding: 8bit @@ -79,11 +88,11 @@ Content-Transfer-Encoding: 8bit %MAKETEXT{"Subscribe / Unsubscribe in:"}% %SCRIPTURL{"view"}%/%WEB%/%NOTIFYTOPIC% ---=_=0i0k0i0w0tXuOi0E0A +--=_=0i0k0i0w0s0o0fXuOi0E0A Content-Type: text/html; charset=%CHARSET% Content-Transfer-Encoding: 8bit %HTML_TEXT% ---=_=0i0k0i0w0tXuOi0E0A-- +--=_=0i0k0i0w0s0o0fXuOi0E0A-- %TMPL:END% diff --git a/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm b/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm index ec259132f3..41d673ac36 100644 --- a/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm +++ b/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm @@ -229,7 +229,6 @@ sub set_up { $web, $Foswiki::cfg{NotifyTopicName}, $meta, "Before\n${s}After" ); - for my $testTopic ( keys %expectedRevs ) { my $parent = 'WebHome'; if ( $testTopic =~ /^TestTopic(\d+)\d$/ ) { @@ -407,55 +406,121 @@ sub testCovers { my $s1 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, 0 ); $this->assert( $s1->covers($s1) ); - my $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + my $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( !$s1->covers($s2) ); $s1 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, - $Foswiki::Contrib::MailerContrib::Constants::ALWAYS | - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $s1->covers($s2) ); $this->assert( !$s2->covers($s1) ); $s1 = new Foswiki::Contrib::MailerContrib::Subscription( 'A*', 0, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $s1->covers($s2) ); $this->assert( !$s2->covers($s1) ); $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 1, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( !$s1->covers($s2) ); $this->assert( !$s2->covers($s1) ); $s1 = new Foswiki::Contrib::MailerContrib::Subscription( 'A*', 1, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $s1->covers($s2) ); $this->assert( !$s2->covers($s1) ); $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A*B', 1, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $s1->covers($s2) ); $this->assert( !$s2->covers($s1) ); $s1 = new Foswiki::Contrib::MailerContrib::Subscription( 'AxB', 0, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( !$s1->covers($s2) ); $this->assert( $s2->covers($s1) ); # * covers everything. my $AStar = new Foswiki::Contrib::MailerContrib::Subscription( 'A*', 1, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); my $Star = new Foswiki::Contrib::MailerContrib::Subscription( '*', 1, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $Star->covers($AStar) ); $this->assert( !$AStar->covers($Star) ); #as parent-child relationshipd are broken across webs, * should cover topic (2) my $ChildrenOfWebHome = new Foswiki::Contrib::MailerContrib::Subscription( 'WebHome', 2, - $Foswiki::Contrib::MailerContrib::Constants::FULL_TOPIC ); + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); $this->assert( $Star->covers($ChildrenOfWebHome) ); $this->assert( !$ChildrenOfWebHome->covers($Star) ); + + # Special cases involving '*' and modes + $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, + 0); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + 0 ); + $this->assert( $s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); + $this->assert( $s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); + + $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + 0 ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); + $this->assert( $s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); + + $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + 0 ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); + + $s2 = new Foswiki::Contrib::MailerContrib::Subscription( 'A', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + 0 ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); + $this->assert( !$s1->covers($s2) ); + $s1 = new Foswiki::Contrib::MailerContrib::Subscription( '*', 0, + Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | + Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC ); + $this->assert( $s1->covers($s2) ); } # Check filter-in on email addresses