Subject: Re: A few basic procmail questions

From: [email-masked] (David W. Tamkin)
Date: Fri, 24 Mar 1995 14:13:42 -0600 (CST)

Sharukh Merchant asked,

| 1. What is the default stdout and stderr for procmail?  If I invoke it
| standalone, i.e., procmail <procmail.in, where does the output go if I
| don't explicitly designate a file or program for it to go to?
| I had a simple test case
| 	:0
| 	| cat
| and there was no output whatsover either to my terminal or to my mailbox
| (cat >file was fine).

Just a guess here: if you invoke procmail interactively, stderr is inherited
from your shell until you assign a logfile; then stderr goes to the logfile.
Stdout I'm not so sure of.  It appears to be /dev/null when mail is delivered
but I don't know where it points when you invoke procmail interactively; my
results are the same as Sharukh's.

| 2. Why does procmail add an extra line to the output?  If I do
| 	:0 b  (or :0 h, for that matter)
| 	outfile
| then there is an extra blank line at the end of each message in outfile.
| Is there a way to suppress this?

There is supposed to be one blank line at the end.  If you're getting
additional blank lines added (you said "extra"), that I don't know about. 
Are you sure that the existing blank last line is truly empty and doesn't
contain any spaces or tabs?

| 3. I would like to get the body of my message, but ignoring ALL leading
| blank lines in the body (not just the ONE that normally separates the
| header and the body).  Since I am familiar with awk, here's what I use
| 
| | sed -e '1,/^$/d' \
| | nawk 'x==1 {print; next}; /^$/ {next}; /.+/ {x=1; print}'
| 
| (The sed expression by itself only removes the header and FIRST blank
| line.)  It works, but seems quite complicated to do a simple thing, so
| is there, perhaps, some little feature of formail or procmail that I
| have missed in the manual that would let me do this more easily?

It can be done with only one program instead of two; that's *some*
improvement:

 :0b: # lose the head
 | sed '/./,$ !d' >> file

or -- you didn't say -- if you're using it as a filter:

 :0bwf
 | sed '/./,$ !d'

or here's a nasty trick if the entire body is no longer than $LINEBUF charac-
ters, doesn't contain any backslashes, and doesn't have a hyphen as its first
printing character (the hyphen problem can be taken care of but the exact way
depends on the idiosyncrasies of your site's /bin/echo, and in some cases a
backslash will be harmless):

 :0bBwf
 * ^^( |	|$)*\/[^ 	](.*$)+
 | /bin/echo "$MATCH"

The parentheses enclose space, pipe, tab, pipe, dollar; the brackets enclose
caret, space, tab.  /bin/echo is likely to be a smaller binary to fork than
sed.

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284
[email-masked]    MCI Mail: 426-1818   +1 312 714 5610

---

From: Roman Czyborra <[email-masked]>
Date: Mon, 27 Mar 1995 11:40:29 +0200

> What is the default stdout and stderr for procmail?

stdout is closed whenever you use procmail for mail delivery.
procmail -m can pipe to stdout via the "|" file.

> Why does procmail add an extra line to the output?

To make sure the messages in your mailbox stay separated.

> Is there a way to suppress this?

Use the r flag.

> I would like to get the body of my message, but ignoring ALL leading
> blank lines in the body.

	:0fbw	# :)
	| nawk 'ONR||NF'

---

From: [email-masked] (Stephen R. van den Berg)
Date: Mon, 27 Mar 1995 18:17:19 +0200

>procmail -m can pipe to stdout via the "|" file.

Actually, procmail can *always* deliver to stdout using the '|' file.

In a recipe like:

	:0
	| cat

Stdout of the started program is always connected to /dev/null.

-- 
Sincerely,                                  [email-masked]
           Stephen R. van den Berg (AKA BuGless).

"Listen very carefully, I shall only say this once."

---

From: [email-masked] (s.merchant)
Date: 27 Mar 1995 18:29 EST

Thanks for your helpful replies, Roman.

>> Is there a way to suppress this?

There is no "r" flag in my documentation.  I think my system has 3.03,
and perhaps it wasn't in that.  Is there a "release notes" list, listing
which release each feature was introduced in?

>> I would like to get the body of my message, but ignoring ALL leading

Again, my version of nawk does not recognize ONR (I assume this is
number of records output).  I suppose
	| nawk 'onr || NF {onr++; print}'
would emulate this.  At any rate, that was a clever suggestion--it
concisely takes care of stripping off "blank" lines that have only
spaces and tabs too.  Thanks again.

Shahrukh

---

From: Roman Czyborra <[email-masked]>
Date: Tue, 28 Mar 1995 10:09:33 +0200

> There is no "r" flag in my documentation.  I think my system has
> 3.03, and perhaps it wasn't in that.  Is there a "release notes"
> list, listing which release each feature was introduced in?

The r flag was not added until version 3.10 according to
http://www.cs.tu-berlin.de/usr/elm/src/procmail/HISTORY

> my version of nawk does not recognize ONR

Try the GNU gawk then.

> Thanks again.

You're welcome.