procmail
[Top] [All Lists]

Re: not starting one recipe until the previous has finished

2000-01-05 17:11:58
check out the 'w' and 'W' flags. I think they make procmail wait until the
forked program finishes before proceeding.

example:
:0hfw
| $FORMAIL -I"Subject: hi"


On Wed, 5 Jan 2000, Benjamin Elijah Griffin wrote:


I need to have one recipe wait for a previous one to finish
before it should run. (One saves output from a filter to a
file, the next prepends that output to the message body.)

Merely having the recipes sequentially placed in the rc file
does not seem to be sufficent. I'd guess it is the :c flag
that causes this; does procmail still implement :c by forking?

So next I tried setting LOCKFILE before the first recipe and
clearing it after the second, but that does not seem to help.
I've also tried storing the output of the filter in a procmail
variable, but it was doing something funny, removing the newlines
or somesuch.

So I just gave up and put a sleep in the second recipe.
Recently that has failed due to my getting some very large
messages (specifically MP3 files).

What's the ideal way to do this, other than having the filter
rewrite the body itself?

Benjamin
------
# a procmailrc file to deal with attachments
# Benjamin Elijah Griffin     7 Dec 1999

:0
* ^Content-type:[     ]*multipart/(mixed|related)
{

  # VERBOSE=yes
  BASEDIR=$MAILSPOOL/attachments

  # Don't let dumper and the cat below run at the same time.
  LOCKFILE=$MAILSPOOL/.wait-for-it

  # The perl script creates a directory based on the date,
  # the passed in base dir, and a unique sequential number
  # for each day. It returns the name of the directory.
  SAVEDIR=`perl -we 
'@t=localtime;$t=sprintf("%4d%02d%02d",$t[5]+1900,$t[4]+1,$t[3]);$bd=(shift||".");for($i=1;-d($n="$bd/$t-$i");$i++){;}mkdir($n,0755);print"$n"'
 $BASEDIR`

  PID=$$

  # Do the dump and grab the ouput; dumper is based perl's MIME::Parser 
module.
  :0hbc
  |$HOME/bin/dumper -o $SAVEDIR > $SAVEDIR/dumper.$PID.out

  # Prepend that output to the message body (where MIME-compliant
  # mail readers will ignore it).
  :0bf
  | (sleep 5; cat $SAVEDIR/dumper.$PID.out $MAILSPOOL/.blankline -)

  LOCKFILE=
  # That's it. We are done.

}