Ignore:
Timestamp:
10/15/09 19:28:59 (3 years ago)
Author:
KennethLavrsen
Message:

Item2260: MailerContrib cannot find email templates based on skin or web
The checkin does the following

  • It makes a tiny little fix in MailerContrib.pm where I pushTopicContext before loading mail template and pop it again afterwards
  • Updates the the documentation to show by example how to tailor the mail message
  • Merge over the code from trunk. This introduces a bug fix from Item1603 which for some reason was only applied to trunk
  • And with this merge also merge over a lot of perl tinying.

It was too difficult to separate the two once I was this far. Look at next checkin in trunk to see only the actual code changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x00/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscriber.pm

    r1340 r5269  
    6767    my $this = shift; 
    6868 
    69     unless ( defined( $this->{emails} )) { 
    70         $this->{emails} = getEmailAddressesForUser( $this->{name}); 
     69    unless ( defined( $this->{emails} ) ) { 
     70        $this->{emails} = getEmailAddressesForUser( $this->{name} ); 
    7171    } 
    7272    return $this->{emails}; 
     
    8282 
    8383sub getEmailAddressesForUser { 
    84     my $name = shift; 
     84    my $name   = shift; 
    8585    my $emails = []; 
    8686 
     
    8989    if ( $name =~ /^$Foswiki::cfg{MailerContrib}{EmailFilterIn}$/ ) { 
    9090        push( @{$emails}, $name ); 
    91     } else { 
     91    } 
     92    else { 
    9293        my $users = $Foswiki::Plugins::SESSION->{users}; 
    93         if ($users->can('findUserByWikiName')) { 
     94        if ( $users->can('findUserByWikiName') ) { 
     95 
    9496            # User is represented by a wikiname. Map to a canonical 
    9597            # userid. 
    9698            my $list = $users->findUserByWikiName($name); 
    9799            foreach my $user (@$list) { 
     100 
    98101                # Automatically expands groups 
    99102                push( @{$emails}, $users->getEmails($user) ); 
    100103            } 
    101         } else { 
     104        } 
     105        else { 
     106 
    102107            # Old code; use the user object 
    103108            my $user = $users->findUser( $name, undef, 1 ); 
    104             if( $user ) { 
     109            if ($user) { 
    105110                push( @{$emails}, $user->emails() ); 
    106             } else { 
    107                 $user = $users->findUser( 
    108                     $name, $name, 1 ); 
    109                 if( $user ) { 
     111            } 
     112            else { 
     113                $user = $users->findUser( $name, $name, 1 ); 
     114                if ($user) { 
    110115                    push( @{$emails}, $user->emails() ); 
    111                 } else { 
     116                } 
     117                else { 
     118 
    112119                    # unknown - can't find an email 
    113120                    $emails = []; 
     
    123130# topics. 
    124131sub _addAndOptimise { 
    125     my( $this, $set, $new ) = @_; 
     132    my ( $this, $set, $new ) = @_; 
    126133 
    127134    # Don't add already covered duplicates 
    128135    my $i = 0; 
    129136    my @remove; 
    130     foreach my $known (@{$this->{$set}}) { 
     137    foreach my $known ( @{ $this->{$set} } ) { 
    131138        return if $known->covers($new); 
    132         if( $new->covers( $known )) { 
     139        if ( $new->covers($known) ) { 
     140 
    133141            # remove anything covered by the new subscription 
    134             unshift(@remove, $i); 
     142            unshift( @remove, $i ); 
    135143        } 
    136144        $i++; 
    137145    } 
    138146    foreach $i (@remove) { 
    139         splice(@{$this->{$set}}, $i, 1); 
    140     } 
    141     push( @{$this->{$set}}, $new ); 
     147        splice( @{ $this->{$set} }, $i, 1 ); 
     148    } 
     149    push( @{ $this->{$set} }, $new ); 
    142150} 
    143151 
     
    145153# you can in the face of wildcards. 
    146154sub _subtract { 
    147     my( $this, $set, $new ) = @_; 
     155    my ( $this, $set, $new ) = @_; 
    148156 
    149157    my $i = 0; 
    150158    my @remove; 
    151     foreach my $known (@{$this->{$set}}) { 
    152         if( $new->covers( $known )) { 
     159    foreach my $known ( @{ $this->{$set} } ) { 
     160        if ( $new->covers($known) ) { 
     161 
    153162            # remove anything covered by the new subscription 
    154             unshift(@remove, $i); 
     163            unshift( @remove, $i ); 
    155164        } 
    156165        $i++; 
    157166    } 
    158167    foreach $i (@remove) { 
    159         splice(@{$this->{$set}}, $i, 1); 
     168        splice( @{ $this->{$set} }, $i, 1 ); 
    160169    } 
    161170} 
     
    193202 
    194203    $this->_addAndOptimise( 'unsubscriptions', $subs ); 
    195     if ($subs->matches('*')) { 
     204    if ( $subs->matches('*') ) { 
     205 
    196206        # -* makes no sense and causes evaluation problems. 
    197207        $this->_subtract( 'unsubscriptions', $subs ); 
    198208    } 
    199209    $this->_subtract( 'subscriptions', $subs ); 
    200     #TODO: should look at removing redundant exclusions ie a - SubScribe (2) when there is no positive subscription 
    201      
     210 
     211#TODO: should look at removing redundant exclusions ie a - SubScribe (2) when there is no positive subscription 
     212 
    202213    #if there are no subscriptions, there is no point luging around the unsubs 
    203     if (scalar(@{$this->{'subscriptions'}}) == 0) { 
    204         undef @{$this->{'unsubscriptions'}}; 
     214    if ( scalar( @{ $this->{'subscriptions'} } ) == 0 ) { 
     215        undef @{ $this->{'unsubscriptions'} }; 
    205216    } 
    206217} 
     
    217228 
    218229sub isSubscribedTo { 
    219    my ( $this, $topic, $db ) = @_; 
    220  
    221    foreach my $subscription ( @{$this->{subscriptions}} ) { 
    222        if ( $subscription->matches( $topic, $db )) { 
    223            return $subscription; 
    224        } 
    225    } 
    226  
    227    return undef; 
     230    my ( $this, $topic, $db ) = @_; 
     231 
     232    foreach my $subscription ( @{ $this->{subscriptions} } ) { 
     233        if ( $subscription->matches( $topic, $db ) ) { 
     234            return $subscription; 
     235        } 
     236    } 
     237 
     238    return; 
    228239} 
    229240 
     
    238249 
    239250sub isUnsubscribedFrom { 
    240    my ( $this, $topic, $db ) = @_; 
    241  
    242    foreach my $subscription ( @{$this->{unsubscriptions}} ) { 
    243        if ( $subscription->matches( $topic, $db )) { 
    244            return $subscription; 
    245        } 
    246    } 
    247  
    248    return undef; 
     251    my ( $this, $topic, $db ) = @_; 
     252 
     253    foreach my $subscription ( @{ $this->{unsubscriptions} } ) { 
     254        if ( $subscription->matches( $topic, $db ) ) { 
     255            return $subscription; 
     256        } 
     257    } 
     258 
     259    return; 
    249260} 
    250261 
     
    258269sub stringify { 
    259270    my $this = shift; 
    260     my $subs = join( ' ', 
    261                      map { $_->stringify(); } 
    262                      @{$this->{subscriptions}} ); 
    263     my $unsubs = join( " - ", 
    264                        map { $_->stringify(); } 
    265                        @{$this->{unsubscriptions}} ); 
     271    my $subs = 
     272      join( ' ', map { $_->stringify(); } @{ $this->{subscriptions} } ); 
     273    my $unsubs = 
     274      join( " - ", map { $_->stringify(); } @{ $this->{unsubscriptions} } ); 
    266275    $unsubs = " - $unsubs" if $unsubs; 
    267276 
    268277    my $name = $this->{name}; 
    269     if ($name =~ /^$Foswiki::regex{wikiWordRegex}$/) { 
    270         $name = '%USERSWEB%.'.$name; 
    271     } elsif ($name !~ /^$Foswiki::cfg{MailerContrib}{EmailFilterIn}$/) { 
    272         $name = $name =~ /'/ ? '"'.$name.'"' : "'$name'"; 
    273     } 
    274     return "   * " . $name . ": " . 
    275       $subs . $unsubs; 
     278    if ( $name =~ /^$Foswiki::regex{wikiWordRegex}$/ ) { 
     279        $name = '%USERSWEB%.' . $name; 
     280    } 
     281    elsif ( $name !~ /^$Foswiki::cfg{MailerContrib}{EmailFilterIn}$/ ) { 
     282        $name = $name =~ /'/ ? '"' . $name . '"' : "'$name'"; 
     283    } 
     284    return "   * " . $name . ": " . $subs . $unsubs; 
    276285} 
    277286 
Note: See TracChangeset for help on using the changeset viewer.