Perl supports opening pipes to processes as well as files.... so...
open(HNDL, "mailx -args |");
That last character is a PIPE. I don't remember all the args you need (I think mailx by default first gives you only headers, but there is an argument that tells it "just dump the whole mailbox")
So now you can do something like
while (<HNDL>)
{
# do all your parsing code line by line subjects AND bodies
}
close(HNDL);
Now this is WAY over simplified, because after you dump the mailbox you have to execute mailx again like system("mailx -args bla bla bla") or die;
or qx|mailx -args bla bla bla|, etc to DELETE the mail you've just read. But you have to be careful that you don't delete NEW mail that comes into the box while you are reading so count the headers and delete only those perhaps with something like mailx -d1-10 or something like that... Also, I don't know what kind of mail might show up in this box -- could it have attachments, etc.
There is a whole other approach you might find useful... I used to set up special accounts whose only purpose was to receive email of a certain kind, etc. Like we would tell our trading partners to send all X12 data to
xyzaccount@myhost.com or what ever... xyzaccount then had a .forward file and the .forward REDIRECTED the email into my perl scripts...
so .forward would be something like "| myscript.pl". Thus everytime mail was received by xyzaccount it would be immediately piped to the script, one mail at a time. No need to open and read the mailbox....
Now one issue there is that sometimes for security reasons sysadmins won't let you FORWARD email to a PROCESS (as opposed to just another address). We had no problem with this since we expected only ONE kind of mail in that account and the first thing myscript.pl would do is make sure that it was the kind of mail we were expecting. If not, we just quit, issue a warning, etc.
quine@sonic.net