Subject: Re: lots o' questions

From: [email-masked] (David W. Tamkin)
Date: Tue, 11 Oct 1994 22:17:59 -0500 (CDT)

Nancy McGough asked few questions, of which I can answer some:

| 2] What does "exit 75" mean in the suggested .forward file?

With many mail delivery agents, if the mail thrower exits with status 75 the
delivery agent requeues the undelivered letter and tries again later.  Any
other non-zero exit status is an irrecoverable failure and will cause a
bounce, either to the sender or, if the delivery agent has some intellect,
to the owner of the forward file.

| 3] What is the difference between using :0: and :: at the beginning
|    of a recipe that has all conditions starting with *?

When the flag line has no number, procmail expects one condition unless the
'A', 'a', 'E', or 'e' flag is present, in which case procmail expects zero
conditions.  You can always add more conditions than the number expected,
even if that number was specified in the flags, by using asterisks, and
asterisks on expected conditions don't hurt.

If a recipe requires no flags except a request for a local lockfile, usually
:0: and :: are equivalent.  However, if there really are zero conditions --
if the recipe is executed whenever procmail gets to that part of the rcfile
regardless of any particulars about a given letter -- then "::" will make
procmail expect one condition and therefore mistake the action line for the
condition (and probably the next line after it for the action).

If you always use the zero and always use asterisks, you can't go wrong.

| 6] The procmailex man pages uses the regular expression ^^(.+$)*^%!
|    Could someone explain what exactly this means.  I know that ^^ means
|    the beginning of the first line but what does (.+$)*^%! mean?

Procmail allows multi-line regular expressions, so "$" always means a
newline, even if it isn't at the right end of the expression.  (You need
"\$" to match a dollar sign.)  "." matches any character except newline,
so .+$ matches a complete non-empty line.  (.+$)* matches zero or more
consecutive non-empty lines.  [I'm not sure if "$" can mean a right anchor
where there is no newline; that is, I don't know if a final "$" is a
substitute for "^^" if the search area does net end in a newline.]

"^" also means a newline (you need "\^" to match a literal caret) except
in the ^^ token (which means beginning or end of search area -- well, I
think it just now with version 3.10 can mean end as well as beginning).

When the search area is the entire text (HB or BH flags or, in 3.10, "HB ??"
or "BH ??" search area specifiers), that expression means "from the beginning
of the search area, find zero or more non-empty lines and the newlines that
terminate them, another newline (the caret) [thus forcing a blank line if
`zero or more' turns out to match one or more], a percent sign, and an
exclamation point."  Thus it would find %! at the start of the body with a B
flag (or, in 3.10, the "B ??" search area specifier) or with HB or BH flags. 
Somehow the caret can also mean a left anchor, I think ... if I wanted to
find something in the header or at the start of the body, I'd use this,
though, since I'm not positive how non-initial carets work, and I'd search
HB (or BH):

   ^^(.+$)*$?search_string

To get a string that would work on a search of B as well as one of HB or H,
I'd do this, but it might fail if the header is currently in a state of flux:

   ^^(From .+$(.+$)*$?)?search_string

| 7] What version of procmail started understanding TO, FROM_DAEMON, and
|    FROM_MAILER?

That should be in the HISTORY file.

| 9] Is there a standard name for the procmail log file - right now I'm
|    using ~/.procmailrc.log?

There is no standard name; I call mine Ralph or Sheila, depending on the day
of the week.  (Actually I use ~/.pmlog, which in turn is a symlink to yet
something else particular to my setup here.)

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

---

From: [email-masked]
Date: Tue, 11 Oct 1994 23:44:46 -0700 (PDT)

>> Nancy McGough wrote:
> 8] Is there an easy way to get a list of only procmail errors.  Right
>    now I'm using mailstat to look at all activity but I'd like to just
>    look for errors during each login.

  Nancy, here's a shell script I wrote a while back that summarizes
the procmail log and report any errors.  Hopefully the comments are
sufficient explanation...  You could put a call to proc-sum into your
.login/.profile file.

#!/bin/sh
# A simple script to provide the functionality of elm's "filter -s"
#  - summarize the contents of the logfile.
# Also, supports -c to clear the log
#  since we don't know where you  put the logfile, you must
#  tell us explicitly on the command line.
# Syntax:
#   proc-sum mylogfile
# or
#   proc-sum mylogfile -c
#
# Oh, don't forget to set LOGFILE=mylogfile in your .procmailrc
# 
# To use this as suggested in elm  add the following to your crontab
#1 3 * * * $HOME/bin/proc-sum $HOME/mylogfile -c |/usr/local/bin/elm -s 'Filter Sum' $USER
# the command  will mail you a summary & clear the log at 3:01 AM every day.

# First, simple error checking.
if ( test -z "$1" ) then 
   echo You must call $0 with the name of your procmail log file.
   exit 1
fi
if ( test ! -r "$1" ) then 
   echo "Log file $1 does not exist!"
   echo Perhaps you have received no mail.
   exit 1
fi

# "Folder:" is the only type of line that really counts for our
# summary.  Sort the lines so the awk script can count it easily.
egrep '^ *Folder:' $1 | sort | awk '
BEGIN { cnt = 0}

# this action puts the procmail action into a single string named action
{ action = $2; first_item = $2
  for ( x = 3; x < NF; x++ ) {
       action = sprintf "%s %s", action, $x}
}

action != prev { if ( prev != "" ) {
		    printf "%s messages ", cnt;
		    if ( -x first_item) printf "Processed via: %s\n", prev
		    else printf "Stored in %s\n", prev;
		    cnt = 0}
	 	prev = action}

action == prev { cnt++ }

END {		    printf "%s messages ", cnt;
		    if ( -x first_item) printf "Processed via: %s\n", prev
		    else printf "Stored in %s\n", prev;
#print first_item
}'

# now report any errors that made it into the log.
echo ""
echo "Errors, if any:"
/usr/bin/egrep -v '(^(From| *Subject:| *Folder))' $1
echo "Done."

# do a slightly smart "clear log" function:  keep a single backup.
if ( test "$2" = -c )  then 
  echo Saving log file to $1.old
  mv -f $1 $1.old
fi

---

From: Roman Czyborra <[email-masked]>
Date: Wed, 12 Oct 1994 15:40:48 +0100

> 4] What happens when you are using Pine to read a folder (not $DEFAULT)
>    and a procmail filtered message arrives and the folder is locked?  And
>    what happens if the folder is not locked?

Mail, Elm and Pine are all very tolerant of and prepared for other
messages being appended from the outside to a folder they are
currently looking at.  They will incorporate the new stuff before
writing out their deletions.  There is just this slight possibility
that messages arrive in the short time span between their check on the
file size and the completion of their write operation.  Therefore you
need to use local lockfiles, i.e. add colons in .procmailrc and
specify the incoming-folders list in your .pinerc.

> 5] The procmailex man pages mentions a program called movemail?  What is
>    this and where can I get it?

Emacs comes with it.  It is a tiny C program that locks your mailbox
and moves its contents to another place.  Unfortunately it is not
immune to clock skew in a network file system and has caused loss of
mail.  You are better off replacing it with the equivalent but safer

	#!/bin/sh
	set -e; lockfile $1.lock
	set +e; cp -ip $1 $2 && ( : ) > $1; rm -f $1.lock

> 9] Is there a standard name for the procmail log file

I personally use .elm/logfile but recommend $HOME/.maillog because not
everybody has the .elm directory.  If you just want to log errors you
can set LOGABSTRACT=no.

---

From: [email-masked] (Stephen R. van den Berg)
Date: Fri, 14 Oct 1994 13:26:40 +0100

Nancy McGough <[email-masked]> wrote:
>1] Is it possible to use ftp to do archive retrieval or do you have to
>   email [email-masked] to get files like
>   best_of_procmail_list.gz?

It will be possible to get them via ftp or http some day.  But I'd have to
automate this first somehow.  Due to a lack of time I didn't get around
to doing this yet, so yes, currently you have to use the mail server.

>2] What does "exit 75" mean in the suggested .forward file?

The "exit 75" only takes effect if the procmail binary could not be found.

>6] The procmailex man pages uses the regular expression ^^(.+$)*^%!
>   Could someone explain what exactly this means.  I know that ^^ means
>   the beginning of the first line but what does (.+$)*^%! mean?

This matches "%!" at the very start of the body (i.e. directly following
the first empty line).

>7] What version of procmail started understanding TO, FROM_DAEMON, and
>   FROM_MAILER?

All versions of procmail understand ^TO.  The other two were introduced
somewhere around v2.80 (the HISTORY file is trimmed now and then, this
was already weeded out).

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

"Good moaning!"