Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving email with IMAP 2

Status
Not open for further replies.

casperovjp

Programmer
Jun 30, 2002
18
FR
I'm trying to move email from one folder to another. On that part I was successful. But if two or more people move the same email at the same time it will make several copies of that email, one for each request.

I want to prevent this from happening. I'm thinking if it is possible to make only one connection at a time. So others will have to wait their turn. Or be able to lock an email so others can not move or make a copy of that email.

Any suggestions will be greatly appreciated.
 
what's about writing a lock file? PHP is server side, so if you visit the "move" page, write a lock file (say.. /tmp/move_mail.lck), so if another user visit the "move" page and the file exist he can be redirected to "Sorry page in use".

Hope this helps.
 
Thanks thats a great idea. Now all I need to know is how to make a lock file. Do you know how or at least point me to the right direction. Thanks!
 
it's as simple as creating a txt file. it doesn't even have to have something in it.

Code:
//incoming request to move file filename.txt
$path="path/to/";
$filename="filename";
$ext = ".txt";

//check to make sure file exists
if (!file_exists($path.$filename.$ext))
{die ("file does not exist");}

//check for lock file
if(file_exists($path.$filename.".lck"))
{
  die("file is currently locked for editing");
}

//if we got here there is no lock file

//create lock file
$fh = @fopen($path.$filename.".lck","w+")

if (!$fh)
{
  die("unable to create a lock file");
}
fclose($fh);

//perform the move here

unlink ($path.$filename.".lck");
// file is now ready for copy again.
 
Code:
//check to make sure file exists
if (!file_exists($path.$filename.$ext))
{die ("file does not exist");}

???? it should not exist!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top