Changeset 5288


Ignore:
Timestamp:
10/17/09 11:44:14 (2 years ago)
Author:
KennethLavrsen
Message:

Item1302: mailnotify ignores -news operand
It is a bug that goes back to TWiki 4.0. The -news was documented but never implemented
Fixing it as speced would cause trouble for people.
And the spec is bad. It would not work well. So instead of implenting a bad spec I decided to implement -nonews and -nochanges which will give people the flexibility AND maintain status quo for those already using the mailnotify with or without a -news switch on the cronjob.

Location:
branches/Release01x00/MailerContrib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x00/MailerContrib/data/System/MailerContrib.txt

    r5273 r5288  
    5050   * *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. 
    5151   * *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 Foswiki "Topic parent" feature. 
    52    * *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]]). 
     52   * *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 the script mailnotify can be run with the options -nochanges or -nonews so that you can run the two mode on different schedules (see [[%TOPIC%#Setting_up_your_cron_job_s][details]]). 
    5353 
    5454Examples: 
     
    114114You need to set up a =cron= (or equivalent) job to run the =tools/mailnotify= perl script. 
    115115 
    116 The script is used as follows: <code>perl -I _bin_ mailnotify [-q] [-news] [ <i>web1 web2 ... webN</i> ]</code> 
     116The script is used as follows: <code>perl -I _bin_ mailnotify [-q] [-nonews] [-nochanges] [ <i>web1 web2 ... webN</i> ]</code> 
    117117| _bin_ | path to the Foswiki bin directory, so that the script can find the rest of Foswiki. | 
    118118| =-q= | Don't print progress information | 
    119 | =-news= | Run in "news mode" (process subscriptions that include "!" or "?" following the topic) | 
     119| =-nonews= | Skip the "news mode" (do not process subscriptions that include "!" or "?" following the topic) | 
     120| =-nochanges= | Only run the news mode. (only process subscriptions that include "!" or "?" following the topic) | 
    120121| <code><i>web1 web2 ... webN</i></code> | List of webs to process, separated by spaces or commas. The default is to process all webs. Wildcards (*) are supported. | 
    121122For example, assuming Foswiki was installed at =/usr/local/foswiki=, this cron entry: 
     
    129130will generate change notifications for all webs, except the =Sandbox= web. 
    130131<verbatim> 
    131 0 0 * * 0 cd /usr/local/foswiki && perl -I bin tools/mailnotify -news 
    132 </verbatim> 
    133 will generate newsletters from *all* webs every week on midnight Saturday. 
     1320 0 * * 0 cd /usr/local/foswiki && perl -I bin tools/mailnotify -nochanges 
     133</verbatim> 
     134will generate newsletters from *all* webs every week on midnight Saturday but will not process the non-newsletter subscriptions. 
     135<verbatim> 
     1360 0 * * * cd /usr/local/foswiki && perl -I bin tools/mailnotify -nonews 
     137</verbatim> 
     138will generate change notifications for all webs every night at midnight but will not process the newsletter subscriptions. 
    134139 
    135140%X% Note: Multiple instances of mailnotify script are not allowed to be executed simutaneously. If you need to run the script multiple times with different options, make sure the cron jobs are scheduled so a previous run has finished before the next starts. You can also write a small script that runs mailnotify in sequence as described in Foswiki:Support.DuplicateNotificationsFromMailerCon. 
     141 
     142%X% Note: Even if you run separate -nonews and -nochanges cron jobs, the subscriptions using the "?" feature will only show the topics that changed since last time the mailnotify script was run even if it was run with -nonews. Separate newsletter jobs work best with the unconditional "!" mode. 
    136143 
    137144<!-- 
     
    205212|  Release: | %$RELEASE% | 
    206213|  Change History: | | 
    207 |  15 Oct 2009 | Foswikitask:Item2260. Make the feature that allows defining the email template based in either skin or web path. And improve the documentation so people can learn how to tailor the emails that the WebNotify feature sends. <br /> Foswikitask:Item1603: use quotes to protect topic names with odd characters in them | 
     214|  17 Oct 2009 | Foswikitask:Item1302: Removed the documentation of the -news mode which was actually never really implemented. Instead added two new -nonews and -nochanges modes which enables running mailnotify in newsletter mode with another schedule than the changes mode. If you upgrade and used the -news option with mailnotify things will work like you are used to as the -news option made no difference (old bug). | 
     215|  15 Oct 2009 | Foswikitask:Item2260: Make the feature that allows defining the email template based in either skin or web path. And improve the documentation so people can learn how to tailor the emails that the WebNotify feature sends. <br /> Foswikitask:Item1603: use quotes to protect topic names with odd characters in them | 
    208216|  20 Sep 2009 | Small documentation update for Foswiki 1.0.7 release (RELEASE and adding parent) | 
    209217|  23 Apr 2009 | Foswikitask:Item1501: Minor bug in logfile output fixed | 
  • branches/Release01x00/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm

    r5269 r5288  
    2727 
    2828our $VERSION = '$Rev$'; 
    29 our $RELEASE = '15 Oct 2009'; 
     29our $RELEASE = '17 Oct 2009'; 
    3030our $SHORTDESCRIPTION = 'Supports e-mail notification of changes'; 
    3131 
    3232our $verbose = 0; 
     33our $nonews = 0; 
     34our $nochanges = 0; 
    3335 
    3436# PROTECTED STATIC ensure the contrib is initernally initialised 
     
    4042=pod 
    4143 
    42 ---++ StaticMethod mailNotify($webs, $session, $verbose, $exwebs) 
     44---++ StaticMethod mailNotify($webs, $session, $verbose, $exwebs, $nonewsmode, $nochangesmode) 
    4345   * =$webs= - filter list of names webs to process. Wildcards (*) may be used. 
    4446   * =$session= - optional session object. If not given, will use a local object. 
    4547   * =$verbose= - true to get verbose (debug) output. 
    4648   * =$exwebs = - filter list of webs to exclude. 
     49   * =$nonewsmode = the notify script was called with the -nonews option so we skip news mode 
     50   * =$nochangesmode = the notify script was called with the -nochanges option 
    4751 
    4852Main entry point. 
     
    5559 
    5660sub mailNotify { 
    57     my ( $webs, $twiki, $noisy, $exwebs ) = @_; 
     61    my ( $webs, $twiki, $noisy, $exwebs, $nonewsmode, $nochangesmode ) = @_; 
    5862 
    5963    $verbose = $noisy; 
     64    $nonews = $nonewsmode || 0; 
     65    $nochanges = $nochangesmode || 0; 
    6066 
    6167    my $webstr; 
     
    208214# PRIVATE: Read the webnotify, and notify changes 
    209215sub _processWeb { 
    210     my ( $twiki, $web ) = @_; 
     216    my ( $twiki, $web, $nonews, $nochanges ) = @_; 
    211217 
    212218    if ( !Foswiki::Func::webExists($web) ) { 
     
    315321 
    316322    # Now generate emails for each recipient 
    317     my $report = 
    318       _sendChangesMails( $twiki, $web, \%changeset, 
    319         Foswiki::Time::formatTime($timeOfLastNotify) ); 
    320  
    321     $report .= _sendNewsletterMails( $twiki, $web, \%allSet ); 
    322  
     323    my $report = ''; 
     324     
     325    if ( !$nochanges ) { 
     326        $report .= _sendChangesMails( $twiki, $web, \%changeset, 
     327          Foswiki::Time::formatTime($timeOfLastNotify) ); 
     328    } 
     329 
     330    if ( !$nonews ) { 
     331        $report .= _sendNewsletterMails( $twiki, $web, \%allSet ); 
     332    } 
     333     
    323334    if ( $timeOfLastChange != 0 ) { 
    324335        if ( open( F, '>', $notmeta ) ) { 
  • branches/Release01x00/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm

    r3661 r5288  
    358358 
    359359    my @webs = ( $this->{test_web}, $this->{users_web} ); 
    360     Foswiki::Contrib::MailerContrib::mailNotify( \@webs, $this->{twiki}, 0 ); 
     360    Foswiki::Contrib::MailerContrib::mailNotify( \@webs, $this->{twiki}, 0, 0, 0 ); 
    361361 
    362362    #print "REPORT\n",join("\n\n", @FoswikiFnTestCase::mails); 
     
    415415 
    416416    my @webs = ( $testWeb2, $this->{users_web} ); 
    417     Foswiki::Contrib::MailerContrib::mailNotify( \@webs, $this->{twiki}, 0 ); 
     417    Foswiki::Contrib::MailerContrib::mailNotify( \@webs, $this->{twiki}, 0, 0, 0 ); 
    418418 
    419419    #print "REPORT\n",join("\n\n", @FoswikiFnTestCase::mails); 
     
    542542        $meta, "Before\n${s}After", $meta ); 
    543543    Foswiki::Contrib::MailerContrib::mailNotify( [ $this->{test_web} ], 
    544         $this->{twiki}, 0 ); 
     544        $this->{twiki}, 0, 0, 0 ); 
    545545 
    546546    my %matched; 
     
    571571        $meta, "Before\n${s}After", $meta ); 
    572572    Foswiki::Contrib::MailerContrib::mailNotify( [ $this->{test_web} ], 
    573         $this->{twiki}, 0 ); 
     573        $this->{twiki}, 0, 0, 0 ); 
    574574 
    575575    my %matched; 
  • branches/Release01x00/MailerContrib/tools/mailnotify

    r5269 r5288  
    3535my @webs = (); 
    3636my @exwebs = (); 
     37my $nonews = 0; 
     38my $nochanges = 0; 
    3739 
    3840# Called from the command line 
     
    4042    if( $arg eq "-q" ) { 
    4143        $verbose = 0; 
     44    } elsif ( $arg eq "-nonews" ) { 
     45        $nonews = 1; 
     46    } elsif ( $arg eq "-nochanges" ) { 
     47        $nochanges = 1; 
    4248    } elsif ( $arg =~ m/^-(.*)/ ) { 
    4349        push( @exwebs, $1 ); 
     
    5157 
    5258my $report = Foswiki::Contrib::MailerContrib::mailNotify( 
    53     \@webs, undef, $verbose, \@exwebs ); 
     59    \@webs, undef, $verbose, \@exwebs, $nonews, $nochanges ); 
    5460 
    5561print $report."\n" if $verbose; 
Note: See TracChangeset for help on using the changeset viewer.