From 4f2ab4db71e2afc3bf9a71bcdffdf56d820489bc Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sun, 31 Aug 2008 16:41:15 -0300 Subject: [PATCH] work on postal-accept filter to add message to wiki --- filters/postal-accept.pl | 70 ++++++++++++++++++---------------------- test/in/test.mdwn | 1 + test/test.setup | 2 +- 3 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 test/in/test.mdwn diff --git a/filters/postal-accept.pl b/filters/postal-accept.pl index ebd2627d5..135635ccf 100644 --- a/filters/postal-accept.pl +++ b/filters/postal-accept.pl @@ -1,71 +1,63 @@ #!/usr/bin/perl -use Email::Folder; +# Take message on stdin, write to appropiate comment folder, +# update wiki + use Email::LocalDelivery; +use Email::Filter; use Convert::YText qw(decode_ytext encode_ytext); # we need at least version 2.54 of IkiWiki for the new config api BEGIN { require IkiWiki; die unless ($IkiWiki::version >= 2.54) } +use IkiWiki; use IkiWiki::Setup; use Getopt::Long; use Carp; +my $folder_ext=".mbox"; + my $config_file=undef; GetOptions('config=s'=>\$config_file); die "configuration file is mandatory" unless ($config_file); -my %config=IkiWiki::Setup::load($config_file); - -my $queue=$config{queue} || croak("missing queue location"); +%config=IkiWiki::defaultconfig(); -my $folder=Email::Folder->new($path,reader=>'Email::Folder::maildir') - || croak("mailbox could not be opened"); +IkiWiki::Setup::load($config_file); -for my $messages ($folder->messages){ +$message=Email::Filter->new(); - my $to=$message->to; - if ($to =~ m/$prefix($Convert::YText::valid_rex)/){ - my $page=decode_ytext($1); - - # sanity check the page path - - # check if comments folder exists, create if needed - - # write the message to the folder +my $to=$message->to; +if ($to =~ m/$prefix($Convert::YText::valid_rex)/){ + my $page=decode_ytext($1); + + die("page ".$page." does not exist") if !($pagesources{$page}); + + my $comments_folder=$page."/comments".$folder_ext; - $msg_file= $comment_folder->write($message); + # write the message to the comment - # update vcs, copied from Ikiwiki::Plugins::attachment + my ($delivered) = Email::LocalDeliver($config{srcdir}."/".$comments_folder); - if ($config{rcs}) { - IkiWiki::rcs_add($filename); - IkiWiki::disable_commit_hook(); - IkiWiki::rcs_commit($filename, gettext("attachment upload"), - IkiWiki::rcs_prepedit($filename), - $session->param("name"), $ENV{REMOTE_ADDR}); - IkiWiki::enable_commit_hook(); - IkiWiki::rcs_update(); - } - - # tag for deletion - - push (@must_die, $message->message-id); - - $folder->delete($message); - + die ("delivery failed") if (!defined ($delivered)); + + # update vcs, copied from Ikiwiki::Plugins::attachment + + if ($config{rcs}) { + IkiWiki::rcs_add($delivered); + IkiWiki::disable_commit_hook(); + IkiWiki::rcs_commit($delivered, gettext("postal delivery"), + IkiWiki::rcs_prepedit($delivered)); + IkiWiki::enable_commit_hook(); + IkiWiki::rcs_update(); } # refresh wiki IkiWiki::refresh(); IkiWiki::saveindex(); - - # make regex for message-id - - # called delete_message from Email::Delete -} +} diff --git a/test/in/test.mdwn b/test/in/test.mdwn new file mode 100644 index 000000000..d5157040d --- /dev/null +++ b/test/in/test.mdwn @@ -0,0 +1 @@ +this is page called test diff --git a/test/test.setup b/test/test.setup index 56a4a8b12..96aec15d7 100644 --- a/test/test.setup +++ b/test/test.setup @@ -139,7 +139,7 @@ use IkiWiki::Setup::Standard { #multimarkdown => 1, # To add plugins, list them here. - add_plugins=>[qw{mailbox}], + add_plugins=>[qw{mailbox postal}], #add_plugins => [qw{goodstuff search wikitext camelcase # htmltidy fortune sidebar map rst anonok}], # If you want to disable any of the default plugins, list them here. -- 2.26.2