Read mail file? (Linux)

C

Crom

How can I parse my mail spool file? Like in /var/spool/mail (and I think
the mailbox file in my home dir follows the same format.)

I've been trying to find this on google groups, but could not find
anything that really answers this.

Thanks for any help.

-----
(And by the way, what the hell did they do to google groups? It looks
nice and all but when reading a threaded view it's very hard to see
where one post ends and another begins, unless you click "show options".

am I the only one who thinks google groups was fine the way it was
before?????)
 
C

Christopher Nehren

How can I parse my mail spool file? Like in /var/spool/mail (and I think
the mailbox file in my home dir follows the same format.)

I personally like the Mail::Box suite. Whenever I've needed to do
something with email, it's come through for me (except for that one time
when I was fiddling with STDOUT, STDIN, and STDERR, but I'm sure that
its not working was my fault somewhere along the line...). I'm not one
for the simplicity of the Email:: namespace -- but then, I despise
simplicity in general. If you want simplicity, then I recommend
Email::Folder; a cursory glance yields it to do what you want.
However, if you want more complete functionality and a unified API, then
I wholeheartedly recommend Mail::Box.
am I the only one who thinks google groups was fine the way it was
before?????)

There's a still-growing thread about this in news.software.readers.
You're not alone. I personally don't care, since I use a Real
Newsreader.

Best Regards,
Christopher Nehren
 
S

Sherm Pendley

Crom said:
How can I parse my mail spool file? Like in /var/spool/mail (and I think
the mailbox file in my home dir follows the same format.)

Dunno if it's the same format as the mail spool or not, but there are a
couple of modules on CPAN for working with the standard mbox format:

Mail::Mbox::MessageParser
Mail::MboxParser
I've been trying to find this on google groups

Nothing wrong with searching Google groups, but it's not a substitute
for searching CPAN. You really should search both.

sherm--
 
D

David Efflandt

How can I parse my mail spool file? Like in /var/spool/mail (and I think
the mailbox file in my home dir follows the same format.)

In the main spool file any line that begins with "From " (From followed by
a space, which as a regex would be /^From / ) marks the start of the next
message. Not sure if From is always capitalized. This is not to be
confused with "From:" (w/colon) which is within headers, if present.

Search for 'mail parse' on www.perl.com for examples of perl handling of
mail including an overview http://www.perl.com/pub/a/2004/06/10/email.html
 
C

Crom

David said:
In the main spool file any line that begins with "From " (From
followed by a space, which as a regex would be /^From / ) marks the
start of the next message. Not sure if From is always capitalized.
This is not to be confused with "From:" (w/colon) which is within
headers, if present.

But what if From wit ha space occurs in the message body itself? How do
you know the difference?
 
T

Tassilo v. Parseval

Also sprach Crom:
But what if From wit ha space occurs in the message body itself? How do
you know the difference?

Under unlucky circumstances you can't. Note however that sane mail
processors don't just test for /^From /. These From-lines also have to
end with four digits so a more robust check is /^From .*\d{4}$/. And of
course there are heuristics that could be used (such as looking at the
preceeding line which has to be empty or the next line that has to be a
valid mail-header line).

Such a line could still show up in the body though which is one of those
unlucky circumstances. In order to avoid this problem many MUAs (or is it
MTAs that do that?) will turn a line starting with "From" in the body
into ">From" to disambiguate the matter.

In practice, nearly every mailbox turns out to be parseable just fine.
Over the years in which I've done quite a bit of mailbox parsing I never
came across a mailbox that couldn't be parsed with the common tools
around (such as those modules mentioned elsewhere in this thread).
They've been around long enough and grown very stable, also dealing with
edge-cases and such.

Tassilo
 
J

Joe Smith

David said:
In the main spool file any line that begins with "From " (From followed by
a space, which as a regex would be /^From / ) marks the start of the next
message. Not sure if From is always capitalized. This is not to be
confused with "From:" (w/colon) which is within headers, if present.

Other than the first line of the file, the delimiter is "\n\nFrom ".
The blank line before "^From " is required. It is always capitalized.
-Joe
 
A

Alfred Z. Newmane

Joe said:
Other than the first line of the file, the delimiter is "\n\nFrom ".
The blank line before "^From " is required. It is always capitalized.

But it can stil show up in the message body text can it not? If all it
is doing is checking for what you described above, it seems it could
easily be broken by putting that in the message body text:

---- MSG BODY BEGIN


^From


----- MSN BODY END

Do mail handlers (ie sendmail) it take any actualy to (temporarly)
handle such cases?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top