André Rothe writes:
My solution is now:.mailfilter cc "|scripts/buildfilterlist" include "mailfilters/list" A directory "mailfilters" in the user's home which contain a lot of preordered rulesets. scripts/buildfilterlist #!/bin/bash ls -1 mailfilters/* | grep "^.*/[0-9]\{2,\}_.*" | sed -e 's/^/include "/' | sed -e 's/$/"/' > mailfilters/list chmod 600 mailfilters/list The .mailfilter calls a Bash script, which builds a current list of ruleset files, which the .mailfilter includes again.
This is mostly equivalent to: ls mailfilters/[0-9]* | sed -e 's/^/include "/' | sed -e 's/$/"/' > mailfilters/list There is no need to waste time with grep, when this is much simpler.However, this is not technically correct. Immediately after opening "mailfilter/list" for writing, the file will be empty. The new contents of the file get written to it a short time later. The time in question is minimal, a small fraction of a second, but it is not atomic, and it's possible that mail being delivered at that time will attempt to read "mailfilter/list", and read an empty file.
Marginally, it is also possible that if the list of files is very large, "mailfilter/list" will be partially written, cut off in a middle of a statement, and maildrop will encounter a parsing error, and abort mail delivery.
The chances are small, but real.The way to do it correctly is to write the new contents into a temporary file, and rename it. Rename is an atomic operation:
set -e ls mailfilters/[0-9]* | sed -e 's/^/include "/' | sed -e 's/$/"/' > mailfilters/list.tmp mv mailfilters/list.tmp mailfilters/list
pgpuj_xpydkTZ.pgp
Description: PGP signature
------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________ courier-users mailing list courier-users@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users