From: <de...@de...> - 2008-08-27 11:44:21
|
Author: CrawfordCurrie Date: 2008-08-27 06:44:30 -0500 (Wed, 27 Aug 2008) New Revision: 17462 Trac url: http://develop.twiki.org/trac/changeset/17462 Added: twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Constants.pm Modified: twiki/trunk/MailerContrib/data/TWiki/MailerContrib.txt twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscriber.pm twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscription.pm twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/WebNotify.pm twiki/trunk/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm Log: Item5949: fixed problem with unsubscribe that should result in an empty subscription Modified: twiki/trunk/MailerContrib/data/TWiki/MailerContrib.txt =================================================================== --- twiki/trunk/MailerContrib/data/TWiki/MailerContrib.txt 2008-08-27 08:02:15 UTC (rev 17461) +++ twiki/trunk/MailerContrib/data/TWiki/MailerContrib.txt 2008-08-27 11:44:30 UTC (rev 17462) @@ -51,7 +51,7 @@ * *Using wild-card character in topic names* - You can use =*= in a topic name, where it is treated as a [[http://en.wikipedia.org/wiki/Wildcard_character][wildcard character]]. A =*= will match zero or more other characters - so, for example, =Fred*= will match all topic names starting with =Fred=, =*Fred= will match all topic names _ending_ with =Fred=, and =*= will match _all_ topic names. * *Unsubscribing to specific topics* - Each topic may optionally be preceded by a '+' or '-' sign. The '+' sign means "subscribe to this topic". The '-' sign means "unsubscribe" or "don't send notifications regarding this particular topic". This allows users to elect to filter out certain topics. Topic filters ('-') take precedence over topic includes ('+') i.e. if you unsubscribe from a topic it will cancel out any subscriptions to that topic. * *Including child-topics in subscription* - Each topic may optionally be followed by an integer in parentheses, indicating the depth of the tree of children below that topic. Changes in all these children will be detected and reported along with changes to the topic itself. _Note_ This uses the TWiki "Topic parent" feature. - * *Subscribing to entire topic ("news mode")* - Each topic may optionally be immediately followed by an exclamation mark ! or a question mark ? with no intervening spaces, indicating that the topic (and children if there is a tree depth specifier as well) should be mailed out as *complete topics* instead of change summaries. ! causes the topic to be mailed every time _even if there have been no changes_, and ? will mail the topic only if there have been changes to it. One can limit the content of the subscribed topic to send out by inserting %<nop>STARTPUBLISH% and %<nop>STOPPUBLISH% markers within the topic. Note that "news mode" subscriptions require a corresponding cron job that includes the "-news" option (see [[%TOPIC%#Setting_up_your_cron_job_s][details]]). + * *Subscribing to entire topic ("news mode")* - Each topic may optionally be immediately followed by an exclamation mark ! and/or a question mark ? with no intervening spaces, indicating that the topic (and children if there is a tree depth specifier as well) should be mailed out as *complete topics* instead of change summaries. ! causes the full topic to be mailed every time _even if there have been no changes_, and ? will mail the full topic only if there have been changes. One can limit the content of the subscribed topic to send out by inserting %<nop>STARTPUBLISH% and %<nop>STOPPUBLISH% markers within the topic. Note that "news mode" subscriptions require a corresponding cron job that includes the "-news" option (see [[%TOPIC%#Setting_up_your_cron_job_s][details]]). Examples: Subscribe Daisy to all changes to topics in this web. @@ -92,7 +92,7 @@ If a _group_ is listed for notification, the group will be recursively expanded to the e-mail addresses of all members. -__%X% Warning: Because an email address is not linked to a user name, there is no way for TWiki to check access controls for email addresses. A user identified by an email address will only be sent change notifications if the topic they are asubscribed to is readable by guest users. You can limit what email addresses can be used in <nop>%NOTIFYTOPIC%, or even block use of emails altogther, using the ={MailerContrib}{EmailFilterIn} setting in =configure=. +__%X% Warning: Because an email address is not linked to a user name, there is no way for TWiki to check access controls for subscribers identified by email addresses. A subscriber identified by an email address alone will only be sent change notifications if the topic they are subscribed to is readable by guest users. You can limit what email addresses can be used in %<nop>NOTIFYTOPIC%, or even block use of emails altogther, using the ={MailerContrib}{EmailFilterIn} setting in =configure=. __%T% Tip:__ List names in alphabetical order to make it easier to find the names. %STOPINCLUDE% @@ -141,7 +141,7 @@ * Set SHORTDESCRIPTION = Supports e-mail notification of changes. --> ---++ Developer Notes -The changes mails sent to users are based on a TWiki template called =mailnotify=. This template must contain the following definitions. +The changes mails sent to subscribers are based on a TWiki template called =mailnotify=. This template must contain the following definitions. | =HTML:before= | Section of a HTML mail before the changes | | =HTML:middle= | Repeated in a HTML mail for each change | | =HTML:after= | Section of a HTML mail after the changes | @@ -166,6 +166,7 @@ | License: | GPL | | Version: | 03 Aug 2008 | | Change History: | | +| 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: TWiki:Main.KennethLavrsen added note to warn against running multiple instances of mailnotify at the same time. | | 15 May 2008 | TWikibug:Item5232: TWiki:Main.CrawfordCurrie added support for non-ascii alphanumerics in topic names to WebNotify. TWikibug:Item5630: TWiki:Main.SvenDowideit fixed some spelling errors | Added: twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Constants.pm =================================================================== --- twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Constants.pm (rev 0) +++ twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Constants.pm 2008-08-27 11:44:30 UTC (rev 17462) @@ -0,0 +1,22 @@ +=pod + +---+ package MailerConst + +$ALWAYS - always send, even if there are no changes +$FULL_TOPIC - send the full topic rather than just changes + +Note that this package is defined in a file with a name different to that +of the package. This is intentional (it's to keep the length of the constants +package name short). + +=cut + +package MailerConst; + +our $ALWAYS = 1; # Always send, even if there are no changes +our $FULL_TOPIC = 2; # Send the full topic rather than just changes + +# ? = FULL_TOPIC +# ! = FULL_TOPIC | ALWAYS + +1; Modified: twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscriber.pm =================================================================== --- twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscriber.pm 2008-08-27 08:02:15 UTC (rev 17461) +++ twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscriber.pm 2008-08-27 11:44:30 UTC (rev 17462) @@ -67,37 +67,55 @@ my $this = shift; unless ( defined( $this->{emails} )) { - if ( $this->{name} =~ /^$TWiki::cfg{MailerContrib}{EmailFilterIn}$/ ) { - push( @{$this->{emails}}, $this->{name} ); + $this->{emails} = getEmailAddressesForUser( $this->{name}); + } + return $this->{emails}; +} + +=pod + +---++ STATIC getEmailAddressesForUser() -> \@list +Get a list of email addresses for the user(s) represented by this +subscription. Static method provided for use by other modules. + +=cut + +sub getEmailAddressesForUser { + my $name = shift; + my $emails = []; + + return $emails unless $name; + + if ( $name =~ /^$TWiki::cfg{MailerContrib}{EmailFilterIn}$/ ) { + push( @{$emails}, $name ); + } else { + my $users = $TWiki::Plugins::SESSION->{users}; + if ($users->can('findUserByWikiName')) { + # User is represented by a wikiname. Map to a canonical + # userid. + my $list = $users->findUserByWikiName($name); + foreach my $user (@$list) { + # Automatically expands groups + push( @{$emails}, $users->getEmails($user) ); + } } else { - my $users = $TWiki::Plugins::SESSION->{users}; - if ($users->can('findUserByWikiName')) { - # User is represented by a wikiname. Map to a canonical - # userid. - my $list = $users->findUserByWikiName($this->{name}); - foreach my $user (@$list) { - # Automatically expands groups - push( @{$this->{emails}}, $users->getEmails($user) ); - } + # Old code; use the user object + my $user = $users->findUser( $name, undef, 1 ); + if( $user ) { + push( @{$emails}, $user->emails() ); } else { - # Old code; use the user object - my $user = $users->findUser( $this->{name}, undef, 1 ); + $user = $users->findUser( + $name, $name, 1 ); if( $user ) { - push( @{$this->{emails}}, $user->emails() ); + push( @{$emails}, $user->emails() ); } else { - $user = $users->findUser( - $this->{name}, $this->{name}, 1 ); - if( $user ) { - push( @{$this->{emails}}, $user->emails() ); - } else { - # unknown - can't find an email - $this->{emails} = []; - } + # unknown - can't find an email + $emails = []; } } } } - return $this->{emails}; + return $emails; } # Add a subsciption to an internal list, optimising the list so that Modified: twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscription.pm =================================================================== --- twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscription.pm 2008-08-27 08:02:15 UTC (rev 17461) +++ twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/Subscription.pm 2008-08-27 11:44:30 UTC (rev 17462) @@ -23,26 +23,31 @@ package TWiki::Contrib::MailerContrib::Subscription; +use Assert; + +use TWiki::Contrib::MailerContrib::Constants; + =pod ----++ new($pages, $childDepth, $news) +---++ new($pages, $childDepth, $options) * =$pages= - Wildcarded expression matching subscribed pages - * =$childDepth= - Depth of children of $topic to notify changes for. Defaults to 0 - * =$mode= - ! if this is a non-changes subscription and the topics should - be mailed evebn if there are no changes. ? to mail the full topic only - if there are changes. undef to mail changes only. + * =$childDepth= - Depth of children of $topic to notify changes + for. Defaults to 0 + * =$options= - bitmask of MailerConst options Create a new subscription. =cut sub new { - my ( $class, $topics, $depth, $mode ) = @_; + my ( $class, $topics, $depth, $opts ) = @_; + ASSERT(defined($opts) && $opts =~ /^\d*$/) if DEBUG; + my $this = bless( {}, $class ); $this->{topics} = $topics || ''; $this->{depth} = $depth || 0; - $this->{mode} = $mode || ''; + $this->{options} = $opts || 0; $topics =~ s/[^\w\*]//g; $topics =~ s/\*/\.\*\?/g; @@ -60,10 +65,10 @@ sub stringify { my $this = shift; - - my $record = $this->{topics} . ($this->{mode} || ''); + my $record = $this->{topics}; # convert RE back to wildcard $record =~ s/\.\*\?/\*/; + $record .= $this->getMode(); $record .= " ($this->{depth})" if ( $this->{depth} ); return $record; } @@ -113,8 +118,9 @@ sub covers { my( $this, $tother, $db ) = @_; - # A different mode never matches - return 0 unless $this->{mode} eq $tother->{mode}; + # Does the mode cover the other subscription? + return 0 unless + (($this->{options} & $tother->{options}) == $tother->{options}); # do they match without taking into account the depth? return 0 unless( $this->matches($tother->{topics}, undef, 0) ); @@ -135,16 +141,19 @@ =pod ---++ getMode() -> $mode -Return ! if this is a non-changes subscription and the topics should -be mailed even if there are no changes. ? to mail the full topic only -if there are changes. undef to mail changes only. +Get the newsletter mode of this subscription ('', '?' or '!') as +specified in WebNotify. =cut sub getMode { my $this = shift; - return $this->{mode}; + if ($this->{options} & $MailerConst::FULL_TOPIC) { + return '!' if ($this->{options} & $MailerConst::ALWAYS); + return '?'; + } + return ''; } =pod @@ -156,7 +165,7 @@ sub equals { my( $this, $tother ) = @_; - return 0 unless ($this->{mode} eq $tother->{mode}); + return 0 unless ($this->{options} eq $tother->{options}); return 0 unless ($this->{depth} == $tother->{depth}); return 0 unless ($this->{topics} eq $tother->{topics}); } Modified: twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/WebNotify.pm =================================================================== --- twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/WebNotify.pm 2008-08-27 08:02:15 UTC (rev 17461) +++ twiki/trunk/MailerContrib/lib/TWiki/Contrib/MailerContrib/WebNotify.pm 2008-08-27 11:44:30 UTC (rev 17462) @@ -33,6 +33,8 @@ use strict; use locale; # required for matching \w with international characters +use Assert; + require TWiki::Func; require TWiki::Contrib::MailerContrib::Subscriber; require TWiki::Contrib::MailerContrib::Subscription; @@ -128,20 +130,20 @@ =pod ----++ subscribe($name, $topics, $depth) +---++ subscribe($name, $topics, $depth, $options) * =$name= - Name of subscriber (wikiname with no web or email address) * =$topics= - wildcard expression giving topics to subscribe to * =$depth= - Child depth to scan (default 0) - * =$mode= - ! if this is a non-changes subscription and the topics should - be mailed even if there are no changes. ? to mail the full topic only - if there are changes. undef to mail changes only. + * =$options= - Bitmap of Mailer::Const options Add a subscription, adding the subscriber if necessary. =cut sub subscribe { - my ( $this, $name, $topics, $depth, $mode ) = @_; + my ( $this, $name, $topics, $depth, $opts ) = @_; + ASSERT(defined($opts) && $opts =~ /^\d*$/) if DEBUG; + my @names = ($name); unless ($this->{noexpandgroups}) { if (defined &TWiki::Func::eachGroupMember) { @@ -164,7 +166,7 @@ foreach my $n (@names) { my $subscriber = $this->getSubscriber( $n ); my $sub = new TWiki::Contrib::MailerContrib::Subscription( - $topics, $depth, $mode ); + $topics, $depth, $opts ); $subscriber->subscribe( $sub ); } } @@ -206,7 +208,7 @@ foreach my $n (@names) { my $subscriber = $this->getSubscriber( $n ); my $sub = new TWiki::Contrib::MailerContrib::Subscription( - $topics, $depth ); + $topics, $depth, 0 ); $subscriber->unsubscribe( $sub ); } } @@ -250,6 +252,9 @@ my $topic = $change->{TOPIC}; my $web = $change->{WEB}; + my %authors = map { $_ => 1 } + @{TWiki::Contrib::MailerContrib::Subscriber::getEmailAddressesForUser( + $change->{author})}; foreach my $name ( keys %{$this->{subscribers}} ) { my $subscriber = $this->{subscribers}{$name}; @@ -262,7 +267,12 @@ my $emails = $subscriber->getEmailAddresses(); if( $emails && scalar( @$emails )) { foreach my $email ( @$emails ) { - if ($subs->getMode()) { # ? or ! + # Skip this change if the subscriber is the author + # of the change, and we are not always sending + next if (!($subs->{options} & $MailerConst::ALWAYS) + && $authors{$email}); + + if ($subs->{options} & $MailerConst::FULL_TOPIC) { push( @{$allSet->{$topic}}, $email ); } else { my $at = $seenSet->{$email}{$topic}; @@ -297,8 +307,7 @@ my $subscriber = $this->{subscribers}{$name}; my $subs = $subscriber->isSubscribedTo( $topic, $db ); next unless $subs; - my $mode = $subs->getMode(); - next if (!defined($mode) || $mode ne '!'); + next unless ($subs->{options} & $MailerConst::ALWAYS); unless( $subscriber->isUnsubscribedFrom( $topic, $db )) { my $emails = $subscriber->getEmailAddresses(); if( $emails ) { @@ -338,21 +347,25 @@ foreach my $baseline ( split ( /\r?\n/, $text )) { my $line = TWiki::Func::expandCommonVariables( $baseline, $this->{topic}, $this->{web}, $meta); - if( $line =~ /^\s+\*\s$webRE($TWiki::regex{wikiWordRegex})\s+\-\s+($TWiki::cfg{MailerContrib}{EmailFilterIn})/o + if( $line =~ /^\s+\*\s$webRE($TWiki::regex{wikiWordRegex})\s+\-\s+($TWiki::cfg{MailerContrib}{EmailFilterIn}+)\s*$/o && $1 ne $TWiki::cfg{DefaultUserWikiName}) { # Main.WikiName - email@domain (legacy format) - $this->subscribe( $2, '*', 0 ); + $this->subscribe( $2, '*', 0, 0 ); $in_pre = 0; } - elsif ( $line =~ /^\s+\*\s$webRE($TWiki::regex{wikiWordRegex}|'.*?'|".*?"|$TWiki::cfg{MailerContrib}{EmailFilterIn})\s*(?::(.*))?$/o + elsif ( $line =~ /^\s+\*\s$webRE($TWiki::regex{wikiWordRegex}|'.*?'|".*?"|$TWiki::cfg{MailerContrib}{EmailFilterIn})\s*(:.*)?$/o && $1 ne $TWiki::cfg{DefaultUserWikiName}) { my $subscriber = $1; - my $topics = $3; - $subscriber =~ s/^(['"])(.*)\1$/$2/; - if (defined($topics) && $topics) { + # Get the topic list from the last bracket matched. Have to do it + # this awkward way because the email filter may contain braces + my $topics = $+; + # email addresses can't start with : + $topics = undef unless ($topics =~ s/^://); + $subscriber =~ s/^(['"])(.*)\1$/$2/; # remove quotes + if ($topics) { $this->_parsePages( $subscriber, $topics ); } else { - $this->subscribe($subscriber, '*', 0 ); + $this->subscribe($subscriber, '*', 0, 0 ); } $in_pre = 0; } @@ -372,16 +385,23 @@ my $ospec = $spec; $spec =~ s/,/ /g; while ( $spec =~ s/^\s*([+-])?\s*([\w\*]+)([!?]?)\s*(?:\((\d+)\))?// ) { - my $mode = $3 or 0; + my $opts = 0; + if ($3) { + $opts |= $MailerConst::FULL_TOPIC; + if ($3 =~ /!/) { + $opts |= $MailerConst::ALWAYS; + } + } my $kids = $4 or 0; if ( $1 && $1 eq '-' ) { $this->unsubscribe( $who, $2, $kids ); } else { - $this->subscribe( $who, $2, $kids, $mode ); + $this->subscribe( $who, $2, $kids, $opts ); } } if ( $spec =~ m/\S/ ) { - print STDERR "Badly formatted page list at $who: $ospec\n"; + TWiki::Func::writeWarning( + "Badly formatted page list at $who: $ospec"); } } @@ -394,8 +414,9 @@ # Topic we are notifying on. unless (defined $this->{nomail}{$name}) { $this->{nomail}{$name} = 1; - print STDERR "WARNING: Failed to find permitted email for '". - $subscriber->stringify()."' when processing web '$web'\n"; + TWiki::Func::writeWarning( + "Failed to find permitted email for '". + $subscriber->stringify()."' when processing web '$web'"); } } Modified: twiki/trunk/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm =================================================================== --- twiki/trunk/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm 2008-08-27 08:02:15 UTC (rev 17461) +++ twiki/trunk/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm 2008-08-27 11:44:30 UTC (rev 17462) @@ -36,8 +36,10 @@ TestTopic1221 => "What's up, Buck?", TestTopic2 => "roast my nipple-nuts", TestTopic21 => "smoke me a kipper, I'll be back for breakfast", - 'RequsNon' => "make it so, number one", - 'RequsOui' => "you're such a smeeee heeee", + # High-bit chars - assumes {Site}{CharSet} is set for a high-bit + # encoding. No tests for multibyte encodings :-( + 'RequsNon' => "makt so, number on + 'RequsOui' => "you're such a sm heeee", ); sub new { @@ -50,6 +52,8 @@ $this->SUPER::set_up(); $TWiki::cfg{EnableHierarchicalWebs} = 1; + $TWiki::cfg{MailerContrib}{EmailFilterIn} ||= + $TWiki::regex{emailAddrRegex}; $this->{twiki}->net->setMailHandler(\&TWikiFnTestCase::sentMail); @@ -160,24 +164,34 @@ entry => "'IT:admins': TestTopic1", topicsout => "", }, - # Francais - { - email => "test1\@example.com", - entry => "TestUser1 : Requs*", - topicsout => "RequsNon RequsOui", - }, ); + if (!$TWiki::cfg{Site}{CharSet} + || $TWiki::cfg{Site}{CharSet} =~ /^iso-?8859/) { + # High-bit chars - assumes {Site}{CharSet} is set for a high-bit + # encoding. No tests for multibyte encodings :-( + push(@specs, # Francais + { + email => "test1\@example.com", + entry => "TestUser1 : Requs*", + topicsout => "RequsNon RequsOui", + }, + ); + } else { + print STDERR "WARNING: High-bit tests disabled for $TWiki::cfg{Site}{CharSet}\n"; + } + my $s = ""; foreach my $spec (@specs) { $s .= " * $spec->{entry}\n"; } - foreach my $web ($this->{test_web}, $testWeb2) { - my $meta = new TWiki::Meta($this->{twiki},$web,"WebNotify"); + my $meta = new TWiki::Meta($this->{twiki},$web, + $TWiki::cfg{NotifyTopicName}); $meta->put( "TOPICPARENT", { name => "$web.WebHome" } ); - TWiki::Func::saveTopic( $web, "WebNotify", $meta, + TWiki::Func::saveTopic( $web, $TWiki::cfg{NotifyTopicName}, $meta, "Before\n${s}After"); + $meta = new TWiki::Meta($this->{twiki},$web,"TestTopic1"); $meta->put( "TOPICPARENT", { name => "WebHome" } ); TWiki::Func::saveTopic( $web, "TestTopic1", $meta, @@ -390,12 +404,15 @@ } foreach my $spec (@specs) { if ($spec->{topicsout} ne "") { - $this->assert($matched{$spec->{email}}, - "Expected mails for ".$spec->{email} . " got " . + $this->assert( + $matched{$spec->{email}}, + "Expected mails for ".$spec->{email} . + " but only saw mails for " . join(" ", keys %matched)); } else { - $this->assert(!$matched{$spec->{email}}, - "Unexpected mails for ".$spec->{email} . " got " . + $this->assert( + !$matched{$spec->{email}}, + "Didn't expect mails for ".$spec->{email} . "; got " . join(" ", keys %matched)); } } @@ -405,35 +422,40 @@ my $this = shift; my $s1 = new TWiki::Contrib::MailerContrib::Subscription( - 'A', 0, undef); + 'A', 0, 0); $this->assert($s1->covers($s1)); my $s2 = new TWiki::Contrib::MailerContrib::Subscription( - 'A', 0, '!'); + 'A', 0, $MailerConst::FULL_TOPIC); $this->assert(!$s1->covers($s2)); $s1 = new TWiki::Contrib::MailerContrib::Subscription( - 'A*', 0, '!'); + 'A', 0, $MailerConst::ALWAYS | $MailerConst::FULL_TOPIC); $this->assert($s1->covers($s2)); $this->assert(!$s2->covers($s1)); + $s1 = new TWiki::Contrib::MailerContrib::Subscription( + 'A*', 0, $MailerConst::FULL_TOPIC); + $this->assert($s1->covers($s2)); + $this->assert(!$s2->covers($s1)); + $s2 = new TWiki::Contrib::MailerContrib::Subscription( - 'A', 1, '!'); + 'A', 1, $MailerConst::FULL_TOPIC); $this->assert(!$s1->covers($s2)); $this->assert(!$s2->covers($s1)); $s1 = new TWiki::Contrib::MailerContrib::Subscription( - 'A*', 1, '!'); + 'A*', 1, $MailerConst::FULL_TOPIC); $this->assert($s1->covers($s2)); $this->assert(!$s2->covers($s1)); $s2 = new TWiki::Contrib::MailerContrib::Subscription( - 'A*B', 1, '!'); + 'A*B', 1, $MailerConst::FULL_TOPIC); $this->assert($s1->covers($s2)); $this->assert(!$s2->covers($s1)); $s1 = new TWiki::Contrib::MailerContrib::Subscription( - 'AxB', 0, '!'); + 'AxB', 0, $MailerConst::FULL_TOPIC); $this->assert(!$s1->covers($s2)); $this->assert($s2->covers($s1)); } @@ -449,12 +471,15 @@ * go...@ex...: * HERE - my $meta = new TWiki::Meta($this->{twiki},$this->{test_web},"WebNotify"); + my $meta = new TWiki::Meta($this->{twiki},$this->{test_web}, + $TWiki::cfg{NotifyTopicName}); $meta->put( "TOPICPARENT", { name => "$this->{test_web}.WebHome" } ); - TWiki::Func::saveTopic( $this->{test_web}, "WebNotify", $meta, - "Before\n${s}After", - $meta); - TWiki::Contrib::MailerContrib::mailNotify( [ $this->{test_web} ], $this->{twiki}, 0 ); + TWiki::Func::saveTopic( $this->{test_web}, $TWiki::cfg{NotifyTopicName}, + $meta, + "Before\n${s}After", + $meta); + TWiki::Contrib::MailerContrib::mailNotify( + [ $this->{test_web} ], $this->{twiki}, 0 ); my %matched; foreach my $message ( @TWikiFnTestCase::mails ) { @@ -467,4 +492,61 @@ #print "REPORT\n",join("\n\n", @TWikiFnTestCase::mails); } +sub testExpansion { + my $this = shift; + + my $s = <<'HERE'; +%SEARCH{"gribble.com" multiple="on" topic="%TOPIC%" format=" * se...@ex...: *"}% +gribble.com +HERE + + my $meta = new TWiki::Meta($this->{twiki},$this->{test_web}, + $TWiki::cfg{NotifyTopicName}); + $meta->put( "TOPICPARENT", { name => "$this->{test_web}.WebHome" } ); + TWiki::Func::saveTopic( $this->{test_web}, $TWiki::cfg{NotifyTopicName}, + $meta, + "Before\n${s}After", + $meta); + TWiki::Contrib::MailerContrib::mailNotify( [ $this->{test_web} ], $this->{twiki}, 0 ); + + my %matched; + foreach my $message ( @TWikiFnTestCase::mails ) { + next unless $message; + $message =~ /^To: (.*?)$/m; + my $mailto = $1; + $this->assert($mailto, $message); + $this->assert_str_equals('se...@ex...', $mailto, $mailto); + } + #print "REPORT\n",join("\n\n", @TWikiFnTestCase::mails); +} + +sub test_5949 { + my $this = shift; + my $s = <<'HERE'; + * TestUser1: SpringCabbage +HERE + my $meta = new TWiki::Meta($this->{twiki},$this->{test_web}, + $TWiki::cfg{NotifyTopicName}); + $meta->put( "TOPICPARENT", { name => "$this->{test_web}.WebHome" } ); + TWiki::Func::saveTopic( $this->{test_web}, + $TWiki::cfg{NotifyTopicName}, $meta, + "Before\n${s}After", + $meta); + + my $wn = new TWiki::Contrib::MailerContrib::WebNotify( + $TWiki::Plugins::SESSION, $this->{test_web}, + $TWiki::cfg{NotifyTopicName}, 1 ); + $this->assert_str_equals(<<HERE, $wn->stringify()); +Before + * TestUser1: SpringCabbage +After +HERE + $wn->unsubscribe("TestUser1", "SpringCabbage"); + $this->assert_str_equals(<<HERE, $wn->stringify()); +Before + * TestUser1: - SpringCabbage +After +HERE +} + 1; |