Ignore:
Timestamp:
02/03/09 13:05:52 (3 years ago)
Author:
CrawfordCurrie
Message:

Foswikitask:Item456: ported to Foswiki Foswikitask:Item4955: config options moved to 'Mail and Proxies' Foswikitask:Item5829: force new revision on each submission Foswikitask:Item5843: extract target topic from CC: field - general improvement to rules for extracting the target topic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib.pm

    r1323 r2328  
    22# Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    33# 
     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: 
    410# 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 root 
    7 # of this distribution. 
    8 # NOTE: Please extend that file, not this notice. 
    911# 
    1012# This program is free software; you can redistribute it and/or 
     
    2325use strict; 
    2426use Foswiki; 
     27use Assert; 
    2528 
    2629use Email::Folder; 
     
    164167            } 
    165168        } 
    166         unless ($received) { 
     169        if (!$received && $mail->header('Date')) { 
    167170            # Use the send date 
    168171            $received = Time::ParseDate::parsedate($mail->header('Date')); 
     
    171174 
    172175        # 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) 
    177181        #    3. Routing the comment to the spambox if it is enabled 
    178182        #    4. Otherwise replying to the user to say "no thanks" if replyonnotopic 
     
    191195            $user = $targets->[0]; 
    192196        } 
    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}; 
    195206 
    196207        unless( $user ) { 
     
    204215        } 
    205216 
    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: 
    212237        if( !$topic && $box->{topicPath} =~ /\bsubject\b/ && 
    213238              $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 
    216243        } 
    217244 
     
    402429        print STDERR "Save topic $web.$topic:\n$text\n" if( $this->{debug} ); 
    403430 
     431        ASSERT(!$meta || $meta->isa('Foswiki::Meta')) if DEBUG; 
    404432        Foswiki::Func::saveTopic( 
    405             $web, $topic, $text, $meta, 
     433            $web, $topic, $meta, $text, 
    406434            { comment => "Submitted by e-mail", 
    407435              forcenewrevision => 1} ); 
Note: See TracChangeset for help on using the changeset viewer.