hs12
changeset 10 af315e1a9b1e
parent 9 26659f592363
child 11 1fccf68e52c6
--- a/hs12	Wed Sep 05 08:53:01 2007 +0000
+++ b/hs12	Wed Sep 05 14:52:16 2007 +0000
@@ -6,12 +6,12 @@
 use File::Temp qw(tempfile);
 use Smart::Comments;
 
+sub print_message(*$);
 sub read_message();
-sub parse(*);
 sub pass_mime($);
 sub forward_to_boundary($*);
 sub read_header(*);
-sub process(*);
+sub process(*$);
 
 MAIN: {
     my $message = read_message();
@@ -19,7 +19,7 @@
     my $stdout  = select $tmpout;
 
     seek($message, 0, 0);
-    process($message);
+    process($message, undef);
 
     # spit out everthing
     select $stdout;
@@ -33,36 +33,41 @@
     }
 }
 
-sub process(*) {
-    my $m = shift;
-    my ($header, %header) = read_header($m);
+sub print_message(*$) {
+    my ($m, $b) = @_;
+
+    if (not defined $b) {
+        return print while <$m>;
+    }
+
+    while (<$m>) {
+        print;
+        last if /^--$b--\s*/;
+    }
+}
 
-    if (   !$header{"mime-version"}
-        or !$header{"content-type"})
+sub process(*$) {
+    my ($m,      $boundary) = shift;
+    my ($header, %header)   = read_header($m);
+    my $mime;
+
+    if (    $header{"mime-version"}
+        and $header{"content-type"})
     {
+        ($mime, undef, $boundary) = (
+            $header{"content-type"} =~ /^(.*?); # mime type
+	      (?:.*(?:boundary=(['"])(.*?)\2))? # eventuell noch mehr
+	    /x
+        );
+    }
+
+    if (!$mime or pass_mime($mime)) {
         print $header;
+        print_message($m, $boundary);
         return;
     }
 
-    if (my $boundary = pass_mime($header{"content-type"})) {
-        warn "passing ", ($header{"content-type"} =~ /^(.*?);/)[0], "\n";
-        print $header;
-        while (<$m>) { print; last if /^--\Q$boundary\E--\s*/ }
-    }
 
-
-    #my $boundary;
-    #$boundary = $2
-    #    if ($header{"content-type"} =~ m{boundary=(['"])(.*?)\1});
-
-}
-
-sub forward_to_boundary($*) {
-    my ($b, $fh) = @_;
-    while (<$fh>) {
-        print;
-        return if /^--$b/;
-    }
 }
 
 sub pass_mime($) {
@@ -97,8 +102,3 @@
     return ("$from$h", ":unix_from:" => split(/^(\S+):\s*/m, "$from$_"));
 }
 __END__
-
-my $parser = new MIME::Parser;
-
-# read the complete mail
-my $entity = $parser->parse(\*STDIN);