From: David Bremner Date: Thu, 31 Jul 2008 02:24:54 +0000 (-0300) Subject: Scan a maildir and output each message via a template. Currently output is escaped... X-Git-Tag: 0.4~30 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/f1c66708e33b6db8f2dbe33bb4799b8fa3a7f829 Scan a maildir and output each message via a template. Currently output is escaped HTML --- diff --git a/IkiWiki/Plugin/mailbox.pm b/IkiWiki/Plugin/mailbox.pm index 838a6378e..5f1c7d48e 100644 --- a/IkiWiki/Plugin/mailbox.pm +++ b/IkiWiki/Plugin/mailbox.pm @@ -12,42 +12,9 @@ use IkiWiki 2.00; use Email::Folder; sub import { #{{{ - hook(type => "getopt", id => "mailbox", call => \&getopt); - hook(type => "checkconfig", id => "mailbox", call => \&checkconfig); - hook(type => "needsbuild", id => "mailbox", call => \&needsbuild); hook(type => "preprocess", id => "mailbox", call => \&preprocess); - hook(type => "filter", id => "mailbox", call => \&filter); - hook(type => "linkify", id => "mailbox", call => \&linkify); - hook(type => "scan", id => "mailbox", call => \&scan); - hook(type => "htmlize", id => "mailbox", call => \&htmlize); - hook(type => "sanitize", id => "mailbox", call => \&sanitize); - hook(type => "postscan", id => "mailbox", call => \&postscan); - hook(type => "format", id => "mailbox", call => \&format); - hook(type => "pagetemplate", id => "mailbox", call => \&pagetemplate); - hook(type => "templatefile", id => "mailbox", call => \&templatefile); - hook(type => "delete", id => "mailbox", call => \&delete); - hook(type => "change", id => "mailbox", call => \&change); - hook(type => "cgi", id => "mailbox", call => \&cgi); - hook(type => "auth", id => "mailbox", call => \&auth); - hook(type => "sessioncgi", id => "mailbox", call => \&sessioncgi); - hook(type => "canedit", id => "mailbox", call => \&canedit); - hook(type => "editcontent", id => "mailbox", call => \&editcontent); - hook(type => "formbuilder_setup", id => "mailbox", call => \&formbuilder_setup); - hook(type => "formbuilder", id => "mailbox", call => \&formbuilder); - hook(type => "savestate", id => "mailbox", call => \&savestate); } # }}} -sub getopt () { #{{{ - debug("mailbox plugin getopt"); -} #}}} - -sub checkconfig () { #{{{ - debug("mailbox plugin checkconfig"); -} #}}} - -sub needsbuild () { #{{{ - debug("mailbox plugin needsbuild"); -} #}}} sub preprocess (@) { #{{{ my %params=@_; @@ -55,151 +22,18 @@ sub preprocess (@) { #{{{ my $page=$params{page}; my $type=$params{type} || 'maildir'; - print STDERR join("\n",%params); - - error("path is mandatory") if (!defined($params{path})); + my $path=$params{path} || error gettext("missing parameter") . " path"; - # note, mbox is not a directory + # note, mbox is not a directory, needs to be special cased my $dir=bestdir($page,$params{path}) || error("could not find ".$params{path}); - $dir = $config{srcdir} ."/" . $dir; - - return format_mailbox(path=>$dir); - -} # }}} - -sub filter (@) { #{{{ - my %params=@_; - - -# debug("mailbox plugin: path=".$params{path}); - - return $params{content}; -} # }}} - -sub linkify (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running as linkify"); - - return $params{content}; -} # }}} - -sub scan (@) { #{{{a - my %params=@_; - - debug("mailbox plugin running as scan"); -} # }}} - -sub htmlize (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running as htmlize"); - - return $params{content}; -} # }}} - -sub sanitize (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running as a sanitizer"); - - return $params{content}; -} # }}} - -sub postscan (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running as postscan"); -} # }}} - -sub format (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running as a formatter"); - - return $params{content}; -} # }}} - -sub pagetemplate (@) { #{{{ - my %params=@_; - my $page=$params{page}; - my $template=$params{template}; - - debug("mailbox plugin running as a pagetemplate hook"); -} # }}} - -sub templatefile (@) { #{{{ - my %params=@_; - my $page=$params{page}; - - debug("mailbox plugin running as a templatefile hook"); -} # }}} - -sub delete (@) { #{{{ - my @files=@_; - - debug("mailbox plugin told that files were deleted: @files"); -} #}}} - -sub change (@) { #{{{ - my @files=@_; - - debug("mailbox plugin told that changed files were rendered: @files"); -} #}}} - -sub cgi ($) { #{{{ - my $cgi=shift; - - debug("mailbox plugin running in cgi"); -} #}}} - -sub auth ($$) { #{{{ - my $cgi=shift; - my $session=shift; - - debug("mailbox plugin running in auth"); -} #}}} - -sub sessionncgi ($$) { #{{{ - my $cgi=shift; - my $session=shift; - - debug("mailbox plugin running in sessioncgi"); -} #}}} - -sub canedit ($$$) { #{{{ - my $page=shift; - my $cgi=shift; - my $session=shift; + $params{path} = $config{srcdir} ."/" . $dir; - debug("mailbox plugin running in canedit"); -} #}}} + return format_mailbox(path=>$dir,%params); -sub editcontent ($$$) { #{{{ - my %params=@_; - - debug("mailbox plugin running in editcontent"); - - return $params{content}; -} #}}} - -sub formbuilder_setup (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running in formbuilder_setup"); } # }}} -sub formbuilder (@) { #{{{ - my %params=@_; - - debug("mailbox plugin running in formbuilder"); -} # }}} - -sub savestate () { #{{{ - debug("mailbox plugin running in savestate"); -} #}}} ### The guts of the plugin ### parameters @@ -209,10 +43,32 @@ sub format_mailbox(@){ my $header_list=$params{headers} || "subject,from"; my $folder=Email::Folder->new($path) || error("mailbox could not be opened"); - return join "\n", map { format(message=>$_) } $folder->messages; + return join "\n", map { format_message(message=>$_) } $folder->messages; } +sub format_message(@){ + my %params=@_; + + my $message=$params{message} || + error gettext("missing parameter"). "message"; + + my $template= + template("email.tmpl") || error gettext("missing template"); + + + my @headers=map { {'HEADERNAME'=>$_,'VAL'=>$message->header($_)} } + $message->header_names; + + $template->param(HEADERS=>[@headers]); + + $template->param(body=>$message->body); + + my $output=$template->output(); + print STDERR $output; + return $output; +} + ### Utilities # From Arpit Jain @@ -249,4 +105,23 @@ sub bestdir ($$) { #{{{ +sub fill_template(@){ + my %params=@_; + my $template = $params{template} || error gettext("missing parameter"); + + $params{basename}=IkiWiki::basename($params{page}); + + foreach my $param (keys %params) { + if ($template->query(name => $param)) { + $template->param($param => + IkiWiki::htmlize($params{page}, $params{destpage}, + pagetype($pagesources{$params{page}}), + $params{$param})); + } + if ($template->query(name => "raw_$param")) { + $template->param("raw_$param" => $params{$param}); + } + } +} + 1 diff --git a/test/in/testbox/cur/1216509900.24030_0.rocinante:2,S b/test/in/testbox/cur/1216509900.24030_0.rocinante:2,S new file mode 100644 index 000000000..86f673fcb --- /dev/null +++ b/test/in/testbox/cur/1216509900.24030_0.rocinante:2,S @@ -0,0 +1,31 @@ +Return-path: +Envelope-to: + bremner-comment-blog~posts~filling_in_forms_with_pdftk@pivot.cs.unb.ca +Delivery-date: Tue, 01 Jul 2008 09:22:23 -0300 +Received: from [141.44.229.26] (helo=rocinante.cs.unb.ca) by pivot.cs.unb.ca + with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from + ) id 1KDesI-0006HF-VQ for + bremner-comment-blog~posts~filling_in_forms_with_pdftk@pivot.cs.unb.ca; Tue, + 01 Jul 2008 09:22:23 -0300 +Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.69) + (envelope-from ) id 1KDerP-0008FX-CM for + bremner-comment-blog~posts~filling_in_forms_with_pdftk@pivot.cs.unb.ca; Tue, + 01 Jul 2008 14:21:27 +0200 +From: David Bremner +Organization: University of New Brunswick, Alpha Centurai Campus +To: bremner-comment-blog~posts~filling_in_forms_with_pdftk@pivot.cs.unb.ca +Subject: this is a test of special casing for / +Date: Tue, 1 Jul 2008 14:21:27 +0200 +User-Agent: KMail/1.9.9 +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200807011421.27352.bremner@unb.ca> +X-Host-Lookup-Failed: Reverse DNS lookup failed for 141.44.229.26 (failed) +X-Sender-Verified: bremner@unb.ca +X-IkiPostal-Key: blog/posts/filling in forms with pdftk +Lines: 0 + + + diff --git a/test/test.setup b/test/test.setup index 5ec06b45d..82b725e30 100644 --- a/test/test.setup +++ b/test/test.setup @@ -16,7 +16,7 @@ use IkiWiki::Setup::Standard { url => "file:///tmp/test-wiki/", #cgiurl => "http://example.org/wiki/ikiwiki.cgi", - #templatedir => "/usr/share/ikiwiki/templates", + templatedir => $ENV{PWD}."/../templates", #underlaydir => "/usr/share/ikiwiki/basewiki", # Subversion stuff.