How to lock an inbox using UNIX scripting

Hi All,

I have an inbox , which recieves mails every second. I need to copy the contents of the mails in the inbox to a file , say once every minute. Then clear the content of the inbox. There is a possibility that a new mail might come in before I delete the content.

Please let me know if there is a way to lock the inbox , so that no new mails come in , and they are queued up , till the time the lock is released.In that time gap I will copy and clear the contents of the inbox without loosing any mails.

This is bit urgent , so please help me in this. Also I not well versed in UNIX scripting.

What happens if you just move the inbox to a new filename before processing it? Does your mail program re-create it or does it have the inbox permanently open (i.e. referencing it by inode)? What is your mail delivery program, sendmail or something else?

I would also try setting the mail user alias to point to a script instead of a file (you can do this in sendmail). Then the script can decide what to do with each email, and put it in different files depending on the time of day...