From 118ef48910835d996ebabab75176228fd5717491 Mon Sep 17 00:00:00 2001 From: CrawfordCurrie Date: Sat, 13 Dec 2008 16:58:36 +0000 Subject: [PATCH] Item456: work in progress git-svn-id: http://svn.foswiki.org/trunk/MailInContrib@1323 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- data/{TWiki => System}/MailInContrib.txt | 44 ++++---- .../MailInContribTemplate.txt | 0 .../Contrib/MailInContrib.pm | 104 +++++++++--------- .../Contrib/MailInContrib/Config.spec | 3 +- .../Contrib/MailInContrib/DEPENDENCIES | 2 - lib/Foswiki/Contrib/MailInContrib/MANIFEST | 8 ++ lib/Foswiki/Contrib/MailInContrib/build.pl | 15 +++ lib/TWiki/Contrib/MailInContrib/MANIFEST | 8 -- lib/TWiki/Contrib/MailInContrib/build.pl | 50 --------- pub/{TWiki => System}/MailInContrib/logo.gif | Bin .../MailInContrib/wikiringlogo20x20.png | Bin test/unit/MailInContrib/MailInContribSuite.pm | 43 ++++---- tools/mailincron | 20 +--- 13 files changed, 124 insertions(+), 173 deletions(-) rename data/{TWiki => System}/MailInContrib.txt (73%) rename data/{TWiki => System}/MailInContribTemplate.txt (100%) rename lib/{TWiki => Foswiki}/Contrib/MailInContrib.pm (80%) rename lib/{TWiki => Foswiki}/Contrib/MailInContrib/Config.spec (98%) rename lib/{TWiki => Foswiki}/Contrib/MailInContrib/DEPENDENCIES (79%) create mode 100644 lib/Foswiki/Contrib/MailInContrib/MANIFEST create mode 100755 lib/Foswiki/Contrib/MailInContrib/build.pl delete mode 100644 lib/TWiki/Contrib/MailInContrib/MANIFEST delete mode 100755 lib/TWiki/Contrib/MailInContrib/build.pl rename pub/{TWiki => System}/MailInContrib/logo.gif (100%) rename pub/{TWiki => System}/MailInContrib/wikiringlogo20x20.png (100%) diff --git a/data/TWiki/MailInContrib.txt b/data/System/MailInContrib.txt similarity index 73% rename from data/TWiki/MailInContrib.txt rename to data/System/MailInContrib.txt index 2762207..69b5165 100644 --- a/data/TWiki/MailInContrib.txt +++ b/data/System/MailInContrib.txt @@ -1,7 +1,7 @@ ----+!! MailInContrib for TWiki +---+!! Mail In to Foswiki %SHORTDESCRIPTION% -This Contrib supports the submission of content to TWiki topics via e-mail. +This Contrib supports the submission of content to Foswiki topics via e-mail. -
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]].
+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. -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. - -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. +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. For example, your wayward child might send a mail like this from an internet cafe in Thailand: @@ -27,7 +25,7 @@ Subject: Travels.DailyDiary: cashless *Phuket*: I've run out of money! -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 TWiki Web.TopicName 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. +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.TopicName 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. In our example, the web exists, and so does the topic, so the following text gets appended to Travels.DailyDiary:
@@ -37,7 +35,7 @@ In our example, the web exists, and so does the topic, so the following text get -- Prodigal Son <gapper@isp.co.uk> 10 Jul 2005 08:35:11 -0900
-Attachments to the mail get treated as attachments by TWiki, and attached to the target topic. +Attachments to the mail get treated as attachments by Foswiki, and attached to the target topic. 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. @@ -50,53 +48,51 @@ You can also define a 'spambox' for each mail folder. A spambox is a topic that The module can use special HTML comments in the topic to decide where to insert new emails within the text. -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: +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: * =where= - can be =above=, =below= (relative to the comment) =top=, =bottom= (of the topic) * =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. 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. -Any attachments in the mail get added to the target topic as TWiki attachments. Attachments are also listed immediately below the mail body in the topic. +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. ---+ How the contributor is identified -The user identity is used for access control checks on the target topic, so you can use TWiki access controls to protect target topics. +The user identity is used for access control checks on the target topic, so you can use Foswiki access controls to protect target topics. 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. You can also optionally set a default user for an inbox, so if the user can't be identified from the mail, it will fall back to the default. ---++ Installation %$INSTALL_INSTRUCTIONS% __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. - * Set up cron (or equivalent) jobs to run =mailincron=. You must =cd= to the TWiki bin directory, and invoke the sript from there (this is so =mailincron= can read =setlib.cfg=) + * 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=) 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=. -The =mailincron= script takes one optional parameter, debug, which takes a boolean value e.g. debug=1. 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. +The =mailincron= script takes one optional parameter, debug, which takes a boolean value e.g. debug=1. 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. -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: +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: -0 * * * * cd /home/twiki/bin && ../tools/mailincron 2&>1 >> /home/twiki/logs/mailincron.log +0 * * * * cd /home/twiki/bin && ../tools/mailincron 2>&1 >> /home/twiki/logs/mailincron.log You _must_ run the script from the bin directory. -Make sure that the cron is run by a user with the permissions needed to read and write the TWiki data directory. - -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. ;-) +Make sure that the cron is run by a user with the permissions needed to read and write the =data= directory. ---++ Contrib Info -Another great TWiki extension from the *WikiRing* - working together to improve your wiki experience! +Another great Foswiki extension from the *WikiRing* - working together to improve your wiki experience! Many thanks to the following sponsors for supporting this work: * [[http://www.evolvedmedianetwork.com][Evolved Media Network]] -| Author: | TWiki:Main/CrawfordCurrie (http://c-dot.co.uk) | -| Copyright ©: | 2005, TWiki Contributors | +| Author: | Foswiki:Main.CrawfordCurrie (http://c-dot.co.uk) | +| Copyright ©: | 2005, TWiki Contributors; 2008 Foswiki Contributors | | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | | Dependencies: | %$DEPENDENCIES% | | Version: | %$VERSION% | @@ -118,8 +114,6 @@ Many thanks to the following sponsors for supporting this work: | 31 July 2005 | 1.001 Back-ported to Cairo, added spambox (work generously supported by the [[http://www.evolvedmedianetwork.com/][Evolved Media Network]]) | | 10 Mar 2005 | 1.000 Initial version | | Home: | Foswiki:Extensions/%TOPIC% | -| Feedback: | Foswiki:Extensions/%TOPIC%Dev | -| Appraisal: | http://foswiki.org/Extensions/%TOPIC%Appraisal | __Related Topics:__ %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences diff --git a/data/TWiki/MailInContribTemplate.txt b/data/System/MailInContribTemplate.txt similarity index 100% rename from data/TWiki/MailInContribTemplate.txt rename to data/System/MailInContribTemplate.txt diff --git a/lib/TWiki/Contrib/MailInContrib.pm b/lib/Foswiki/Contrib/MailInContrib.pm similarity index 80% rename from lib/TWiki/Contrib/MailInContrib.pm rename to lib/Foswiki/Contrib/MailInContrib.pm index 3bb38ed..1a54e4d 100644 --- a/lib/TWiki/Contrib/MailInContrib.pm +++ b/lib/Foswiki/Contrib/MailInContrib.pm @@ -2,7 +2,8 @@ # Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # # Copyright (C) 2005 TWiki Contributors. All Rights Reserved. -# TWiki Contributors are listed in the AUTHORS file in the root +# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved. +# Foswiki Contributors are listed in the AUTHORS file in the root # of this distribution. # NOTE: Please extend that file, not this notice. # @@ -17,10 +18,10 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # As per the GPL, removal of this notice is prohibited. -package TWiki::Contrib::MailInContrib; +package Foswiki::Contrib::MailInContrib; use strict; -use TWiki; +use Foswiki; use Email::Folder; use Email::FolderType::Net; @@ -31,7 +32,7 @@ use Error qw( :try ); use vars qw ( $VERSION $RELEASE ); use Carp; -# This should always be $Rev: 10183$ so that TWiki can determine the checked-in +# This should always be $Rev: 10183$ so that Foswiki can determine the checked-in # status of the plugin. It is used by the build automation tools, so # you should leave it alone. $VERSION = '$Rev: 10183$'; @@ -61,7 +62,7 @@ BEGIN { =pod ---++ ClassMethod new( $session ) - * =$session= - ref to a TWiki object + * =$session= - ref to a Foswiki object Construct a new inbox processor. =cut @@ -73,7 +74,7 @@ sub new { $this->{debug} = $debug; # Find out when we last processed mail - my $workdir = TWiki::Func::getWorkArea('MailInContrib'); + my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); if (-e "$workdir/timestamp") { open(F, "<$workdir/timestamp") || die $!; $this->{lastMailIn} = ; @@ -99,7 +100,7 @@ sub wrapUp { my $this = shift; # re-stamp - my $workdir = TWiki::Func::getWorkArea('MailInContrib'); + my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); open(F, ">$workdir/timestamp") || die $!; print F time(),"\n"; close(F); @@ -108,10 +109,10 @@ sub wrapUp { sub _getUser { my $u = shift; - if ($TWiki::Plugins::SESSION->{users}->can('getCanonicalUserID')) { - return $TWiki::Plugins::SESSION->{users}->getCanonicalUserID($u); + if ($Foswiki::Plugins::SESSION->{users}->can('getCanonicalUserID')) { + return $Foswiki::Plugins::SESSION->{users}->getCanonicalUserID($u); } else { - return $TWiki::Plugins::SESSION->{users}->findUser( $u ); + return $Foswiki::Plugins::SESSION->{users}->findUser( $u ); } } @@ -120,14 +121,14 @@ sub _getUser { ---++ ObjectMethod processInbox( $box ) * =$box= - hash describing the box Scan messages in the box that have been received since the last run, -and process them for inclusion in TWiki topics. +and process them for inclusion in Foswiki topics. =cut sub processInbox { my( $this, $box ) = @_; - $TWiki::Plugins::SESSION = $this->{session}; + $Foswiki::Plugins::SESSION = $this->{session}; die "No folder specification" unless $box->{folder}; @@ -147,7 +148,7 @@ sub processInbox { $box->{onSuccess} ||= 'log'; # Load the file of mail templates - my $templates = TWiki::Func::loadTemplate( 'MailInContrib' ); + my $templates = Foswiki::Func::loadTemplate( 'MailInContrib' ); print STDERR "Scanning $box->{folder}\n" if $this->{debug}; my $mail; # an Email::Simple object @@ -171,7 +172,7 @@ sub processInbox { # Try to get the target topic by # 1. examining the "To" address to see if it is a valid web.wikiname (if # enabled in config) - # 2. if the subject line starts with a valid TWiki Web.WikiName (if optionally + # 2. if the subject line starts with a valid Foswiki Web.WikiName (if optionally # followed by a colon, the rest of the subject line will be ignored) # 3. Routing the comment to the spambox if it is enabled # 4. Otherwise replying to the user to say "no thanks" if replyonnotopic @@ -205,12 +206,12 @@ sub processInbox { print STDERR "User ",($user||'undefined'),"\n" if( $this->{debug} ); if( $box->{topicPath} =~ /\bto\b/ && - $to =~ /^(?:($TWiki::regex{webNameRegex})\.)($TWiki::regex{wikiWordRegex})@/i) { + $to =~ /^(?:($Foswiki::regex{webNameRegex})\.)($Foswiki::regex{wikiWordRegex})@/i) { ( $web, $topic ) = ( $1, $2 ); } if( !$topic && $box->{topicPath} =~ /\bsubject\b/ && $subject =~ - s/^\s*(?:($TWiki::regex{webNameRegex})\.)?($TWiki::regex{wikiWordRegex})(:\s*|\s*$)// ) { + s/^\s*(?:($Foswiki::regex{webNameRegex})\.)?($Foswiki::regex{wikiWordRegex})(:\s*|\s*$)// ) { ( $web, $topic ) = ( $1, $2 ); } @@ -218,7 +219,7 @@ sub processInbox { print STDERR "Topic $web.",$topic||'',"\n" if $this->{debug}; - unless( TWiki::Func::webExists( $web )) { + unless( Foswiki::Func::webExists( $web )) { $topic = ''; } @@ -242,7 +243,7 @@ sub processInbox { if( $received > $this->{lastMailIn} ) { my $err = ''; - unless( $this->{session}->{store}->webExists( $web )) { + unless( Foswiki::Func::webExists( $web )) { $err = "Web $web does not exist"; } else { my $sender = $mail->header( 'From' ) || 'unknown'; @@ -260,7 +261,7 @@ sub processInbox { if( $err ) { $this->_onError( $box, $mail, - "TWiki encountered an error while adding your mail to $web.$topic: $err", \%kill, $num ); + "Foswiki encountered an error while adding your mail to $web.$topic: $err", \%kill, $num ); } else { if( $box->{onSuccess} =~ /\breply\b/ ) { $this->_reply( @@ -278,7 +279,7 @@ sub processInbox { eval 'use Email::Delete'; if( $@ ) { - TWiki::writeWarning( "Cannot delete from inbox: $@\n" ); + Foswiki::writeWarning( "Cannot delete from inbox: $@\n" ); } else { Email::Delete::delete_message ( from => $box->{folder}, @@ -303,11 +304,11 @@ sub _onError { print STDERR "ERROR: $mess\n" if( $this->{debug} ); if( $box->{onError} =~ /\blog\b/ ) { - TWiki::Func::writeWarning( $mess ); + Foswiki::Func::writeWarning( $mess ); } if( $box->{onError} =~ /\breply\b/ ) { $this->_reply( $box, $mail, - "TWiki found an error in your e-mail submission\n\n$mess\n\n". + "Foswiki found an error in your e-mail submission\n\n$mess\n\n". $mail->as_string()); } if( $box->{onError} =~ /\bdelete\b/ ) { @@ -340,15 +341,17 @@ sub _saveTopic { my( $this, $user, $web, $topic, $body, $subject, $attachments ) = @_; my $err = ''; + my $curUser = $Foswiki::Plugins::SESSION->{user}; + $Foswiki::Plugins::SESSION->{user} = $user; + try { - my( $meta, $text ) = $this->{session}->{store}->readTopic( - $user, $web, $topic ); + my( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); my $opts; if( $text =~ // ) { - $opts = new TWiki::Attrs( $1 ); + $opts = new Foswiki::Attrs( $1 ); } else { - $opts = new TWiki::Attrs( '' ); + $opts = new Foswiki::Attrs( '' ); } $opts->{template} ||= 'normal'; $opts->{where} ||= 'bottom'; @@ -357,7 +360,7 @@ sub _saveTopic { # the look and feel of the output pages is to copy # MailInContribTemplate as MailInContribUserTemplate and edit to # taste. - VickiBrown - 07 Sep 2007 - my $insert = TWiki::Func::expandTemplate( 'MAILIN:'.$opts->{template} ); + my $insert = Foswiki::Func::expandTemplate( 'MAILIN:'.$opts->{template} ); $insert ||= " * *%SUBJECT%*: %TEXT% _%WIKIUSERNAME% @ %SERVERTIME%_\n"; $insert =~ s/%SUBJECT%/$subject/g; $body =~ s/\r//g; @@ -366,8 +369,8 @@ sub _saveTopic { my $atts = ''; foreach my $att ( @$attachments ) { $attached = 1; - $err .= $this->_saveAttachment( $user, $web, $topic, $att ); - my $tmpl = TWiki::Func::expandTemplate( + $err .= $this->_saveAttachment( $web, $topic, $att ); + my $tmpl = Foswiki::Func::expandTemplate( 'MAILIN:'.$opts->{template}.':ATTACHMENT' ); if( $tmpl ) { $tmpl =~ s/%A_FILE%/$att->{filename}/g; @@ -379,15 +382,11 @@ sub _saveTopic { $insert =~ s/%ATTACHMENTS%/$atts/; $insert =~ s/%TEXT%/$body/g; - my $curUser = $TWiki::Plugins::SESSION->{user}; - $TWiki::Plugins::SESSION->{user} = $user; - $insert = TWiki::Func::expandVariablesOnTopicCreation($insert); - $TWiki::Plugins::SESSION->{user} = $curUser; + $insert = Foswiki::Func::expandVariablesOnTopicCreation($insert); # Reload the topic if we added attachments. if( $attached ) { - ( $meta, $text ) = $this->{session}->{store}->readTopic( - $user, $web, $topic ); + ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic ); } if( $opts->{where} eq 'top' ) { @@ -402,29 +401,32 @@ sub _saveTopic { print STDERR "Save topic $web.$topic:\n$text\n" if( $this->{debug} ); - $this->{session}->{store}->saveTopic( - $user, $web, $topic, $text, $meta, - { comment => "Submitted by e-mail" } ); + Foswiki::Func::saveTopic( + $web, $topic, $text, $meta, + { comment => "Submitted by e-mail", + forcenewrevision => 1} ); - } catch TWiki::AccessControlException with { + } catch Foswiki::AccessControlException with { my $e = shift; $err .= $e->stringify(); } catch Error::Simple with { my $e = shift; $err .= $e->stringify(); + } finally { + $Foswiki::Plugins::SESSION->{user} = $curUser; }; return $err; } sub _saveAttachment { - my( $this, $user, $web, $topic, $attachment ) = @_; + my( $this, $web, $topic, $attachment ) = @_; my $filename = $attachment->{filename}; my $payload = $attachment->{payload}; print STDERR "Save attachment $filename\n" if( $this->{debug} ); my $tmpfile = $web.'_'.$topic.'_'.$filename; - $tmpfile = $TWiki::cfg{PubDir}.'/'.$tmpfile; + $tmpfile = $Foswiki::cfg{PubDir}.'/'.$tmpfile; $tmpfile .= 'X' while -e $tmpfile; open( TF, ">$tmpfile" ) || return 'Could not write '.$tmpfile; @@ -433,12 +435,12 @@ sub _saveAttachment { my $err = ''; # SMELL: no central way to process attachment filenames, so we - # have to copy-paste the TWiki core code. + # have to copy-paste the Foswiki core code. $filename =~ s/ /_/go; - $filename =~ s/$TWiki::cfg{NameFilter}//goi; - $filename =~ s/$TWiki::cfg{UploadFilter}/$1\.txt/goi; - $this->{session}->{store}->saveAttachment( - $web, $topic, $filename, $user, + $filename =~ s/$Foswiki::cfg{NameFilter}//goi; + $filename =~ s/$Foswiki::cfg{UploadFilter}/$1\.txt/goi; + Foswiki::Func::saveAttachment( + $web, $topic, $filename, { comment => "Submitted by e-mail", file => $tmpfile }); unlink( $tmpfile ); return $err; @@ -454,13 +456,11 @@ sub _reply { my $message = "To: $addressee" . "\nFrom: ".$mail->header('To'). - "\nSubject: RE: your TWiki submission to ".$mail->header('Subject'). + "\nSubject: RE: your Foswiki submission to ".$mail->header('Subject'). "\n\n$body\n"; - eval { - $TWiki::Plugins::SESSION->{net}->sendEmail( $message, 5 ); - }; - if ($@) { - print "Failed trying to send mail: $@\n"; + my $errors = Foswiki::Func::sendEmail( $message, 5 ); + if ($errors) { + print "Failed trying to send mail: $errors\n"; } } diff --git a/lib/TWiki/Contrib/MailInContrib/Config.spec b/lib/Foswiki/Contrib/MailInContrib/Config.spec similarity index 98% rename from lib/TWiki/Contrib/MailInContrib/Config.spec rename to lib/Foswiki/Contrib/MailInContrib/Config.spec index 62ad132..e805a22 100644 --- a/lib/TWiki/Contrib/MailInContrib/Config.spec +++ b/lib/Foswiki/Contrib/MailInContrib/Config.spec @@ -1,4 +1,5 @@ -# ---+ MailInContrib +#---+ Mail and Proxies +#---++ Mail In # **PERL** # The configuration is in the form of an (perl) array of mailbox # specifications. Each specification defines a number of fields: diff --git a/lib/TWiki/Contrib/MailInContrib/DEPENDENCIES b/lib/Foswiki/Contrib/MailInContrib/DEPENDENCIES similarity index 79% rename from lib/TWiki/Contrib/MailInContrib/DEPENDENCIES rename to lib/Foswiki/Contrib/MailInContrib/DEPENDENCIES index 8880e95..8013705 100644 --- a/lib/TWiki/Contrib/MailInContrib/DEPENDENCIES +++ b/lib/Foswiki/Contrib/MailInContrib/DEPENDENCIES @@ -1,6 +1,4 @@ -TWiki::Plugins,>=1.1,,This module requires TWiki-4 Time::ParseDate,>=2003.0211,cpan,Required. Available from the CPAN:Time::ParseDate archive. -Error,>=0.15,cpan,Required. Available from the CPAN:Error archive. Email::Folder,>=0.84,cpan,Required. Available from the CPAN:Email::Folder archive. Email::FolderType::Net,>=1.02,cpan,Required. Available from the CPAN:Email::FolderType::Net archive. Email::MIME,>=1.82,cpan,Required. Available from the CPAN:Email::MIME archive. diff --git a/lib/Foswiki/Contrib/MailInContrib/MANIFEST b/lib/Foswiki/Contrib/MailInContrib/MANIFEST new file mode 100644 index 0000000..d11320f --- /dev/null +++ b/lib/Foswiki/Contrib/MailInContrib/MANIFEST @@ -0,0 +1,8 @@ +tools/mailincron 0555 command-line perl script +data/System/MailInContrib.txt 0444 this topic +data/System/MailInContribTemplate.txt 0444 file of templates +lib/Foswiki/Contrib/MailInContrib.pm 0444 perl module +lib/Foswiki/Contrib/MailInContrib/Config.spec 0444 configure spec +lib/CPAN/lib/Email/Delete/IMAP.pm 0444 Extension to incomplete CPAN module +lib/CPAN/lib/Email/Delete/POP3.pm 0444 Extension to incomplete CPAN module +pub/System/MailInContrib/wikiringlogo20x20.png 0660 diff --git a/lib/Foswiki/Contrib/MailInContrib/build.pl b/lib/Foswiki/Contrib/MailInContrib/build.pl new file mode 100755 index 0000000..a1c867d --- /dev/null +++ b/lib/Foswiki/Contrib/MailInContrib/build.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w +BEGIN { + foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) { + unshift @INC, $pc; + } +} + +use Foswiki::Contrib::Build; + +# Create the build object +$build = new Foswiki::Contrib::Build("MailInContrib"); + +# Build the target on the command line, or the default target +$build->build($build->{target}); + diff --git a/lib/TWiki/Contrib/MailInContrib/MANIFEST b/lib/TWiki/Contrib/MailInContrib/MANIFEST deleted file mode 100644 index 440243f..0000000 --- a/lib/TWiki/Contrib/MailInContrib/MANIFEST +++ /dev/null @@ -1,8 +0,0 @@ -tools/mailincron 0555 command-line perl script -data/TWiki/MailInContrib.txt 0444 this topic -data/TWiki/MailInContribTemplate.txt 0444 file of templates -lib/TWiki/Contrib/MailInContrib.pm 0444 perl module -lib/TWiki/Contrib/MailInContrib/Config.spec 0444 configure spec -lib/CPAN/lib/Email/Delete/IMAP.pm 0444 Extension to incomplete CPAN module -lib/CPAN/lib/Email/Delete/POP3.pm 0444 Extension to incomplete CPAN module -pub/TWiki/MailInContrib/wikiringlogo20x20.png 0660 diff --git a/lib/TWiki/Contrib/MailInContrib/build.pl b/lib/TWiki/Contrib/MailInContrib/build.pl deleted file mode 100755 index b205860..0000000 --- a/lib/TWiki/Contrib/MailInContrib/build.pl +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/perl -w -# -# Example build class. Copy this file to the equivalent place in your -# plugin or contrib and edit. -# -# Requires the environment variable FOSWIKI_LIBS (a colon-separated path -# list) to be set to point at the build system and any required dependencies. -# Usage: ./build.pl [-n] [-v] [target] -# where [target] is the optional build target (build, test, -# install, release, uninstall), test is the default. -# Two command-line options are supported: -# -n Don't actually do anything, just print commands -# -v Be verbose -# - -# Standard preamble -BEGIN { - foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) { - unshift @INC, $pc; - } -} - -use TWiki::Contrib::Build; - -# Declare our build package -{ package MailInBuild; - - @MailInBuild::ISA = ( "TWiki::Contrib::Build" ); - - sub new { - my $class = shift; - return bless( $class->SUPER::new( "MailInContrib" ), $class ); - } - - # Example: Override the build target - sub target_build { - my $this = shift; - - $this->SUPER::target_build(); - - # Do other build stuff here - } -} - -# Create the build object -$build = new MailInBuild(); - -# Build the target on the command line, or the default target -$build->build($build->{target}); - diff --git a/pub/TWiki/MailInContrib/logo.gif b/pub/System/MailInContrib/logo.gif similarity index 100% rename from pub/TWiki/MailInContrib/logo.gif rename to pub/System/MailInContrib/logo.gif diff --git a/pub/TWiki/MailInContrib/wikiringlogo20x20.png b/pub/System/MailInContrib/wikiringlogo20x20.png similarity index 100% rename from pub/TWiki/MailInContrib/wikiringlogo20x20.png rename to pub/System/MailInContrib/wikiringlogo20x20.png diff --git a/test/unit/MailInContrib/MailInContribSuite.pm b/test/unit/MailInContrib/MailInContribSuite.pm index 987d6d5..38b40cc 100644 --- a/test/unit/MailInContrib/MailInContribSuite.pm +++ b/test/unit/MailInContrib/MailInContribSuite.pm @@ -1,14 +1,13 @@ use strict; package MailInContribSuite; +use base 'FoswikiFnTestCase'; -use base qw( FoswikiFnTestCase! ); - -use TWiki; +use Foswiki; use Error qw( :try ); use File::Path; use Error qw( :try ); -use TWiki::Contrib::MailInContrib; +use Foswiki::Contrib::MailInContrib; my $box; @@ -22,17 +21,19 @@ sub set_up { $this->{system_web} = 'TemporaryMailInContribSuiteSystemWeb'; $this->{twiki}->{store}->createWeb( $this->{twiki}->{user}, $this->{system_web}, - $TWiki::cfg{SystemWebName} ); + $Foswiki::cfg{SystemWebName} ); + my $adm = Foswiki::Func::getCanonicalUserID( + $Foswiki::cfg{AdminUserWikiName}); $this->{twiki}->{store}->saveTopic( - $TWiki::cfg{AdminUserWikiName}, $this->{system_web}, + $adm, $this->{system_web}, 'WebPreferences', ""); - $TWiki::cfg{SystemWebName} = $this->{system_web}; + $Foswiki::cfg{SystemWebName} = $this->{system_web}; $this->{twiki}->finish(); - $this->{twiki} = new TWiki(); + $this->{twiki} = new Foswiki(); - my $workdir = TWiki::Func::getWorkArea('MailInContrib'); + my $workdir = Foswiki::Func::getWorkArea('MailInContrib'); open(F, ">$workdir/timestamp") || die $!; print F "0\n"; close(F); @@ -49,11 +50,10 @@ sub set_up { $this->{test_topic}, ""); $this->{twiki}->finish(); - $this->{twiki} = new TWiki(); + $this->{twiki} = new Foswiki(); $this->{twiki}->net->setMailHandler(\&sentMail); $box = {}; - # Make a maildir my $tmp = "/tmp/mail$$"; File::Path::mkpath("$tmp/tmp"); @@ -61,7 +61,7 @@ sub set_up { File::Path::mkpath("$tmp/new"); $box->{folder} = "$tmp/"; - $TWiki::cfg{MailInContrib} = [ $box ]; + $Foswiki::cfg{MailInContrib} = [ $box ]; @mails = (); } @@ -93,7 +93,7 @@ sub sentMail { sub cron { my $this = shift; - my $min = new TWiki::Contrib::MailInContrib( $this->{twiki}, 0 ); + my $min = new Foswiki::Contrib::MailInContrib( $this->{twiki}, 0 ); $min->processInbox( $box ); $min->wrapUp(); return $min; @@ -118,7 +118,7 @@ HERE From: notauser@example.com and there is no valid default username', $c->{error}); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic}); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); $this->assert($t !~ /\S/, $t); $this->assert_equals(0, scalar(@mails)); @@ -153,7 +153,7 @@ HERE my $c = $this->cron(); $this->assert_null($c->{error}); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic}); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); $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); $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); @@ -189,7 +189,7 @@ HERE my $c = $this->cron(); $this->assert_null($c->{error}); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},$this->{test_topic}); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},$this->{test_topic}); $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); $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); @@ -222,7 +222,7 @@ HERE my $c = $this->cron(); $this->assert_null($c->{error}); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'DangleBerries'); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'DangleBerries'); $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; $this->assert_matches(qr/^\s*$/, $t); @@ -366,15 +366,16 @@ HERE $box->{onSuccess} = 'reply'; my $c = $this->cron(); +print STDERR "VBLO\n"; $this->assert_equals(1, scalar(@mails)); $this->assert_matches(qr/Thank you for your successful/, $mails[0]); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'AnotherTopic'); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'AnotherTopic'); my @a = $m->get('FILEATTACHMENT'); $this->assert_equals(1, scalar(@a)); $this->assert_str_equals("data.asc", $a[0]->{attachment}); - $this->assert(-e "$TWiki::cfg{PubDir}/$this->{test_web}/AnotherTopic/data.asc"); + $this->assert(-e "$Foswiki::cfg{PubDir}/$this->{test_web}/AnotherTopic/data.asc"); } # templates @@ -394,7 +395,7 @@ HERE $box->{topicPath} = 'to'; $box->{onSuccess} = 'reply delete'; $this->{twiki}->{store}->saveTopic( - $this->{twiki}->{user}, $TWiki::cfg{SystemWebName}, + $this->{twiki}->{user}, $Foswiki::cfg{SystemWebName}, 'MailInContribUserTemplate', <<'HERE'); %TMPL:DEF{MAILIN:wierd}% Subject: %SUBJECT% @@ -413,7 +414,7 @@ HERE $this->assert_equals(1, scalar(@mails)); $this->assert_matches(qr/Thank you for your successful/, $mails[0]); - my( $m, $t ) = TWiki::Func::readTopic($this->{test_web},'TargetTopic'); + my( $m, $t ) = Foswiki::Func::readTopic($this->{test_web},'TargetTopic'); $this->assert_matches(qr/BEGIN\s*Subject: Object\s*Body: Message 1 text here\s*