docster has asked for the wisdom of the Perl Monks concerning the following question:

Hello friends. I need to take a .forward email to a perl script and extract the "sender address" and "subject". After quite a bit of searching my head is starting to smoke... There seems to be a trillion ways to approach this. But none of the ones I have tried have actually worked. Something I thought was very simple has grown very complicated. ;)

I have the email forwarding to a Perl script. Now I just need to tell "who" sent it. And what the subject line was... Then I can work out the rest of what I need to do. Has anyone done this and can maybe supply me a simple example? Thank you!

Replies are listed 'Best First'.
Re: Simple .forward email parse
by rhesa (Vicar) on Sep 16, 2008 at 16:38 UTC
    Email::Filter rocks!
    my $mail = Email::Filter->new; say "sent by: ", $mail->from; say "about: ", $mail->subject;
      Thank you both. It appears that Email::Filter has replaced Email::Audit. So I tried it and the following works! Thank you.
      #!/usr/bin/perl use Email::Filter; my $mail = Email::Filter->new; my $myFrom = $mail->from; my $mySubject = $mail->subject; exec "echo \"From: $myFrom \nSubject: $mySubject\" > temp.log";

        Unless Email::Filter is making the results taint-safe, you are passing unvalidated data directly to a shell. Big time security no-no. It is better to open the file from within perl, and write escaped data to the file.

        Depending on your mailer, you could also have a race condition on temp.log. Might be better to lock that file prior to writing to it.

        --MidLifeXis

Re: Simple .forward email parse
by Fletch (Bishop) on Sep 16, 2008 at 16:32 UTC

    Should be trivial to whip up something to do this using Mail::Audit.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.