# This file is distributed under the Artistic License/GPL2+
use Email::MIME;
+use Email::MIME::Modifier;
package Email::MIMEFolder;
use base 'Email::Folder';
sub bless_message { return Email::MIME->new($_[1]) };
use CGI 'escapeHTML';
use File::Temp qw/tempfile/;
use File::MimeInfo::Magic;
-
+use Date::Parse;
+use Email::Address;
my %metaheaders;
hook(type => "preprocess", id => "mailbox", call => \&preprocess);
hook(type => "scan", id => "mailbox", call => \&scan);
hook(type => "pagetemplate", id=>"mailbox", call => \&pagetemplate);
+ hook(type => "htmlize",id=>"mbox",call => \&mbox_htmlize);
+ IkiWiki::loadplugin("filecheck");
} # }}}
sub scan(@){
my %params=@_;
my $page=$params{page};
+
+ my $linktext=$config{url}.'/mailbox.css';
push @{$metaheaders{$page}},
- '<link rel="stylesheet" href="mailbox.css" type="text/css"/>'
+ '<link rel="stylesheet" href="'.$linktext.'" type="text/css"/>'
}
sub preprocess (@) { #{{{
} # }}}
+sub mbox_htmlize(@){
+ my %params=@_;
+
+ my $path=$config{srcdir} . '/' . $params{page}.".mbox";
+ return format_mailbox(path=>$path,type=>'Mbox',destpage=>$params{page});
+}
### The guts of the plugin
### parameters
$threader->thread();
- return join "\n", map { format_thread(%params,thread=>$_) } $threader->rootset;
+ my @roots= sort { str2time($a->header('Date')) <=>
+ str2time($b->header('Date'))} ($threader->rootset);
+
+ return join "\n", map { format_thread(%params,thread=>$_) } @roots;
+
}
sub format_thread(@){
return $output;
}
+sub sanitize_address($$){
+ my $hdrname=shift;
+ my $val=shift;
+ my $strategy= $config{mailbox_obfuscation_strategy} || "delete";
+
+ return $val if ($strategy eq "none");
+
+ if ($hdrname =~ qr/From|To|Reply-To|CC/){
+ my @addrs=Email::Address->parse($val);
+ foreach my $addr (@addrs){
+ if ($strategy eq "rot13"){
+ my $orig=$addr->address;
+ $orig =~ y/A-Za-z/N-ZA-Mn-za-m/;
+ $addr->address($orig);
+ } else {
+ $addr->address(gettext("address deleted"));
+ }
+ }
+ $val=join(",",map {$_->format;} @addrs);
+ }
+ return $val;
+ }
+
sub make_pair($$){
my $message=shift;
my $name=shift;
- my $val=$message->header($_);
-
+ my $val=$message->header($name);
+
+ $val = sanitize_address($name,$val);
+
$val = escapeHTML($val);
my $hash={'HEADERNAME'=>$name,'VAL'=>$val};
my $output="";
my @names = grep {m/$keep_headers/;} ($message->header_names);
+
my @headers=map { make_pair($message,$_) } @names;
+
$template->param(HEADERS=>[@headers]);
#this sucks. But someone would need to modify filecheck to
#accept a blob of content. Or maybe hacking with IO::Scalar
my $tmpfile=File::Temp->new();
- print $tmpfile $_;
- debug("checking ".$allowed_attachments);
+ binmode $tmpfile,':utf8';
+ print $tmpfile $_->body();
my $allowed=pagespec_match($dest, $allowed_attachments, file=>$tmpfile);
- debug("pagespec_return = ". $allowed);
- debug("mimetype = ".File::MimeInfo::Magic::magic($tmpfile));
- if (+!$allowed) {
- debug("clobbering attachment");
- $_->body_set("skipping part $partcount: $allowed");
+ if (!$allowed) {
+ debug("clobbering attachment $partcount");
+ $_->content_type_set('text/plain');
+ $_->body_set("[ omitting part $partcount: $allowed ]");
+
}
$partcount++;
}
my $destpage=$params{destpage};
my $template=$params{template};
+
+ if ($page =~ /.*comments/ && defined($config{mailbox_copyright})){
+ $template->param(COPYRIGHT=>$config{mailbox_copyright});
+ }
+
if (exists $metaheaders{$page} && $template->query(name => "meta")) {
# avoid duplicate meta lines
my %seen;