#!/usr/bin/perl
#This script will lock in /var/spool/mail so that freaking sendmail respects it
#and doesn't append anything to the spoolfile while CSCMail is reading it - it
#was a pain to find out that sendmail doesn't respect flock() therefore this 
#script has to be installed setgid just like movemail, however at least its 
#our code.
#Maher <muhri@muhri.net>


$action = $ARGV[0];
$path = $ARGV[1];
if (!$action) { printf("This is a script to lock/unlock the mail spool file\n
for use with CSCMail, You shouldn't be running it.\n");

}
if ($action eq "lock") {

$tmp=">>$path.lock";
 if ($tmp=~/(.*)/){$tmp=$1;}
 open LOCK, $tmp or die $!;

}

if ($action eq "unlock") {

$tmp="$path.lock";
 if ($tmp=~/(.*)/){$tmp=$1;}
 unlink $tmp or die $!;

 }
