Jump to content

Recommended Posts

Posted

I'm writing a script which modifes mailbox files (the purpose of this is to delete messages which are older than a certain date). My intention is to run this script as a Cron job. In order to avoid trouble if I try to modify a mailbox file at the same time that TCH's mail software is also modifying it, I need to be able to lock the file before I modify it, and unlock it again afterwards. This lock/unlock needs to be done in the same way that the TCH mail software does it.

 

Does anyone know how to do this?

 

Failing that, what is the software that TCH uses to process mail, i.e. to receive it via SMTP, to allow it to be fetched via POP3 or IMAP, and to do the webmail stuff? Presumably all of this software needs to be able to lock and unlock mailbox files. If I know what this software is I'll try to find out how it does lock/unlock.

 

Many thanks - Rowan

Posted
create a file called "inbox.lock" in the same directory as the inbox - and delete it again once you have finished.

Presumably I have to check for the existence of the file before creating it, and if it's already there wait a while?

 

And how do I create the lock file in an atomic way? I have read that the straightforward way of doing this can result in race conditions, especially if NFS is being used. Does TCH use NFS?

 

The recommended solution to this is said to be to create the lock file as a link to a previously created uniquely named file. Would you recommend this approach? Is this what the mail software used on TCH actually does? Or is there a better way?

 

Thanks for your help - Rowan

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...