procmail
[Top] [All Lists]

Cloning within a LOCKFILE block

1997-10-12 07:15:38
The first email message I receive each day causes procmail to email me a
file.  The file is a summary of suspected spam.

Basically, each message compares the current date with the date stored in a
flag file, and if different, email me the "summary.spam" file.

I must wait for this operation to complete before processing the current
mail, as the current mail may need to write to the "summary.spam" file.

I used Edward J. Sabol's great suggestions for mailing the file to myself as:


   # Golbal lock for entire transaction
   # (flag file might not exist)

   LOCKFILE=summary.spam$LOCKEXT

   TODAY=`date '+%m-%d-%y'`

   :0i  #Is this flag necessary?
   * ? test -f $SPAMDIR/currentdate
   { 
      CURRENT=`cat $SPAMDIR/currentdate`

      :0
      * CURRENT ?? ! $ ^^$\TODAY^^
      {
         # update the current date as today
         DUMMY=`echo $TODAY > $SPAMDIR/currentdate`
         
         # now send yesterday's spam summary (must wait)
         :0icwr
         * ? test -f $SPAMDIR/summary.spam
         | Mail -s "Spam Summary for $CURRENT" $LOGNAME <
$SPAMDIR/summary.spam && rm -f $SPAMDIR/summary.spam
      }
   }

   :0E  # Flag file "currentdate" doesn't exist, so create
   { DUMMY=`echo $TODAY > $SPAMDIR/currentdate` }


   # Unlock and unset
   LOCKFILE
   CURRENT
   TODAY


Instead of spawning Mail (and thus another procmail), it would seem better
if I just cloned the current mail, replaced the mail body with the contents
of the file "summary.spam" and then just delivered the mail to $ORGMAIL.

Obviously I need to prevent the parent mail from writing to summary.spam
before I finish delivering the mail and deleting the summary file.

What I'd like to do is place the entire block above (except the global
LOCKFILE) within a locked nesting block that uses the SAME lock file as
used later in the procmail recipe?

   :0c:summary.spam$LOCKEXT
   {
      ...
   }

But era pointed:

$ cat scratch/rc
:0:pluck
{
  :0:
  /tmp/output
}

$ procmail DEFAULT=/dev/null scratch/rc </dev/null
procmail: Extraneous locallockfile ignored

In a VERBOSE log, you'll actually notice that it locks, then releases
the lockfile +before+ going inside the block.

So how do I clone and preserve the lock file.  If I clone within the
LOCKFILE block above, won't the parent remove the LOCKFILE when it jumps
across the current nesting level?

Thanks,

Bill Moseley
mailto:moseley(_at_)netcom(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>