Mail queue and file locking

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi there, here's what I'm trying to do:

I'm on a Windows NT system, and want to monitor the Exchange mail queue for
new files. When there's a new file (an email) with certain keywords (i.e.
characteristic spam strings) I want to move the file to another folder so it
doesn't get sent.

Here's my approach, which is working but could probably be improved:

1. Poll the folder (waiting 1 second between polls)
2. If a file is "there", i.e. it has finished being copied across, and it is
less than 1 megabyte, scan it for keywords.
3. If the file has any keywords, move it to a different folder.
4. Goto 1.

To check if the file is copied across, I try to rename the file to itself.
If it's locked, Perl's rename function returns a 0 and if it's unlocked,
rename returns a 1.

I'm worried that using this approach of renaming files will lock them, and
prevent email from being moved out of the queue folder to be sent.

1. Is there a better way to detect new files than to poll the directory
every second?
2. What's the best way to check if a file is unlocked (i.e. fully copied
3. (Off topic) Any potential problems in scanning the NT Exchange 5.5 mail
queue folder and moving files out?


Site Timeline