Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Decode a mail with MIME::Parser

by RuneK (Sexton)
on Sep 03, 2002 at 08:02 UTC ( #194699=note: print w/replies, xml ) Need Help??

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/> /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 is just installed.
Any ideas?
Thanks, Rune

Replies are listed 'Best First'.
Using MIME::Lite to resend plain text messages (no attachments)
by jlongino (Parson) on Sep 03, 2002 at 14:45 UTC
    I'd move
    close MSG;

    outside of the for loop just for aesthetic purposes and check for errors on your open statement:

    open (MSG, ">>mailmessage") or die "File open failed: $!\n";
    but otherwise it performs as I would expect. Try saving a copy of your mail message to a file and invoke the program like so:
    /tmp/ < mail.message.file

    This suggests that you'll probably have to modify your procmail config line in some way, but I'm not familiar with procmail.

    Update: I've had a similar problem using the /etc/aliases file to strip/redirect mail to a special account. I solved my problem by parsing the message and then resending it to a different account. This is sort of ugly, but it works until I can figure out the correct method:

    #/etc/aliases entry ## The below entry saves an unaltered copy on account original, and ## pipes the incoming message through our program which ## resends to the final destination account. Be sure to execute ## 'newaliases' after you modify the /etc/aliases for the changed ## entry to be updated. original: \original, "|/tmp/"
    The modified perl program:
    ## # MboxParser stuff here ## use MIME::Lite; my $msg = new MIME::Lite To => '', From => $from, Cc => $cc, Subject => $subject, Type => 'TEXT', Comments => $to, ## save original to: if needed Data => $body_str; MIME::Lite->send('smtp', "", Timeout=>60); $msg->send;


Re: Re: Decode a mail with MIME::Parser
by Anonymous Monk on Jan 04, 2004 at 08:46 UTC
    I faced the same problem with pipeline from .procmailrc \*STDIN; seem to be not work..

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://194699]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-05-18 03:34 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (68 votes). Check out past polls.