Changeset 5269 for branches/Release01x00/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscriber.pm
- Timestamp:
- 10/15/09 19:28:59 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Release01x00/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscriber.pm
r1340 r5269 67 67 my $this = shift; 68 68 69 unless ( defined( $this->{emails} ) ) {70 $this->{emails} = getEmailAddressesForUser( $this->{name} );69 unless ( defined( $this->{emails} ) ) { 70 $this->{emails} = getEmailAddressesForUser( $this->{name} ); 71 71 } 72 72 return $this->{emails}; … … 82 82 83 83 sub getEmailAddressesForUser { 84 my $name = shift;84 my $name = shift; 85 85 my $emails = []; 86 86 … … 89 89 if ( $name =~ /^$Foswiki::cfg{MailerContrib}{EmailFilterIn}$/ ) { 90 90 push( @{$emails}, $name ); 91 } else { 91 } 92 else { 92 93 my $users = $Foswiki::Plugins::SESSION->{users}; 93 if ($users->can('findUserByWikiName')) { 94 if ( $users->can('findUserByWikiName') ) { 95 94 96 # User is represented by a wikiname. Map to a canonical 95 97 # userid. 96 98 my $list = $users->findUserByWikiName($name); 97 99 foreach my $user (@$list) { 100 98 101 # Automatically expands groups 99 102 push( @{$emails}, $users->getEmails($user) ); 100 103 } 101 } else { 104 } 105 else { 106 102 107 # Old code; use the user object 103 108 my $user = $users->findUser( $name, undef, 1 ); 104 if ( $user) {109 if ($user) { 105 110 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) { 110 115 push( @{$emails}, $user->emails() ); 111 } else { 116 } 117 else { 118 112 119 # unknown - can't find an email 113 120 $emails = []; … … 123 130 # topics. 124 131 sub _addAndOptimise { 125 my ( $this, $set, $new ) = @_;132 my ( $this, $set, $new ) = @_; 126 133 127 134 # Don't add already covered duplicates 128 135 my $i = 0; 129 136 my @remove; 130 foreach my $known ( @{$this->{$set}}) {137 foreach my $known ( @{ $this->{$set} } ) { 131 138 return if $known->covers($new); 132 if( $new->covers( $known )) { 139 if ( $new->covers($known) ) { 140 133 141 # remove anything covered by the new subscription 134 unshift( @remove, $i);142 unshift( @remove, $i ); 135 143 } 136 144 $i++; 137 145 } 138 146 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 ); 142 150 } 143 151 … … 145 153 # you can in the face of wildcards. 146 154 sub _subtract { 147 my ( $this, $set, $new ) = @_;155 my ( $this, $set, $new ) = @_; 148 156 149 157 my $i = 0; 150 158 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 153 162 # remove anything covered by the new subscription 154 unshift( @remove, $i);163 unshift( @remove, $i ); 155 164 } 156 165 $i++; 157 166 } 158 167 foreach $i (@remove) { 159 splice( @{$this->{$set}}, $i, 1);168 splice( @{ $this->{$set} }, $i, 1 ); 160 169 } 161 170 } … … 193 202 194 203 $this->_addAndOptimise( 'unsubscriptions', $subs ); 195 if ($subs->matches('*')) { 204 if ( $subs->matches('*') ) { 205 196 206 # -* makes no sense and causes evaluation problems. 197 207 $this->_subtract( 'unsubscriptions', $subs ); 198 208 } 199 209 $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 202 213 #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'} }; 205 216 } 206 217 } … … 217 228 218 229 sub 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; 228 239 } 229 240 … … 238 249 239 250 sub 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; 249 260 } 250 261 … … 258 269 sub stringify { 259 270 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} } ); 266 275 $unsubs = " - $unsubs" if $unsubs; 267 276 268 277 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; 276 285 } 277 286
Note: See TracChangeset
for help on using the changeset viewer.
