procmail
[Top] [All Lists]

Re: How to include an on the fly autogenerated file in procmailrc

2007-11-11 08:19:14
On Sun, 11 Nov 2007, Stefano Sabatini wrote:
Here it is my problem: I see that there is the possibility to include
a procmailrc inside another. Would be possible to include a file
autogenerated on the fly.....

I run a mailfilter with autoupdate of the user's text file whitelist
into a procmail recipe which occurs 'on the fly' and only when needed.
The following code 'checks' whether the recipe file is NEWER than any
of the source text or rc files. If it's not, the update script is run:

# LINEBUF makes the filter work space big enough to accomodate large recipes.
LINEBUF=128000
# If needed.....
SHELL=/bin/sh

# CHECK FOR WHITELIST OR FILTER CONTROL FILE UPDATES 
# - ".mailfilter.recipe" should be first in a file list sorted by 
#   modify date/time. If it isn't, this means the user has modified one 
#   or more files, so execute the PERL program "filtgen" so that the recipes
#   to process the incoming mail are current.
#   (New recipes are generated to a temporary file which is copied to
#    ".mailfilter.recipe" and deleted once generation is complete).
# - Set USER-ONLY permissions on the filter rc and recipe files.
#
# Even if logging is otherwise enabled, set it to dev null to avoid a
# bunch of nuisance possible 'file not found' messages....
LOGFILE=/dev/null
#
# - This script uses #HOME because it runs per user, replace $HOME
# with a hard path for system-wide usage, though you have to be sure
# this script then runs before privileges are dropped....
# - The name of the filter generating perl script is 
# IN this list so that if you upgrade your program, all the user RC files
# will automatically be updated!
# - All the file names with 'mailfilter' in them are home grown.
# I'm not showing my whole system here, just the regenerate code....
# - Note the 'c' this is NOT the delivering recipe.....
:1 c
? ( shudbeone=`ls -t $HOME/mailfilter.whitelist $HOME/mailfilter.blacklist \
    $HOME/.mailfilter.recipe $HOME/.mailfilterrc $FILTFILE/filtgen.pl |\
    awk '/^.*.mailfilter.recipe$/ {print NR}'` ;\
  if [ "$shudbeone" != "1" ] ; then \
    $PATHTO/filtgen.pl ;\
    cp $HOME/.mailfilter.recipe.new $HOME/.mailfilter.recipe ;\
    rm $HOME/.mailfilter.recipe.new ;\
    chmod go-rwx $HOME/.mailfilterrc ;\
    chmod go-rwx $HOME/.mailfilter.recipe ;\
  fi )
/dev/null

# Now include the recipe file which may or may not have just been updated
# by the above code.

# If you are loggging, reneable it with the correct name here:
#LOGFILE=$HOME/.procmail.log
INCLUDERC=$HOME/.mailfilter.recipe

-------------------------------------------

And that chunk of code will monitor and auto-run just about anything...

Enjoy!

- Charles, HWCN

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail