procmail
[Top] [All Lists]

Re: executing line by line through a message

1997-10-26 04:18:55
On Sat, 25 Oct 1997 19:13:12 -0500 (CDT), dattier(_at_)wwa(_dot_)com 
(David W. Tamkin) wrote:
I suggested this to Matthew Saroff,
| >     | while read url; do case "$url" in; *://*) lynx -dump "$url" ;; ; \
| >       esac | $SENDMAIL -oi $LOGNAME; done
Third, bash is barfing on a semicolon.  It could be that it doesn't
want both ";;" and ";" before esac; I don't know.  So let's try this,
a syntax which behaved when I tried it in pdksh: 
 :0bw
 * ^Subject: xxxxx
 | while read url; do case "$url" in  *://*) lynx \
   -traversal -realm -crawl -number_links "$url" | \
   $SENDMAIL -oi msaroff(_at_)pca(_dot_)net ;; esac; done
It might be impossible to get bash to take a case structure without 
embedded newlines.  If that is the case, we can either

Actually, this works fine with bash (an old 1.14.7 as well as a not so
old 2.00.0(1)). 

1. move the entire while structure into a shell script and call the shell
script on the recipe's action line, or
2. if the message body fits into $LINEBUF, use a recursive INCLUDERC to read
one line at a time.

I have also found this to work with some tricky commands:

 3. Define the actual pipeline as a variable, then pipe into the
    expansion of that variable:

COMMAND='while read url; do
    case "$url" in
      *://*)
        lynx -traversal -realm -crawl -number_links "$url" |
        $SENDMAIL -oi $LOGNAME
        ;;
    esac
done'

# You might have to muck with SHELLMETAS here

:0bw
* ^Subject: xxxxx
| eval "$COMMAND"


This is untested but I used to do a similar thing for some tricky sed
scripts with multi-line strings and lots of backslashes in them. It's
also nice for scripts where you want to echo back a multi-line message
with a single echo:

MESSAGE='Thank you so much for your message. 

Unfortunately, the volume of mail I receive .... (blah blah blah). 

If your matter is urgent, try calling +358-50-524-0965.
'

:0hw
* ! ^X-Loop: moo$
| ( formail -rt -A"X-Loop: moo" ; echo "$MESSAGE" ) | $SENDMAIL -oi -t


I don't like the former (for one thing, I'm always a bit superstitious
about code with eval:s in it) but it can imagine it might be a
necessary workaround in some situations. (In my experience, bash
doesn't force you to use braindead constructs very often. I'd imagine
the ksh is also mostly written with your sanity in mind. But if all
you have is a vendor-supplied /bin/sh, all bets are off.)

/* era */

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>