Changeset 2328 for trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib.pm
- Timestamp:
- 02/03/09 13:05:52 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib.pm
r1323 r2328 2 2 # Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 3 3 # 4 # Copyright (C) 2009 Foswiki Contributors. All Rights Reserved. 5 # Foswiki Contributors are listed in the AUTHORS file in the root 6 # of this distribution. NOTE: Please extend that file, not this notice. 7 # 8 # Additional copyrights apply to some or all of the code in this module 9 # as follows: 4 10 # Copyright (C) 2005 TWiki Contributors. All Rights Reserved. 5 # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.6 # Foswiki Contributors are listed in the AUTHORS file in the root7 # of this distribution.8 # NOTE: Please extend that file, not this notice.9 11 # 10 12 # This program is free software; you can redistribute it and/or … … 23 25 use strict; 24 26 use Foswiki; 27 use Assert; 25 28 26 29 use Email::Folder; … … 164 167 } 165 168 } 166 unless ($received) {169 if (!$received && $mail->header('Date')) { 167 170 # Use the send date 168 171 $received = Time::ParseDate::parsedate($mail->header('Date')); … … 171 174 172 175 # Try to get the target topic by 173 # 1. examining the "To" address to see if it is a valid web.wikiname (if 174 # enabled in config) 175 # 2. if the subject line starts with a valid Foswiki Web.WikiName (if optionally 176 # followed by a colon, the rest of the subject line will be ignored) 176 # 1. examining the "To" and "cc" addresses to see if either has 177 # a valid web.wikiname (if enabled in config) 178 # 2. if the subject line starts with a valid Foswiki Web.WikiName 179 # (if optionally followed by a colon, the rest of the subject 180 # line will be ignored) 177 181 # 3. Routing the comment to the spambox if it is enabled 178 182 # 4. Otherwise replying to the user to say "no thanks" if replyonnotopic … … 191 195 $user = $targets->[0]; 192 196 } 193 my $to = $mail->header('To'); 194 $to =~ s/^.*<(.*)>.*$/$1/; 197 198 my @to = split(/,\s*/, $mail->header('To') || ''); 199 if (defined $mail->header('CC')) { 200 push(@to, split(/,\s*/, $mail->header('CC'))); 201 } 202 # Use the address in the <> if there is one 203 @to = map { /^.*<(.*)>.*$/ ? $1 : $_; } @to; 204 print STDERR "Targets: ", join(' ', @to),"\n" if $this->{debug}; 205 print STDERR "Subject: $subject\n" if $this->{debug}; 195 206 196 207 unless( $user ) { … … 204 215 } 205 216 206 print STDERR "User ",($user||'undefined'),"\n" if( $this->{debug} ); 207 208 if( $box->{topicPath} =~ /\bto\b/ && 209 $to =~ /^(?:($Foswiki::regex{webNameRegex})\.)($Foswiki::regex{wikiWordRegex})@/i) { 210 ( $web, $topic ) = ( $1, $2 ); 211 } 217 print STDERR "User is '",($user||'undefined'),"'\n" 218 if( $this->{debug} ); 219 220 # See if we can get a valid web.topic out of to: or cc: 221 if( $box->{topicPath} =~ /\bto\b/) { 222 foreach my $target (@to) { 223 next unless $target =~ /^(?:($Foswiki::regex{webNameRegex})\.)($Foswiki::regex{topicNameRegex})\@/i; 224 my ($guessweb, $guesstopic) = 225 Foswiki::Func::normalizeWebTopicName( 226 ($1 || $box->{defaultWeb}), $2); 227 if (Foswiki::Func::topicExists($guessweb, $guesstopic)) { 228 # Found an existing topic 229 ($web, $topic) = ($guessweb, $guesstopic); 230 last; 231 } 232 } 233 } 234 235 # If we didn't get the name of an existing topic from the 236 # To: or CC:, use the Subject: 212 237 if( !$topic && $box->{topicPath} =~ /\bsubject\b/ && 213 238 $subject =~ 214 s/^\s*(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{wikiWordRegex})(:\s*|\s*$)// ) { 215 ( $web, $topic ) = ( $1, $2 ); 239 /^\s*(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{topicNameRegex})(:\s*|\s*$)/ ) { 240 ($web, $topic) = Foswiki::Func::normalizeWebTopicName( 241 ($1 || $box->{defaultWeb}), $2); 242 # This time the topic doesn't have to exist 216 243 } 217 244 … … 402 429 print STDERR "Save topic $web.$topic:\n$text\n" if( $this->{debug} ); 403 430 431 ASSERT(!$meta || $meta->isa('Foswiki::Meta')) if DEBUG; 404 432 Foswiki::Func::saveTopic( 405 $web, $topic, $ text, $meta,433 $web, $topic, $meta, $text, 406 434 { comment => "Submitted by e-mail", 407 435 forcenewrevision => 1} );
Note: See TracChangeset
for help on using the changeset viewer.
