Changeset 2328


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

Location:
trunk/MailInContrib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MailInContrib/data/System/MailInContrib.txt

    r1323 r2328  
    4141 
    4242---+ Where the mail gets added 
    43 The target topic for a mail is normally specified in the =Subject:= of the mail. You just put Web.Topic as the first thing on the subject line, optionally followed by a colon and other subject text. Alternatively you can configure the module to examine the =To:= field in the mail and get the topic name from there instead. 
    44    * If a topic is specified, but doesn't exist, it will be created. 
    45    * If there is no web name specified, then you can configure a default web to accept those mails. 
    46    * If a non-existant web is specified, then it is an error. 
     43By default the target topic for mail is specified in the =Subject:= of the mail. You just put Web.Topic as the first thing on the subject line, optionally followed by a colon and other subject text. If there is no web name specified, then you can configure a default web to accept those mails. 
     44   * A mail with a subject of =Schedule.MyClass= will be saved to Schedule.<nop>MyClass 
     45   * =Subject: Schedule.MyClass: timetable= will be saved to Schedule.<nop>MyClass 
     46   * =Subject: MyClass= will be saved to &lt;default web>.<nop>MyClass.  
     47   * =Subject: MyClass: timetable= will be saved to &lt;default web>.<nop>MyClass, if the default web is set as =Schedule=.  
     48   * If a topic specified on the =Subject:= line doesn't exist, it will be created. 
     49 
     50You can also configure the module to examine the =To:= and =CC:= fields in the mail, and get the name of an existing topic from there instead. 
     51   * If a non-existant topic is specified, then it is an error. 
     52   * The first valid, existing topic found in the =To:= or =CC:= fields is taken, and overrides the =Subject:=. 
     53   * A mail addressed to =&lt;MyTopic@example.com>= will be saved in &lt;default web>.MyTopic 
     54   * A mail addressed to =&lt;Schedule.MyTopic@example.com>= will be saved in Schedule.<nop>MyTopic 
     55   * A mail addressed to ="Mylene Classe" &lt;Schedule.MyClass<nop>@example.com>= will be saved in Schedule.<nop>MyTopic 
     56   * A mail addressed to ="Mylene Classe" &lt;MyClass<nop>@example.com>= will be saved in &lt;default web>.<nop>MyTopic 
     57 
    4758You can also define a 'spambox' for each mail folder. A spambox is a topic that will take all messages that do _not_ have a valid topic. 
    4859 
     
    8798---++ Contrib Info 
    8899 
    89 Another great Foswiki extension from the <a style="text-decoration:none" href="http://wikiring.com"><img src="%ATTACHURLPATH%/wikiringlogo20x20.png" alt="" /> *WikiRing* </a> - working together to improve your wiki experience! 
     100Another great Foswiki extension from the <a style="text-decoration:none" href="http://wikiring.com"><img src="%ATTACHURLPATH%/wikiringlogo20x20.png" alt="" /> *WikiRing* </a> - *working together to improve your wiki experience!* 
    90101 
    91102Many thanks to the following sponsors for supporting this work: 
     
    93104 
    94105|  Author: | Foswiki:Main.CrawfordCurrie (http://c-dot.co.uk) | 
    95 |  Copyright &copy;: | 2005, TWiki Contributors; 2008 Foswiki Contributors | 
     106|  Copyright &copy;: | 2005, TWiki Contributors<br />2008-2009 Foswiki Contributors | 
    96107|  License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 
    97108|  Dependencies: | %$DEPENDENCIES% | 
    98109|  Version: | %$VERSION% | 
    99110| Change History: | | 
    100 |  1 Aug 2008 | Bugs:Item5450: minor doc fix | 
    101 |  8 Sep 2007 | Bugs:Item4575 various ideas from Dev topic, tested against 4.2.0 | 
    102 |  12412 | Fixed Bugs:Item3334 by removing dependency on !FuncUsersContrib | 
     111|  3 Feb 2009 | 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 | 
     112|  1 Aug 2008 | TWikibug:Item5450: minor doc fix | 
     113|  8 Sep 2007 | TWikibug:Item4575 various ideas from Dev topic, tested against 4.2.0 | 
     114|  12412 | Fixed TWikibug:Item3334 by removing dependency on !FuncUsersContrib | 
    103115|  10239 | Added support for listing attachments in-line with the mail | 
    104116|  10182 | Fixed parser failures on multipart MIME messages | 
  • trunk/MailInContrib/data/System/MailInContribTemplate.txt

    r672 r2328  
    44*DO NOT MODIFY THIS TOPIC* 
    55 
    6 This is a normal TWiki topic, but it is also a template file, as described in %SYSTEMWEB%.SkinTemplates. It contains the template definitions used by the MailInContrib to insert mail messages in topics. 
     6This is a normal topic, but it is also a template file, as described in %SYSTEMWEB%.SkinTemplates. It contains the template definitions used by the MailInContrib to insert mail messages in topics. 
    77 
    8 Each template is specified in the form of a pair of TWiki template definitions, (surrounded by verbatim tags below for readability). The template to use when inserting incoming mail in a topic is decided from the parameters in the =&lt;--MAIL--> comment in the topic. The default template is =normal=. 
     8Each template is specified in the form of a pair of template definitions, (surrounded by verbatim tags below for readability). The template to use when inserting incoming mail in a topic is decided from the parameters in the =&lt;--MAIL--> comment in the topic. The default template is =normal=. 
    99 
    1010<verbatim> 
     
    2121*DO NOT MODIFY THIS TOPIC* 
    2222 
    23 If you want to modify or add any templates, create the TWiki topic %SYSTEMWEB%.MailInContribUserTemplate. This topic is automatically included here if it exists, but it is *not* shipped with the MailInContrib. Any templates you define in %SYSTEMWEB%.MailInContribUserTemplate will override those defined here. 
     23If you want to modify or add any templates, create the topic %SYSTEMWEB%.MailInContribUserTemplate. This topic is automatically included here if it exists, but it is *not* shipped with the MailInContrib. You can create this topic in individual webs, as described in %SYSTEMWEB%.SkinTemplates. In this case the template will only apply in that specific web. 
    2424 
    2525<!-- The following line includes a *template* called "MailInUserContrib", which the template search rules automatically resolve to a *topic* called MailInContribUserTemplate. --> 
  • 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} ); 
  • trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/Config.spec

    r1323 r2328  
    6464#  </li> 
    6565# </ul> 
    66 $TWiki::cfg{MailInContrib} = [ 
     66$Foswiki::cfg{MailInContrib} = [ 
    6767 { 
    6868   folder => 'pop://example_user:password@example.com/Inbox', 
  • trunk/MailInContrib/test/unit/MailInContrib/MailInContribSuite.pm

    r1340 r2328  
    156156    my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 
    157157 
    158     $this->assert($t =~ s/^ *\* \*$this->{test_web}\.NotHere\*: Message 1 text here\s*-- $this->{users_web}\.MoleInnaHole -\s+\d+\s+\w+\s+\d+\s+-\s+\d+:\d+\n//m, $t); 
    159     $this->assert($t =~ s/^ *\* \*$this->{test_web}\.IgnoreThis\*: Message 2 text here\s*-- $this->{users_web}\.AllyGator -\s+\d+\s+\w+\s+\d+\s+-\s+\d+:\d+\n//m, $t); 
     158    $this->assert(0, $t) unless 
     159      $t =~ s/^\s*\*\s+\*$this->{test_web}\.NotHere\*:\s*//s; 
     160    $this->assert(0, $t) unless 
     161      $t =~ s/^Message 1 text here\s*//s; 
     162    $this->assert(0, $t) unless 
     163      $t =~ s/^_$this->{users_web}\.MoleInnaHole\s*\@\s*\d+\s+\w+\s+\d+\s+-\s+\d+:\d+_\s*//s; 
     164    $this->assert(0, $t) unless 
     165      $t =~ s/^ *\* \*$this->{test_web}\.IgnoreThis\*: //s; 
     166    $this->assert(0, $t) unless 
     167      $t =~ s/^Message 2 text here\s*//s; 
     168    $this->assert(0, $t) unless 
     169      $t =~ s/^_$this->{users_web}\.AllyGator\s*\@\s*\d+\s+\w+\s+\d+\s+-\s+\d+:\d+_//s; 
    160170 
    161171    $this->assert_matches(qr/^\s*$/, $t); 
     
    188198    $box->{topicPath} = 'subject'; 
    189199    my $c = $this->cron(); 
    190     $this->assert_null($c->{error}); 
    191  
    192     my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 
    193  
    194     $this->assert($t =~ s/^\s*\* \*\*: Message 1 text here\s* -- $this->{users_web}\.MoleInnaHole -\s+\d+\s+\w+\s+\d+\s+-\s+\d+:\d+$//m, $t); 
    195     $this->assert($t =~ s/^ *\* \*SPAM\*: Message 2 text here\s*-- $this->{users_web}\.AllyGator -\s+\d+\s+\w+\s+\d+\s+-\s+\d+:\d+$//m); 
    196  
     200    if ($c->{error}) { 
     201        print STDERR $c->{error},"\n"; 
     202        $this->assert_null($c->{error}); 
     203    } 
     204 
     205    my( $m, $t ) = Foswiki::Func::readTopic( 
     206        $this->{test_web}, $this->{test_topic}); 
     207 
     208    $this->assert(0, $t) unless 
     209      $t =~ s/^\s*\* \*$this->{test_web}.$this->{test_topic}\*: Message 1 text here\s*//s; 
     210    $this->assert(0, $t) unless 
     211      $t =~ s/^_$this->{users_web}\.MoleInnaHole\s*\@\s*\d+\s+\w+\s+\d+\s+-\s+\d+:\d+_//s; 
     212    $this->assert(0, $t) unless 
     213      $t =~ s/^\s*\*\s*\*$this->{test_web}.$this->{test_topic}: SPAM\*: Message 2 text here\s*//s; 
     214    $this->assert(0, $t) unless 
     215      $t =~ s/^_$this->{users_web}\.AllyGator\s*\@\s*\d+\s+\w+\s+\d+\s+-\s+\d+:\d+_//s; 
    197216    $this->assert_matches(qr/^\s*$/, $t); 
    198217    $this->assert_equals(0, scalar(@mails)); 
     
    297316To: "Dick Head" <dhead@twiki.com> 
    298317Subject: $this->{test_web}.AnotherTopic: attachment test 
    299 Cc: another.idiot@twiki.com> 
     318Cc: another.idiot@twiki.com 
    300319MIME-Version: 1.0 
    301320Content-Type: multipart/mixed;  
     
    367386    my $c = $this->cron(); 
    368387 
    369 print STDERR "VBLO\n"; 
    370388    $this->assert_equals(1, scalar(@mails)); 
    371389    $this->assert_matches(qr/Thank you for your successful/, $mails[0]); 
Note: See TracChangeset for help on using the changeset viewer.