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.

In reply to Re: simple mail filter by Fastolfe
in thread simple mail filter by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.