From: David Bremner Date: Sat, 13 Sep 2008 14:24:30 +0000 (-0300) Subject: Initial, hardcoded address sanitizing X-Git-Tag: 0.5~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b69c55038a343c026b97ab97356b5e73b47df9ca;p=ikiwiki.git Initial, hardcoded address sanitizing --- diff --git a/IkiWiki/Plugin/mailbox.pm b/IkiWiki/Plugin/mailbox.pm index df77579f7..75a64d61b 100644 --- a/IkiWiki/Plugin/mailbox.pm +++ b/IkiWiki/Plugin/mailbox.pm @@ -20,6 +20,7 @@ use CGI 'escapeHTML'; use File::Temp qw/tempfile/; use File::MimeInfo::Magic; use Date::Parse; +use Email::Address; my %metaheaders; @@ -114,11 +115,27 @@ sub format_thread(@){ return $output; } +sub sanitize_address($$){ + my $hdrname=shift; + my $val=shift; + + if ($hdrname =~ qr/From|To|Reply-To|CC/){ + my @addrs=Email::Address->parse($val); + foreach my $addr (@addrs){ + $addr->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}; @@ -142,8 +159,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]);