# HG changeset patch # User schulze # Date 1189178739 0 # Node ID 9482d33663065a88fda6a754a8fedb036125d2b3 # Parent 6f1e07f90b467325b7cc3041d9720ad13540a1fc - mimes werden aus mimes.conf gelesen diff -r 6f1e07f90b46 -r 9482d3366306 hs12 --- a/hs12 Fri Sep 07 13:53:41 2007 +0000 +++ b/hs12 Fri Sep 07 15:25:39 2007 +0000 @@ -12,20 +12,27 @@ use Fatal qw(:void select); use File::Temp qw(tempfile); use if $ENV{DEBUG} => "Smart::Comments"; +use FindBin qw($Bin); sub print_message(*@); sub read_message(); -sub pass_mime($); +sub pass_mime($$); sub forward_to_boundary($*); sub read_header(*); # -sub process(*;@); +sub process($*;@); +my $confdir = -f "$Bin/.build" ? $Bin : "/etc/$0"; +my @mimes; $SIG{__WARN__} = sub { print STDERR "### ", @_ }; MAIN: { + open ( my $fh, "< $confdir/mimes.conf") + or warn "can't read config!\n"; + my @mimes = map { chomp; $_ } grep !/(?:^\s*#|^\s*$)/, <$fh>; + # create an r/o tmp file containing the message for sequential # processing and optional failback in face of some processing error my $message = read_message(); @@ -38,7 +45,7 @@ # now we start processing but at the beginning - of course seek($message, 0, 0); - process($message, boundary => undef); + process(\@mimes, $message, boundary => undef); # everything is done, probably some rest is still unprocessed (some # epilogue, but this shouldn't be a problem at all @@ -64,8 +71,8 @@ } } -sub process(*;@) { - my ($m, %arg) = @_; +sub process($*;@) { + my ($mimes, $m, %arg) = @_; my ($header, %header) = read_header($m); my ($type, $boundary); @@ -80,7 +87,7 @@ $boundary ||= $arg{boundary}; - if (not $type or pass_mime($type)) { + if (not $type or pass_mime($type, $mimes)) { warn "passing: " . ($type ? $type : "no mime type") . "\n"; print $header; print_message($m, to => $boundary); @@ -93,7 +100,7 @@ print_message($m, to => $boundary); while (not eof($m)) { - process($m, boundary => $boundary); + process($mimes, $m, boundary => $boundary); } return; @@ -119,9 +126,11 @@ } -sub pass_mime($) { - local $_ = shift; - return m{(?:^text/)|(?:/signed)}; +sub pass_mime($$) { + my ($type, $mimes) = @_; + local $_ = $type; + my $re = join "|", map { $a = $_; $a =~ s/([^\da-z])/\\$1/gi; $a } @$mimes; + return m{$re}; } sub read_message() { @@ -157,3 +166,4 @@ ":unix_from:" => split(/^(\S+):\s*/m, $_)); } __END__ +# vim:ts=4 diff -r 6f1e07f90b46 -r 9482d3366306 mimes.conf --- a/mimes.conf Fri Sep 07 13:53:41 2007 +0000 +++ b/mimes.conf Fri Sep 07 15:25:39 2007 +0000 @@ -1,15 +1,19 @@ -# mimecutter mimes.conf +# mimes.conf # -# Insert mimes to archive here! -# All other mime types are NOT archived! +# Insert allowed mimes to archive here! +# All other mime types will NOT be archived! -text/plain -text/html -text/css -text/rtf -text/richtext +text/ +#text/plain +#text/html +#text/css +#text/rtf +#text/richtext + +#image/jpeg +#image/gif +# application/vnd.msword - #application/vnd.ms-excel #application/vnd.ms-powerpoint #application/vnd.pdf