From: David Bremner Date: Sat, 30 Aug 2008 13:31:19 +0000 (-0300) Subject: updated attachment filtering X-Git-Tag: 0.4~16 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/4d391f267efda04d2a2c12e4d1412a015f6ac518 updated attachment filtering --- diff --git a/IkiWiki/Plugin/mailbox.pm b/IkiWiki/Plugin/mailbox.pm index bd7882f7c..c8b244d00 100644 --- a/IkiWiki/Plugin/mailbox.pm +++ b/IkiWiki/Plugin/mailbox.pm @@ -5,6 +5,7 @@ # 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]) }; @@ -141,18 +142,22 @@ sub format_message(@){ foreach(@parts){ #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); + my $tmpfile=File::Temp->new(UNLINK=>0); + binmode $tmpfile,':utf8'; + print $tmpfile $_->body(); + my $msgid=$_->header('Message-ID'); + debug("checking $msgid part $partcount ".$allowed_attachments); my $allowed=pagespec_match($dest, $allowed_attachments, file=>$tmpfile); - debug("pagespec_return = ". $allowed); - debug("mimetype = ".File::MimeInfo::Magic::magic($tmpfile)); + debug("pagespec_return= ". $allowed); + debug("magic= ".File::MimeInfo::Magic::magic($tmpfile)); + debug("default= ".File::MimeInfo::Magic::default($tmpfile)); - if (+!$allowed) { + if (!$allowed) { debug("clobbering attachment"); - $_->body_set("skipping part $partcount: $allowed"); + $_->content_type_set('text/plain'); + $_->body_set("[ omitting part $partcount: $allowed ]"); + } $partcount++; }