Mark Bynum wondered about some procmailrc code I wrote:
| I have several questions, interspersed through the recipe.
| > :0
| > * conditions
| > { FOLDERNAME=wherever
| > LOCKFILE=$FOLDERNAME.lock # needs regional lockfile
| > MAXLETTERS=put_your_number_here
| >
| > :0c
| > $FOLDERNAME
|
| Everything is understandable up to here.
OK.
| > # XTRAIN includes the incoming letter:
| > XTRAIN=`formail -I'From x' -z -x'From ' -s < $FOLDERNAME`
|
| What I believe the above line does is insert a "From x" header into each
| message, and then extract what is after the "From " (which is x) from
| each message and put all of them in XTRAIN. In effect, this counts
| the number of messages in the mailbox. Is this right?
Yes. $XTRAIN will consist of a list of x's, separated by newlines, one x
for each letter in the folder, with a trailing newline after the last x.
| > :0hicw
|
| Why do we generate a carbon copy here, this is the only recipe that
| we want this message to operate on. Also why do we wait for the exitcode
| of the command, it seems we don't do anything with it?
Because I missed something in editing a simple recipe into a brace nest.
"h", "i", and "w" are meaningless when the action is "{", and "c" is
incorrect because we've already saved the one backup copy we want; we don't
want to launch a clone after all. So yes, Mark, it should be just :0 and
nothing more.
| > * 1^1 XTRAIN ?? x
| > * $ -$MAXLETTERS^0
| > { EXCESS = $=
|
| I am going to make EXCESS a static number, say 50, where MAXLETTERS is 75.
| This will hopefully not tax the mail server as much, such as for every
| message over 75.
No, no, you can't make $EXCESS a static number. It has to be calculated
each time based on how many letters are in the folder.
| What I believe the lines above did is generate a score of how many x's are
| in XTRAIN (i.e. how many messages are in FOLDERNAME), subtract MAXLETTERS
| from it, then if positive do what is inside the braces.
Right. But if the score is zero or negative, go past that set of braces and
sink to /dev/null.
| > :0fwi
| > | formail +$EXCESS -s < $FOLDERNAME
|
| This skips EXCESS messages from FOLDERNAME. Why not only feed the header
| to the pipe, wouldn't this help because we don't do anything with the
| input coming from procmail? We don't need the whole message right?
If we feed only the header, then the `f' flag will replace only the header.
An extra copy of the body of the original incoming message will get tacked
onto the foot of output of formail. So the `h' flag is poison there. We
need to replace both head and body of the incoming message with the output
of formail.
| > :0r
| > | cat > $FOLDERNAME
| > }
| We have the r flag, because formail already made sure the mail ends with an
| empty line.
No. We have the `r' flag because the output of formail in the preceding
filter recipe will have a number of occurrences of '^From ', and we don't
want procmail to escape them to '>From '. We *want* them to appear as
starts of new messages in the rewritten folder.
| > :0h
| > /dev/null
| I have no idea why this is here. The processing is done, correct?
It's there in case $EXCESS was zero or negative. We've already appended the
incoming message to $FOLDERNAME, so we want to sink it if we don't need to
trim the folder.
| > LOCKFILE # just in case of fall-through
| > }
I'm overcautious there. If there is fall-through after a dump to /dev/null,
you have trouble much worse than a leftover regional lockfile.