Changeset 1323
- Timestamp:
- 12/13/08 16:58:36 (3 years ago)
- Location:
- trunk/MailInContrib
- Files:
-
- 8 edited
- 3 moved
-
data/System (moved) (moved from trunk/MailInContrib/data/TWiki)
-
data/System/MailInContrib.txt (modified) (9 diffs)
-
lib/Foswiki (moved) (moved from trunk/MailInContrib/lib/TWiki)
-
lib/Foswiki/Contrib/MailInContrib.pm (modified) (27 diffs)
-
lib/Foswiki/Contrib/MailInContrib/Config.spec (modified) (1 diff)
-
lib/Foswiki/Contrib/MailInContrib/DEPENDENCIES (modified) (1 diff)
-
lib/Foswiki/Contrib/MailInContrib/MANIFEST (modified) (1 diff)
-
lib/Foswiki/Contrib/MailInContrib/build.pl (modified) (2 diffs)
-
pub/System (moved) (moved from trunk/MailInContrib/pub/TWiki)
-
test/unit/MailInContrib/MailInContribSuite.pm (modified) (12 diffs)
-
tools/mailincron (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/MailInContrib/data/System/MailInContrib.txt
r878 r1323 1 ---+!! <nop>Mail InContrib for TWiki1 ---+!! <nop>Mail In to Foswiki 2 2 %SHORTDESCRIPTION% 3 3 <a href="http://wikiring.com"><img src="%ATTACHURL%/logo.gif" style="float:right" /></a> 4 This Contrib supports the submission of content to TWiki topics via e-mail.4 This Contrib supports the submission of content to Foswiki topics via e-mail. 5 5 6 6 <!-- … … 11 11 you make will simply be overwritten the next time a release is generated. 12 12 13 Instead, you could check your fix in, raise a bug in the Bugs web, or mail the author.13 Instead, you could check your fix in, raise a bug in the Tasks web, or mail the author. 14 14 --> 15 15 16 <div class="twikiBroadcastMessage" style="background-color:#ffc;">WARNING: TWiki-4 only. If you want to use this extension with an earlier version of TWiki, please use [[http://twiki.org/cgi-bin/attach/Plugins/%TOPIC%?filename=%TOPIC%.zip&revInfo=1][revision 7 of the zip]].</div> 16 Mails can be pulled out of mail folders using [[CPAN:Email::Folder::POP3][POP3]], [[CPAN:Email::Folder::IMAP][IMAP]], or anything else supported by CPAN:Email::Folder. 17 17 18 Mails for twiki can be pulled out of mail folders using [[CPAN:Email::Folder::POP3][POP3]], [[CPAN:Email::Folder::IMAP][IMAP]], or anything else supported by CPAN:Email::Folder. 19 20 The implementation is very simple; a script called =mailincron= is run every so often (usually by =cron= or an equivalent offline job scheduler). The script trawls the mail folders you specify and grabs messages that it recognises as being for the TWiki. 18 The implementation is very simple; a script called =mailincron= is run every so often (usually by =cron= or an equivalent offline job scheduler). The script trawls the mail folders you specify and grabs messages that it recognises as being for the wiki. 21 19 22 20 For example, your wayward child might send a mail like this from an internet cafe in Thailand: … … 28 26 *Phuket*: I've run out of money! 29 27 </verbatim> 30 The message lands in your email folder at your ISP. Once an hour, a cron job runs the =mailincron= script, which scans the folder. If it finds any messages that have nothing but a correctly formatted TWikiWeb.Topic<nop>Name in the subject line, that topic is appended to (created) with the plain text of the email. The Web must exist, though the topic will be created if necessary. Both web and topic _must_ be specified.28 The message lands in your email folder at your ISP. Once an hour, a cron job runs the =mailincron= script, which scans the folder. If it finds any messages that have nothing but a correctly formatted Web.Topic<nop>Name in the subject line, that topic is appended to (created) with the plain text of the email. The Web must exist, though the topic will be created if necessary. Both web and topic _must_ be specified. 31 29 32 30 In our example, the web exists, and so does the topic, so the following text gets appended to Travels.Daily<nop>Diary: … … 38 36 39 37 </div> 40 Attachments to the mail get treated as attachments by TWiki, and attached to the target topic.38 Attachments to the mail get treated as attachments by Foswiki, and attached to the target topic. 41 39 42 40 Note that =mailincron= will only process messages that have arrived since the last time it ran. So if there was an error adding a mail, it won't attempt to add it again even if it is still in the inbox. … … 51 49 The module can use special HTML comments in the topic to decide where to insert new emails within the text. 52 50 53 If it sees the comment =<!--MAIL-->= it will insert the incoming mail immediately *below* the comment. =MAIL= is rather ike a TWikiVariable; you can give it parameters. For example, =<!--MAIL{where="below"}-->=. The following options are available:51 If it sees the comment =<!--MAIL-->= it will insert the incoming mail immediately *below* the comment. =MAIL= is rather ike a [[%SYSTEMWEB%.Macro][Foswiki macro]]; you can give it parameters. For example, =<!--MAIL{where="below"}-->=. The following options are available: 54 52 * =where= - can be =above=, =below= (relative to the comment) =top=, =bottom= (of the topic) 55 53 * =template= set to the name of one of the templates in %SYSTEMWEB%.MailInContribTemplate to change the formatting of comments. The default format is "below" format. … … 57 55 If there is no such comment in the topic, then it just appends it to the end. If there is more than one, only the first is recognised. 58 56 59 Any attachments in the mail get added to the target topic as TWikiattachments. Attachments are also listed immediately below the mail body in the topic.57 Any attachments in the mail get added to the target topic as attachments. Attachments are also listed immediately below the mail body in the topic. 60 58 61 59 ---+ How the contributor is identified 62 The user identity is used for access control checks on the target topic, so you can use TWiki access controls to protect target topics.60 The user identity is used for access control checks on the target topic, so you can use Foswiki access controls to protect target topics. 63 61 64 62 You can configure the module to look at the =From:= entry in the email, and if a registered user has set that email (see ChangeEmailAddress), then they are identified as the contributor. Note that there is a security risk here, as the =From:= address in e-mail can easily be spoofed. … … 67 65 68 66 <!-- 69 * Set SHORTDESCRIPTION = Supports submissions to TWiki via e-mail67 * Set SHORTDESCRIPTION = Supports submissions to Foswiki via e-mail 70 68 --> 71 69 … … 74 72 75 73 __Note__: The CPAN =Email= modules uses *many* pluggable modules to support different folder types. It's impossible to cover all the options here; all we can suggest is that you try running the script from the command-line and resolve missing modules as you find them. 76 * Set up cron (or equivalent) jobs to run =mailincron=. You must =cd= to the TWiki bindirectory, and invoke the sript from there (this is so =mailincron= can read =setlib.cfg=)74 * Set up cron (or equivalent) jobs to run =mailincron=. You must =cd= to the =bin= directory, and invoke the sript from there (this is so =mailincron= can read =setlib.cfg=) 77 75 78 76 Because of the security issues involved (passwords for the mailboxes etc.) configuration uses variables set in your =LocalSite.cfg=. The easiest way to set them is using =configure=. 79 77 80 The =mailincron= script takes one optional parameter, <tt>debug</tt>, which takes a boolean value e.g. <tt>debug=1</tt>. If you pass anything other than 0 or the empty string in =debug=, the script will scan the mail folders, describe what it would have done, and exit, without modifying any folders, the TWiki, or sending any mails.78 The =mailincron= script takes one optional parameter, <tt>debug</tt>, which takes a boolean value e.g. <tt>debug=1</tt>. If you pass anything other than 0 or the empty string in =debug=, the script will scan the mail folders, describe what it would have done, and exit, without modifying any folders, the wiki, or sending any mails. 81 79 82 To run the script you need to set up a cron job. For example, to transfer mail into the TWiki once every hour you might write:80 To run the script you need to set up a cron job. For example, to transfer mail into the wiki once every hour you might write: 83 81 <verbatim> 84 0 * * * * cd /home/twiki/bin && ../tools/mailincron 2 &>1 >> /home/twiki/logs/mailincron.log82 0 * * * * cd /home/twiki/bin && ../tools/mailincron 2>&1 >> /home/twiki/logs/mailincron.log 85 83 </verbatim> 86 84 You _must_ run the script from the bin directory. 87 Make sure that the cron is run by a user with the permissions needed to read and write the TWiki data directory. 88 89 This is a brand-new development, not related in any to the original Foswiki:Extensions/MailInAddon. Due acknowledgement is made to those early pioneers for the idea. ;-) 85 Make sure that the cron is run by a user with the permissions needed to read and write the =data= directory. 90 86 91 87 ---++ Contrib Info 92 88 93 Another great TWiki 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!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! 94 90 95 91 Many thanks to the following sponsors for supporting this work: 96 92 * [[http://www.evolvedmedianetwork.com][Evolved Media Network]] 97 93 98 | Author: | TWiki:Main/CrawfordCurrie (http://c-dot.co.uk) |99 | Copyright ©: | 2005, TWiki Contributors |94 | Author: | Foswiki:Main.CrawfordCurrie (http://c-dot.co.uk) | 95 | Copyright ©: | 2005, TWiki Contributors; 2008 Foswiki Contributors | 100 96 | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | 101 97 | Dependencies: | %$DEPENDENCIES% | … … 119 115 | 10 Mar 2005 | 1.000 Initial version | 120 116 | Home: | Foswiki:Extensions/%TOPIC% | 121 | Feedback: | Foswiki:Extensions/%TOPIC%Dev |122 | Appraisal: | http://foswiki.org/Extensions/%TOPIC%Appraisal |123 117 124 118 __Related Topics:__ %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib.pm
r1050 r1323 3 3 # 4 4 # Copyright (C) 2005 TWiki Contributors. All Rights Reserved. 5 # TWiki Contributors are listed in the AUTHORS file in the root 5 # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. 6 # Foswiki Contributors are listed in the AUTHORS file in the root 6 7 # of this distribution. 7 8 # NOTE: Please extend that file, not this notice. … … 18 19 # 19 20 # As per the GPL, removal of this notice is prohibited. 20 package TWiki::Contrib::MailInContrib;21 package Foswiki::Contrib::MailInContrib; 21 22 22 23 use strict; 23 use TWiki;24 use Foswiki; 24 25 25 26 use Email::Folder; … … 32 33 use Carp; 33 34 34 # This should always be $Rev: 10183$ so that TWiki can determine the checked-in35 # This should always be $Rev: 10183$ so that Foswiki can determine the checked-in 35 36 # status of the plugin. It is used by the build automation tools, so 36 37 # you should leave it alone. … … 62 63 63 64 ---++ ClassMethod new( $session ) 64 * =$session= - ref to a TWiki object65 * =$session= - ref to a Foswiki object 65 66 Construct a new inbox processor. 66 67 … … 74 75 75 76 # Find out when we last processed mail 76 my $workdir = TWiki::Func::getWorkArea('MailInContrib');77 my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); 77 78 if (-e "$workdir/timestamp") { 78 79 open(F, "<$workdir/timestamp") || die $!; … … 100 101 101 102 # re-stamp 102 my $workdir = TWiki::Func::getWorkArea('MailInContrib');103 my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); 103 104 open(F, ">$workdir/timestamp") || die $!; 104 105 print F time(),"\n"; … … 109 110 my $u = shift; 110 111 111 if ($ TWiki::Plugins::SESSION->{users}->can('getCanonicalUserID')) {112 return $ TWiki::Plugins::SESSION->{users}->getCanonicalUserID($u);112 if ($Foswiki::Plugins::SESSION->{users}->can('getCanonicalUserID')) { 113 return $Foswiki::Plugins::SESSION->{users}->getCanonicalUserID($u); 113 114 } else { 114 return $ TWiki::Plugins::SESSION->{users}->findUser( $u );115 return $Foswiki::Plugins::SESSION->{users}->findUser( $u ); 115 116 } 116 117 } … … 121 122 * =$box= - hash describing the box 122 123 Scan messages in the box that have been received since the last run, 123 and process them for inclusion in TWiki topics.124 and process them for inclusion in Foswiki topics. 124 125 125 126 =cut … … 128 129 my( $this, $box ) = @_; 129 130 130 $ TWiki::Plugins::SESSION = $this->{session};131 $Foswiki::Plugins::SESSION = $this->{session}; 131 132 132 133 die "No folder specification" unless $box->{folder}; … … 148 149 149 150 # Load the file of mail templates 150 my $templates = TWiki::Func::loadTemplate( 'MailInContrib' );151 my $templates = Foswiki::Func::loadTemplate( 'MailInContrib' ); 151 152 152 153 print STDERR "Scanning $box->{folder}\n" if $this->{debug}; … … 172 173 # 1. examining the "To" address to see if it is a valid web.wikiname (if 173 174 # enabled in config) 174 # 2. if the subject line starts with a valid TWiki Web.WikiName (if optionally175 # 2. if the subject line starts with a valid Foswiki Web.WikiName (if optionally 175 176 # followed by a colon, the rest of the subject line will be ignored) 176 177 # 3. Routing the comment to the spambox if it is enabled … … 206 207 207 208 if( $box->{topicPath} =~ /\bto\b/ && 208 $to =~ /^(?:($ TWiki::regex{webNameRegex})\.)($TWiki::regex{wikiWordRegex})@/i) {209 $to =~ /^(?:($Foswiki::regex{webNameRegex})\.)($Foswiki::regex{wikiWordRegex})@/i) { 209 210 ( $web, $topic ) = ( $1, $2 ); 210 211 } 211 212 if( !$topic && $box->{topicPath} =~ /\bsubject\b/ && 212 213 $subject =~ 213 s/^\s*(?:($ TWiki::regex{webNameRegex})\.)?($TWiki::regex{wikiWordRegex})(:\s*|\s*$)// ) {214 s/^\s*(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{wikiWordRegex})(:\s*|\s*$)// ) { 214 215 ( $web, $topic ) = ( $1, $2 ); 215 216 } … … 219 220 print STDERR "Topic $web.",$topic||'',"\n" if $this->{debug}; 220 221 221 unless( TWiki::Func::webExists( $web )) {222 unless( Foswiki::Func::webExists( $web )) { 222 223 $topic = ''; 223 224 } … … 243 244 if( $received > $this->{lastMailIn} ) { 244 245 my $err = ''; 245 unless( $this->{session}->{store}->webExists( $web )) {246 unless( Foswiki::Func::webExists( $web )) { 246 247 $err = "Web $web does not exist"; 247 248 } else { … … 261 262 $this->_onError( 262 263 $box, $mail, 263 " TWiki encountered an error while adding your mail to $web.$topic: $err", \%kill, $num );264 "Foswiki encountered an error while adding your mail to $web.$topic: $err", \%kill, $num ); 264 265 } else { 265 266 if( $box->{onSuccess} =~ /\breply\b/ ) { … … 279 280 eval 'use Email::Delete'; 280 281 if( $@ ) { 281 TWiki::writeWarning( "Cannot delete from inbox: $@\n" );282 Foswiki::writeWarning( "Cannot delete from inbox: $@\n" ); 282 283 } else { 283 284 Email::Delete::delete_message … … 304 305 305 306 if( $box->{onError} =~ /\blog\b/ ) { 306 TWiki::Func::writeWarning( $mess );307 Foswiki::Func::writeWarning( $mess ); 307 308 } 308 309 if( $box->{onError} =~ /\breply\b/ ) { 309 310 $this->_reply( $box, $mail, 310 " TWiki found an error in your e-mail submission\n\n$mess\n\n".311 "Foswiki found an error in your e-mail submission\n\n$mess\n\n". 311 312 $mail->as_string()); 312 313 } … … 341 342 my $err = ''; 342 343 344 my $curUser = $Foswiki::Plugins::SESSION->{user}; 345 $Foswiki::Plugins::SESSION->{user} = $user; 346 343 347 try { 344 my( $meta, $text ) = $this->{session}->{store}->readTopic( 345 $user, $web, $topic ); 348 my( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); 346 349 347 350 my $opts; 348 351 if( $text =~ /<!--MAIL(?:{(.*?)})?-->/ ) { 349 $opts = new TWiki::Attrs( $1 );352 $opts = new Foswiki::Attrs( $1 ); 350 353 } else { 351 $opts = new TWiki::Attrs( '' );354 $opts = new Foswiki::Attrs( '' ); 352 355 } 353 356 $opts->{template} ||= 'normal'; … … 358 361 # MailInContribTemplate as MailInContribUserTemplate and edit to 359 362 # taste. - VickiBrown - 07 Sep 2007 360 my $insert = TWiki::Func::expandTemplate( 'MAILIN:'.$opts->{template} );363 my $insert = Foswiki::Func::expandTemplate( 'MAILIN:'.$opts->{template} ); 361 364 $insert ||= " * *%SUBJECT%*: %TEXT% _%WIKIUSERNAME% @ %SERVERTIME%_\n"; 362 365 $insert =~ s/%SUBJECT%/$subject/g; … … 367 370 foreach my $att ( @$attachments ) { 368 371 $attached = 1; 369 $err .= $this->_saveAttachment( $ user, $web, $topic, $att );370 my $tmpl = TWiki::Func::expandTemplate(372 $err .= $this->_saveAttachment( $web, $topic, $att ); 373 my $tmpl = Foswiki::Func::expandTemplate( 371 374 'MAILIN:'.$opts->{template}.':ATTACHMENT' ); 372 375 if( $tmpl ) { … … 380 383 381 384 $insert =~ s/%TEXT%/$body/g; 382 my $curUser = $TWiki::Plugins::SESSION->{user}; 383 $TWiki::Plugins::SESSION->{user} = $user; 384 $insert = TWiki::Func::expandVariablesOnTopicCreation($insert); 385 $TWiki::Plugins::SESSION->{user} = $curUser; 385 $insert = Foswiki::Func::expandVariablesOnTopicCreation($insert); 386 386 387 387 # Reload the topic if we added attachments. 388 388 if( $attached ) { 389 ( $meta, $text ) = $this->{session}->{store}->readTopic( 390 $user, $web, $topic ); 389 ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); 391 390 } 392 391 … … 403 402 print STDERR "Save topic $web.$topic:\n$text\n" if( $this->{debug} ); 404 403 405 $this->{session}->{store}->saveTopic( 406 $user, $web, $topic, $text, $meta, 407 { comment => "Submitted by e-mail" } ); 408 409 } catch TWiki::AccessControlException with { 404 Foswiki::Func::saveTopic( 405 $web, $topic, $text, $meta, 406 { comment => "Submitted by e-mail", 407 forcenewrevision => 1} ); 408 409 } catch Foswiki::AccessControlException with { 410 410 my $e = shift; 411 411 $err .= $e->stringify(); … … 413 413 my $e = shift; 414 414 $err .= $e->stringify(); 415 } finally { 416 $Foswiki::Plugins::SESSION->{user} = $curUser; 415 417 }; 416 418 return $err; … … 418 420 419 421 sub _saveAttachment { 420 my( $this, $ user, $web, $topic, $attachment ) = @_;422 my( $this, $web, $topic, $attachment ) = @_; 421 423 my $filename = $attachment->{filename}; 422 424 my $payload = $attachment->{payload}; … … 425 427 426 428 my $tmpfile = $web.'_'.$topic.'_'.$filename; 427 $tmpfile = $ TWiki::cfg{PubDir}.'/'.$tmpfile;429 $tmpfile = $Foswiki::cfg{PubDir}.'/'.$tmpfile; 428 430 429 431 $tmpfile .= 'X' while -e $tmpfile; … … 434 436 my $err = ''; 435 437 # SMELL: no central way to process attachment filenames, so we 436 # have to copy-paste the TWiki core code.438 # have to copy-paste the Foswiki core code. 437 439 $filename =~ s/ /_/go; 438 $filename =~ s/$ TWiki::cfg{NameFilter}//goi;439 $filename =~ s/$ TWiki::cfg{UploadFilter}/$1\.txt/goi;440 $this->{session}->{store}->saveAttachment(441 $web, $topic, $filename, $user,440 $filename =~ s/$Foswiki::cfg{NameFilter}//goi; 441 $filename =~ s/$Foswiki::cfg{UploadFilter}/$1\.txt/goi; 442 Foswiki::Func::saveAttachment( 443 $web, $topic, $filename, 442 444 { comment => "Submitted by e-mail", file => $tmpfile }); 443 445 unlink( $tmpfile ); … … 455 457 "To: $addressee" . 456 458 "\nFrom: ".$mail->header('To'). 457 "\nSubject: RE: your TWiki submission to ".$mail->header('Subject').459 "\nSubject: RE: your Foswiki submission to ".$mail->header('Subject'). 458 460 "\n\n$body\n"; 459 eval { 460 $TWiki::Plugins::SESSION->{net}->sendEmail( $message, 5 ); 461 }; 462 if ($@) { 463 print "Failed trying to send mail: $@\n"; 461 my $errors = Foswiki::Func::sendEmail( $message, 5 ); 462 if ($errors) { 463 print "Failed trying to send mail: $errors\n"; 464 464 } 465 465 } -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/Config.spec
r205 r1323 1 # ---+ MailInContrib 1 #---+ Mail and Proxies 2 #---++ Mail In 2 3 # **PERL** 3 4 # The configuration is in the form of an (perl) array of mailbox -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/DEPENDENCIES
r205 r1323 1 TWiki::Plugins,>=1.1,,This module requires TWiki-42 1 Time::ParseDate,>=2003.0211,cpan,Required. Available from the CPAN:Time::ParseDate archive. 3 Error,>=0.15,cpan,Required. Available from the CPAN:Error archive.4 2 Email::Folder,>=0.84,cpan,Required. Available from the CPAN:Email::Folder archive. 5 3 Email::FolderType::Net,>=1.02,cpan,Required. Available from the CPAN:Email::FolderType::Net archive. -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/MANIFEST
r205 r1323 1 1 tools/mailincron 0555 command-line perl script 2 data/ TWiki/MailInContrib.txt 0444 this topic3 data/ TWiki/MailInContribTemplate.txt 0444 file of templates4 lib/ TWiki/Contrib/MailInContrib.pm 0444 perl module5 lib/ TWiki/Contrib/MailInContrib/Config.spec 0444 configure spec2 data/System/MailInContrib.txt 0444 this topic 3 data/System/MailInContribTemplate.txt 0444 file of templates 4 lib/Foswiki/Contrib/MailInContrib.pm 0444 perl module 5 lib/Foswiki/Contrib/MailInContrib/Config.spec 0444 configure spec 6 6 lib/CPAN/lib/Email/Delete/IMAP.pm 0444 Extension to incomplete CPAN module 7 7 lib/CPAN/lib/Email/Delete/POP3.pm 0444 Extension to incomplete CPAN module 8 pub/ TWiki/MailInContrib/wikiringlogo20x20.png 06608 pub/System/MailInContrib/wikiringlogo20x20.png 0660 -
trunk/MailInContrib/lib/Foswiki/Contrib/MailInContrib/build.pl
r1065 r1323 1 1 #!/usr/bin/perl -w 2 #3 # Example build class. Copy this file to the equivalent place in your4 # plugin or contrib and edit.5 #6 # Requires the environment variable FOSWIKI_LIBS (a colon-separated path7 # list) to be set to point at the build system and any required dependencies.8 # Usage: ./build.pl [-n] [-v] [target]9 # where [target] is the optional build target (build, test,10 # install, release, uninstall), test is the default.11 # Two command-line options are supported:12 # -n Don't actually do anything, just print commands13 # -v Be verbose14 #15 16 # Standard preamble17 2 BEGIN { 18 3 foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) { … … 21 6 } 22 7 23 use TWiki::Contrib::Build; 24 25 # Declare our build package 26 { package MailInBuild; 27 28 @MailInBuild::ISA = ( "TWiki::Contrib::Build" ); 29 30 sub new { 31 my $class = shift; 32 return bless( $class->SUPER::new( "MailInContrib" ), $class ); 33 } 34 35 # Example: Override the build target 36 sub target_build { 37 my $this = shift; 38 39 $this->SUPER::target_build(); 40 41 # Do other build stuff here 42 } 43 } 8 use Foswiki::Contrib::Build; 44 9 45 10 # Create the build object 46 $build = new MailInBuild();11 $build = new Foswiki::Contrib::Build("MailInContrib"); 47 12 48 13 # Build the target on the command line, or the default target -
trunk/MailInContrib/test/unit/MailInContrib/MailInContribSuite.pm
r1064 r1323 2 2 3 3 package MailInContribSuite; 4 5 use base qw( FoswikiFnTestCase! ); 6 7 use TWiki; 4 use base 'FoswikiFnTestCase'; 5 6 use Foswiki; 8 7 use Error qw( :try ); 9 8 use File::Path; 10 9 use Error qw( :try ); 11 use TWiki::Contrib::MailInContrib;10 use Foswiki::Contrib::MailInContrib; 12 11 13 12 my $box; … … 23 22 $this->{twiki}->{store}->createWeb( 24 23 $this->{twiki}->{user}, $this->{system_web}, 25 $TWiki::cfg{SystemWebName} ); 24 $Foswiki::cfg{SystemWebName} ); 25 my $adm = Foswiki::Func::getCanonicalUserID( 26 $Foswiki::cfg{AdminUserWikiName}); 26 27 $this->{twiki}->{store}->saveTopic( 27 $ TWiki::cfg{AdminUserWikiName}, $this->{system_web},28 $adm, $this->{system_web}, 28 29 'WebPreferences', ""); 29 30 30 $ TWiki::cfg{SystemWebName} = $this->{system_web};31 $Foswiki::cfg{SystemWebName} = $this->{system_web}; 31 32 32 33 $this->{twiki}->finish(); 33 $this->{twiki} = new TWiki();34 35 my $workdir = TWiki::Func::getWorkArea('MailInContrib');34 $this->{twiki} = new Foswiki(); 35 36 my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); 36 37 open(F, ">$workdir/timestamp") || die $!; 37 38 print F "0\n"; … … 50 51 51 52 $this->{twiki}->finish(); 52 $this->{twiki} = new TWiki();53 $this->{twiki} = new Foswiki(); 53 54 $this->{twiki}->net->setMailHandler(\&sentMail); 54 55 55 56 $box = {}; 56 57 57 # Make a maildir 58 58 my $tmp = "/tmp/mail$$"; … … 62 62 $box->{folder} = "$tmp/"; 63 63 64 $ TWiki::cfg{MailInContrib} = [ $box ];64 $Foswiki::cfg{MailInContrib} = [ $box ]; 65 65 @mails = (); 66 66 } … … 94 94 sub cron { 95 95 my $this = shift; 96 my $min = new TWiki::Contrib::MailInContrib( $this->{twiki}, 0 );96 my $min = new Foswiki::Contrib::MailInContrib( $this->{twiki}, 0 ); 97 97 $min->processInbox( $box ); 98 98 $min->wrapUp(); … … 119 119 and there is no valid default username', $c->{error}); 120 120 121 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic});121 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 122 122 123 123 $this->assert($t !~ /\S/, $t); … … 154 154 $this->assert_null($c->{error}); 155 155 156 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic});156 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 157 157 158 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); … … 190 190 $this->assert_null($c->{error}); 191 191 192 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic});192 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); 193 193 194 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); … … 223 223 $this->assert_null($c->{error}); 224 224 225 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'DangleBerries');225 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'DangleBerries'); 226 226 227 227 $t =~ s/\* \*no valid topic\*: Message 1 text here\s*-- $this->{users_web}.AllyGator -\s+\d+\s+\w+\s+\d+\s+-\s+\d+:\d+//s; … … 367 367 my $c = $this->cron(); 368 368 369 print STDERR "VBLO\n"; 369 370 $this->assert_equals(1, scalar(@mails)); 370 371 $this->assert_matches(qr/Thank you for your successful/, $mails[0]); 371 372 372 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'AnotherTopic');373 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'AnotherTopic'); 373 374 my @a = $m->get('FILEATTACHMENT'); 374 375 $this->assert_equals(1, scalar(@a)); 375 376 $this->assert_str_equals("data.asc", $a[0]->{attachment}); 376 377 377 $this->assert(-e "$ TWiki::cfg{PubDir}/$this->{test_web}/AnotherTopic/data.asc");378 $this->assert(-e "$Foswiki::cfg{PubDir}/$this->{test_web}/AnotherTopic/data.asc"); 378 379 } 379 380 … … 395 396 $box->{onSuccess} = 'reply delete'; 396 397 $this->{twiki}->{store}->saveTopic( 397 $this->{twiki}->{user}, $ TWiki::cfg{SystemWebName},398 $this->{twiki}->{user}, $Foswiki::cfg{SystemWebName}, 398 399 'MailInContribUserTemplate', <<'HERE'); 399 400 %TMPL:DEF{MAILIN:wierd}% … … 414 415 $this->assert_matches(qr/Thank you for your successful/, $mails[0]); 415 416 416 my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'TargetTopic');417 my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'TargetTopic'); 417 418 418 419 $this->assert_matches(qr/BEGIN\s*Subject: Object\s*Body: Message 1 text here\s*<!--MAIL{/s, $t); -
trunk/MailInContrib/tools/mailincron
r1050 r1323 4 4 # 5 5 # Copyright (C) 2005 TWiki Contributors. All Rights Reserved. 6 # TWiki Contributors are listed in the AUTHORS file in the root 6 # Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. 7 # Foswiki Contributors are listed in the AUTHORS file in the root 7 8 # of this distribution. 8 9 # NOTE: Please extend that file, not this notice. … … 26 27 } 27 28 28 use TWiki::Contrib::MailInContrib;29 use Foswiki::Contrib::MailInContrib; 29 30 30 31 my $debug; … … 43 44 } 44 45 45 my $twiki; 46 my $folders; 47 if( eval 'defined($TWiki::wikiversion)' ) { 48 TWiki::initialize(); 49 $twiki = undef; 50 eval "use LocalSite.cfg"; 51 } else { 52 $twiki = new TWiki(); 53 $TWiki::Plugins::SESSION = $twiki; 54 } 55 $folders = $TWiki::cfg{MailInContrib}; 56 my $processor = new TWiki::Contrib::MailInContrib($twiki, $debug); 46 my $session = new Foswiki(); 47 my $folders = $Foswiki::cfg{MailInContrib}; 48 my $processor = new Foswiki::Contrib::MailInContrib($session, $debug); 57 49 foreach my $folder ( @$folders ) { 58 50 $processor->processInbox( $folder );
Note: See TracChangeset
for help on using the changeset viewer.
