http://qs1969.pair.com?node_id=562677

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

hello again,

I'm trying to find an efficient way to count and/or split email messages from /var/spool/mail/<user>. Apart from opening the spool and iterating through it, could anybody suggest a module they know of that can do this well. I've had a quick look on cpan but got a bit lost.

thanks, Isaac.
  • Comment on splitting email messages from /var/spoolio...

Replies are listed 'Best First'.
Re: splitting email messages from /var/spoolio...
by gellyfish (Monsignor) on Jul 20, 2006 at 19:20 UTC

    Email::Folder and its relatives is probably what you want. You can see more about this at The Perl Email Project (though catch that quickly as the wiki seems to be favoured by comment spammers.)

    /J\

      hey, thanks i've started to read the site as of now.
Re: splitting email messages from /var/spoolio...
by madbombX (Hermit) on Jul 20, 2006 at 19:22 UTC
    I would have to say that your best bet (assuming I understand you correctly) is Mail::Box or Mail::Box::Manager. It's located here.

    Assuming that you are using mbox format for your mailboxes:

    use Mail::Box::Manager; my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open(folder => $ARGV[0]) or die("Mailbox open error: $!"); print $folder->name. ": ".$folder->messages ." Total Messages\n"; # Iterate over the messages foreach (@$folder) { print "Message $_"; } $mgr->close() or die("Mailbox close error: $!");

    Untested.