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

Hi, On Sunday night I went to bed after working on our e-business. All the mail on our server had been downloaded (it checks every 5 minutes) using outlook.

Monday we have 17,000 emails in our inbox on the server and neither outlook, mailwasher, squirrel can open the inbox because they time out (it's too big).

This has never happened to us before. On a typical day we get around 500 emails. I can't completely erase or dump the inbox file because customers emailed us and we need to get their emails.

Is there some type of command line perl mail program that can go and run through the file and perform certain commands? We basically want to delete any emails that were NOT sent to a three our email addresses. All the others can be deleted. We also need to invesitgate and see why this happened.

Any suggestions? Otherwise, I can write my own program, but I'm afraid of messing or corrupting the format of the inbox file.

Replies are listed 'Best First'.
Re: Mail help
by liverpole (Monsignor) on Nov 28, 2006 at 17:41 UTC
    I'm unaware of any Perl mail program, but I do have one suggestion for you:  Make a copy of your mailbox (preferrably saving a copy to backup as well), and use the copy instead of the real thing, either for testing, or for developing your own Perl program to read it.

    That way, you won't corrupt the original, and you can always restore from backup if you destroy the working copy.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Mail help
by madbombX (Hermit) on Nov 28, 2006 at 17:48 UTC
    This is not a direct answer to your question, but a while back I had the need to parse a mailbox and I used a few perl modules to accomplish this task: Downloading IMAP Folders to mbox file. This is how I open the mbox file via IMAP.

    What I would do is to write an interactive script (if you want to go through the mailbox email by email) that will open up a connection to the server or the mailbox on the server and ask you to keep or delete it based on the subject of the message (which is easy to extract using Mail::Box::Manager (Example: Re: splitting email messages from /var/spoolio... or Re: sorting email with email::folder).

    Without knowing more about your setup (Exchange server or linux server using dovecot/courier with postfix/qmail/sendmail into mbox/maildir mailboxes etc) it is difficult to provide you with any more information.

Re: Mail help
by grep (Monsignor) on Nov 28, 2006 at 17:45 UTC
    Did you look at CPAN?

    If not, why would you post here without a basic search of CPAN?

    If you did look at CPAN and did not like a particular module, you should mention that in your post.

    You also should explain what your mail server is and more importantly what format the queued mail is stored in. That would help narrow down a suggestion (I know what I mean. Why don't you?).

    As to the problem of too much spam (I'm assuming) check out Greylisting. It's quite effective without much of a server load. There are several solutions and (from my experience) very easy to setup. If you are worried about the delay affecting your customers, you can setup an whitelist for your customers (avoids the delay) or set it up just to run on the weekend.

    grep
    XP matters not. Look at me. Judge me by my XP, do you?