Read mail file? (Linux)

Discussion in 'Perl Misc' started by Crom, Dec 14, 2004.

  1. Crom

    Crom Guest

    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?????)
    Crom, Dec 14, 2004
    #1
    1. Advertising

  2. On 2004-12-14, Crom scribbled these
    curious markings:
    > 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
    --
    I abhor a system designed for the "user", if that word is a coded
    pejorative meaning "stupid and unsophisticated". -- Ken Thompson
    If you ask the wrong questions, you get answers like "42" and "God".
    Unix is user friendly. However, it isn't idiot friendly.
    Christopher Nehren, Dec 14, 2004
    #2
    1. Advertising

  3. Crom wrote:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Dec 14, 2004
    #3
  4. On Tue, 14 Dec 2004 10:04:17 -0800, Crom <> wrote:
    > 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
    David Efflandt, Dec 14, 2004
    #4
  5. Crom

    Crom Guest

    David Efflandt wrote:
    > On Tue, 14 Dec 2004 10:04:17 -0800, Crom <> wrote:
    > > 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.


    But what if From wit ha space occurs in the message body itself? How do
    you know the difference?
    Crom, Dec 15, 2004
    #5
  6. Also sprach Crom:

    > David Efflandt wrote:
    >> On Tue, 14 Dec 2004 10:04:17 -0800, Crom <> wrote:
    >> > 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.

    >
    > 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
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval, Dec 15, 2004
    #6
  7. Crom

    Joe Smith Guest

    David Efflandt wrote:
    > On Tue, 14 Dec 2004 10:04:17 -0800, Crom <> wrote:
    >
    >>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.


    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
    Joe Smith, Dec 20, 2004
    #7
  8. Joe Smith wrote:
    > David Efflandt wrote:
    >> On Tue, 14 Dec 2004 10:04:17 -0800, Crom <> wrote:
    >>
    >>> 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.

    >
    > 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?
    Alfred Z. Newmane, Dec 20, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    675
    Randy Howard
    Feb 1, 2005
  2. Sreejith K
    Replies:
    24
    Views:
    992
    Sreejith K
    Mar 24, 2009
  3. Alex Dowad
    Replies:
    4
    Views:
    258
    Michel Demazure
    May 1, 2010
  4. Tom Mac
    Replies:
    1
    Views:
    171
    Walton Hoops
    May 3, 2011
  5. Chris
    Replies:
    0
    Views:
    96
    Chris
    Dec 26, 2005
Loading...

Share This Page