Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How to filter a *NIX Mailbox

by McD (Chaplain)
on Dec 01, 2008 at 13:52 UTC ( [id://727091]=note: print w/replies, xml ) Need Help??


in reply to How to filter a *NIX Mailbox

The modules I found with the previous CPAN search give me the impression of doing "kinda too much" and I'm slightly loss.

I think you might be on to something there. The standard unix mailbox file format is pretty simple, you might not want to load up with a heavy mail processing module at all.

A single mail message consists of headers, a blank line, and the body. Mailbox files separate these with lines that begin "From " - case sensitive. So you can write up code that looks for:

/^From / and ... # New message, next line begins the headers /^$/ and ... # Blank line, next line begins the body
Interesting bit of trivia - most mail transfer agents will prefix any line in a mail message that they process that beings "From " with a ">", like a citation, so that this:

From Tuesday on, I'll be on vacation.
becomes this:

>From Tuesday on, I'll be on vacation.
...just to keep that mail message from screwing up the mailbox format when it gets delivered somewhere.

Anyway, if you're not too concerned about parsing MIME structures but just want something closer to a straight grep, taking apart the mailbox file by hand isn't very heavy lifting at all.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found