Changeset 2328
- Timestamp:
- 02/03/09 13:05:52 (3 years ago)
- Location:
- trunk/MailInContrib
- Files:
-
- 5 edited
-
data/System/MailInContrib.txt (modified) (3 diffs)
-
data/System/MailInContribTemplate.txt (modified) (2 diffs)
-
lib/Foswiki/Contrib/MailInContrib.pm (modified) (7 diffs)
-
lib/Foswiki/Contrib/MailInContrib/Config.spec (modified) (1 diff)
-
test/unit/MailInContrib/MailInContribSuite.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/MailInContrib/data/System/MailInContrib.txt
r1323 r2328 41 41 42 42 ---+ 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. 43 By 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 <default web>.<nop>MyClass. 47 * =Subject: MyClass: timetable= will be saved to <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 50 You 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 =<MyTopic@example.com>= will be saved in <default web>.MyTopic 54 * A mail addressed to =<Schedule.MyTopic@example.com>= will be saved in Schedule.<nop>MyTopic 55 * A mail addressed to ="Mylene Classe" <Schedule.MyClass<nop>@example.com>= will be saved in Schedule.<nop>MyTopic 56 * A mail addressed to ="Mylene Classe" <MyClass<nop>@example.com>= will be saved in <default web>.<nop>MyTopic 57 47 58 You 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. 48 59 … … 87 98 ---++ Contrib Info 88 99 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!100 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!* 90 101 91 102 Many thanks to the following sponsors for supporting this work: … … 93 104 94 105 | Author: | Foswiki:Main.CrawfordCurrie (http://c-dot.co.uk) | 95 | Copyright ©: | 2005, TWiki Contributors ; 2008Foswiki Contributors |106 | Copyright ©: | 2005, TWiki Contributors<br />2008-2009 Foswiki Contributors | 96 107 | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 97 108 | Dependencies: | %$DEPENDENCIES% | 98 109 | Version: | %$VERSION% | 99 110 | 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 | 103 115 | 10239 | Added support for listing attachments in-line with the mail | 104 116 | 10182 | Fixed parser failures on multipart MIME messages | -
trunk/MailInContrib/data/System/MailInContribTemplate.txt
r672 r2328 4 4 *DO NOT MODIFY THIS TOPIC* 5 5 6 This is a normal TWikitopic, 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.6 This 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. 7 7 8 Each template is specified in the form of a pair of TWikitemplate 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 =<--MAIL--> comment in the topic. The default template is =normal=.8 Each 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 =<--MAIL--> comment in the topic. The default template is =normal=. 9 9 10 10 <verbatim> … … 21 21 *DO NOT MODIFY THIS TOPIC* 22 22 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.23 If 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. 24 24 25 25 <!-- 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 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} ); -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/Config.spec
r1323 r2328 64 64 # </li> 65 65 # </ul> 66 $ TWiki::cfg{MailInContrib} = [66 $Foswiki::cfg{MailInContrib} = [ 67 67 { 68 68 folder => 'pop://example_user:password@example.com/Inbox', -
trunk/MailInContrib/test/unit/MailInContrib/MailInContribSuite.pm
r1340 r2328 156 156 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 157 157 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; 160 170 161 171 $this->assert_matches(qr/^\s*$/, $t); … … 188 198 $box->{topicPath} = 'subject'; 189 199 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; 197 216 $this->assert_matches(qr/^\s*$/, $t); 198 217 $this->assert_equals(0, scalar(@mails)); … … 297 316 To: "Dick Head" <dhead@twiki.com> 298 317 Subject: $this->{test_web}.AnotherTopic: attachment test 299 Cc: another.idiot@twiki.com >318 Cc: another.idiot@twiki.com 300 319 MIME-Version: 1.0 301 320 Content-Type: multipart/mixed; … … 367 386 my $c = $this->cron(); 368 387 369 print STDERR "VBLO\n";370 388 $this->assert_equals(1, scalar(@mails)); 371 389 $this->assert_matches(qr/Thank you for your successful/, $mails[0]);
Note: See TracChangeset
for help on using the changeset viewer.
