--- 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