procmail
[Top] [All Lists]

Re: Loop within ~/.procmailrc possible?

2003-01-09 13:01:03
is it possible to make a loop _within_ the ~/.procmailrc ?

Yes.  But probably not as neatly as you hope.  You can use recursive
INCLUDERCs to continuously modify a variable until some condition is
met.  For example (and there are plenty of other modifications and tests
that you could use to obtain the same effect as this):

 create a file called, say, looprc containing:

    LOG="I is $I
    "

    :0
    * I ?? ^.\/.*$
    {
            I=$MATCH

            :0 fhw
            * ^()\/[^:]*:
            | formail -I "$MATCH"

            INCLUDERC=looprc
    }

 and in your main rc file have something like:

    LOG="Starting
    "

    I=xxxxxxxxxx

    INCLUDERC=looprc

    LOG="Done
    "

which, when invoked, logs something like:

    Starting
    I is xxxxxxxxxx
    I is xxxxxxxxx
    I is xxxxxxxx
    I is xxxxxxx
    I is xxxxxx
    I is xxxxx
    I is xxxx
    I is xxx
    I is xx
    I is x
    I is
    Done

What happens is:

the main rc file sets the variable I to be a 10 character string, then
it invokes looprc.  The top-level recipe in looprc checks that $I
contains at least 1 character, and sets $MATCH to be everything after
the first character

    * I ?? ^.\/.*$

then (if the test succeeded) sets $I to be $MATCH

    I=$MATCH

So now $I is one character shorter than it was when looprc was invoked.
It then performs your filter operation (note that you had no '*' at the
start of your condition line!) then invokes looprc again.

When $I no longer consists of at least one character - after ten
iterations - it winds back out.

Hope that helps,
Martin
-- 
Martin McCarthy                 /</    http://procmail.non-prophet.org
    `Procmail Companion'        \>\
     Addison Wesley             /</                  PGP key available

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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