procmail
[Top] [All Lists]

Re: recipe to add names to a whitelist

2001-11-10 14:57:35
At 15:49 2001-11-10 -0500, Don Hammond wrote:

If I understand correctly, there may be more than one addition to the
whitelist (space delimited). Right?  If your tr groks "\n" or "\012" and
supports -s, --squeeze-repeats (GNU tr does):

  echo  "$WHITE" |tr -s ' ' '\n'

The sed is also dealing with compacting multiple spaces (and importantly, as corrected below, or tabs) into one, then replacing the single space with a newline. A mixed space/tab spacing would result in two newlines with the above tr (assuming it was updated to deal with translating tabs of course). The original sed expressions could have been combined into a shorter expression, but I was going to add trailing whitespace removal and just hadn't done that yet:

        sed -e "s/[     ][      ]*/ /g" -e "s/ $//" -e "s/ /\\
/g" ) >> $WHITELIST

(brackets are space+tabs)

After looking at it (specifically, the fact that the input is coming from _echo_, not a direct pipe), I realized that was unnecessary - if I merely change the flag on echo and deliberatley ADD a trailing space (which, if there as already some, will be condensed down to only one anyway by sed), one can simplify things further:

        |(echo -n "$WHITE " | \
        sed -e "s/[     ][      ]*/\\
/g" ) >> $WHITELIST

(normally, echo will add a trailing newline, in which case you don't want an extra newline at the end from the sed, so you'd want to trim out a trailing space -- HOWEVER, if you tell echo to not include the newline, but to tack a space on the end of the string it does emit, it all wraps up nicely into the shorter sed expression)

Anyway, this is intended to deal with "variance" in the input subject, where you wouldn't want extra blank lines in your output. If tr dealt with "combo" character repeats, it'd definatley be a better choice.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
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>