Skip to content

Commit

Permalink
Item9459: Item10980: synch with trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@12241 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jul 26, 2011
1 parent 0da93de commit 26f3e2d
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 160 deletions.
54 changes: 6 additions & 48 deletions MailerContrib/data/System/MailerContrib.txt
Expand Up @@ -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. %<nop>HTML_TEXT% expands to the HTML obtained by expanding the =HTML:*= templates, and %<nop>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. %<nop>HTML_TEXT% expands to the HTML obtained by expanding the =HTML:*= templates, %<nop>PLAIN_TEXT% from the =PLAIN:*= templates, and %<nop>DIFF_TEXT from the =DIFF:*= templates%. |
The default template sends multipart emails containing both HTML and plaintext versions.

<blockquote class="foswikiHelp"> %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]].
Expand Down Expand Up @@ -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 |
Expand All @@ -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 Peter<nop>Thoeny provided additional documentation |
| 27 Sep 2004 | 1.001 runnable as CGI script, minor bugfixes, removed dependency on DB<nop>CacheContrib |
| 8 Sep 2004 | 1.000 Initial version |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| Support: | http://foswiki.org/Support/%TOPIC% |

Expand Down
79 changes: 50 additions & 29 deletions MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
64 changes: 63 additions & 1 deletion MailerContrib/lib/Foswiki/Contrib/MailerContrib/Change.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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} = '<verbatim>'.join("\n", @$blocks).'</verbatim>';
}

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;
}

Expand Down
41 changes: 0 additions & 41 deletions MailerContrib/lib/Foswiki/Contrib/MailerContrib/Constants.pm

This file was deleted.

1 change: 0 additions & 1 deletion MailerContrib/lib/Foswiki/Contrib/MailerContrib/MANIFEST
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm
Expand Up @@ -16,15 +16,20 @@ 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
---++ new($pages, $childDepth, $options)
* =$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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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 '';
Expand Down

0 comments on commit 26f3e2d

Please sign in to comment.