http://qs1969.pair.com?node_id=194699


in reply to Decode a mail with MIME::Parser

Hi again, Thanks for the answer but I cannot seem to get your part with the mbox to work.
I'm using the .procmailrc with the following statement:

:0 | /tmp/mailparser.pl> /tmp/test.log

So I'm parsing the mail directly to the script which should read it through STDIN.
I changed the print (to,from,subject,body) to print to a file instead because that is what I need, but the file is empty. The script now looks like this:
#!/usr/bin/perl -w use strict; use warnings; use Mail::MboxParser; my $mbox= \*STDIN; my $mb = Mail::MboxParser->new($mbox); open (MSG,">mailmessage"); for my $msg ($mb->get_messages) { my $to = $msg->header->{to}; my $from = $msg->header->{from}; my $cc = $msg->header->{cc} || " ", my $subject = $msg->header->{subject} || '<No Subject:>', my $body = $msg->body($msg->find_body,0); my $body_str = $body->as_string || '<No message text>'; print MSG "To: $to\n", "From: $from\n", "Cc: $cc\n", "Subject: $subject\n", "Message Text: $body_str\n"; print MSG "~" x 77, "\n\n"; close MSG; }

The file is created so it's not a permission problem but it is empty. The MboxParser.pm is just installed.
Any ideas?
Thanks, Rune