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

I use Netscape on unix (Solaris) to handle my mail and am sometimes confronted with e-mail which is missing various parts of its anatomy. Headers with no body, body with no header. This is due to the way Netscape parses the e-mail, starting a new message each time a line begins with "From ". I'd like to call a Perl script in my .forward file to change "From " in the body to "Coming From " or something like that. I'm using some home brewed Perl to do this, but I run it manually just before I click the "get msg" button in Netscape. Any suggestions? Regards... -jeph

Replies are listed 'Best First'.
Re: simple mail filter
by Fastolfe (Vicar) on Jan 13, 2001 at 05:19 UTC
    If you're having problems because of a bare 'From ' at the beginning of a line in your mail file, this is due to a bug in the program that's writing this to your mail file. I would look at solving the problem at the source instead of periodically running a fix like this to patch up the file. (Update: As coyote mentions, apparently it is standard behavior for stock Solaris sendmail to not quote bare Froms in messages, so if you're on this platform you'll need to modify this sendmail behavior or adapt your mailbox parser to take the 'Content-Length' header of your messages, assuming they're there, into account.)

    Unfortunately, writing a Perl script to parse a Unix mailbox file to fix a problem like this is non-trivial. I mean you can probably get a regexp that'll match 98% of the messages, but generally parsing a Unix mailbox file relies on the fact that a bare 'From ' at the beginning of a line separates one message from the next.

    If you can't identify/fix whatever software is causing this problem and still want to proceed along this line, something like this might work:

    perl -pi.bak -e 's/^(?=From )(?![^\@]+\@)/>/' mailbox.file
    This changes leading 'From's that do not have an @ anywhere on the line to >From, which is usually how this is handled by mail delivery agents.
Re: simple mail filter
by Coyote (Deacon) on Jan 13, 2001 at 11:24 UTC
Re: simple mail filter
by strredwolf (Chaplain) on Jan 13, 2001 at 10:27 UTC
    Similar to above. Netscape's probably tripping over a bare "\nFrom " somewhere in the message. If you want to change it, run your mailbox through procmail and formail. They're experts at handling it. Perl can't do much w/o rewriting procmail/formail, and yes, I've done it.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";

Re: simple mail filter
by chipmunk (Parson) on Jan 14, 2001 at 10:00 UTC
    It's not Perl, but you might consider using formail for this. A snippet from the formail manpage:
    NAME formail - mail (re)formatter [...] DESCRIPTION formail is a filter that can be used to force mail into mailbox format, perform `From ' escaping, generate auto- replying headers, do simple header munging/extracting or split up a mailbox/digest/articles file.
Re: simple mail filter
by deprecated (Priest) on Jan 13, 2001 at 15:49 UTC
    There was an excellent article in TPJ on Mail::Audit a little while back. I think that would give you a solution to your problem and more. :)

    cheers,
    deprecated

    --
    i am not cool enough to have a signature.