]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/mailbox.pm
special case for comments pages
[git.ikiwiki.info.git] / IkiWiki / Plugin / mailbox.pm
index 14a4a78106ed7409b32cbf89178a03d0fb657a11..92ddf99f32f65f141f471b0590b61ba4d443d91c 100644 (file)
@@ -19,7 +19,8 @@ use Email::Thread;
 use CGI 'escapeHTML';
 use File::Temp qw/tempfile/;
 use File::MimeInfo::Magic;
-
+use Date::Parse;
+use Email::Address;
 
 my %metaheaders;
 
@@ -35,9 +36,11 @@ sub import { #{{{
 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 (@) { #{{{
@@ -60,6 +63,12 @@ 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 
@@ -74,7 +83,11 @@ sub format_mailbox(@){
 
     $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(@){
@@ -102,11 +115,36 @@ 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};
@@ -130,8 +168,10 @@ sub format_message(@){
     my $output="";
 
     my @names = grep  {m/$keep_headers/;}  ($message->header_names);
+    
     my @headers=map { make_pair($message,$_) } @names;
     
+    
 
     $template->param(HEADERS=>[@headers]);
 
@@ -215,6 +255,11 @@ sub pagetemplate (@) { #{{{
         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;