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=@_;
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
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
+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
--- /dev/null
+Return-path: <bremner@unb.ca>
+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
+ <bremner@unb.ca>) 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 <bremner@unb.ca>) 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 <bremner@unb.ca>
+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
+
+
+