#!/usr/local/bin/perl -w use strict; use MIME::Parser; use Sys::Syslog qw(:DEFAULT setlogsock); setlogsock 'unix'; sub logmsg($$); my $syslog_opened = 0; my $syslog_facility = 'mail'; my $tag = $0; $tag =~ s,^.*/,,; $tag =~ s/\.pl//; my $p = new MIME::Parser; $p->output_to_core(1); # do not write to fs $p->extract_nested_messages(0); # do not parse nested message/rfc822 $p->extract_uuencode(1); # parse uuencoded too (just in case) $p->decode_bodies(0); # avoid to change entity bodies $p->tmp_dir("/var/tmp"); # place temp files here if needed # read from STDIN my $pos = tell STDIN; my $from = ; exit unless $from; logmsg('notice', "from: $from"); seek STDIN, $pos, 0; my $e = $p->parse(\*STDIN) or exit; my $j = 1; foreach ($e->parts()) { if ($_->mime_type eq 'message/rfc822') { logmsg('notice', "printing part $j"); $j++; print "From - Thu Jan 1 07:00:05 1970\n"; $_->print_body(\*STDOUT); # print out forwarded messages print "\n"; } } # that's all, folks! sub logmsg($$) { my $i = 1; while ($i <= 3) { unless($syslog_opened) { openlog($tag, 'cons,pid', $syslog_facility) and $syslog_opened = 1; } return if syslog($_[0], $_[1]); closelog(); $syslog_opened = 0; $i++; sleep(1); } }