Subject: Re: autoreply header questions

From: "Michael J. Corrigan" <[email-masked]>
Date: Thu, 29 Dec 1994 16:13:23 -0800

> For my autoreply messages there are a group of headers that I 
> always want to use (Organization, X-Delivered-By-Graces-Of, etc.).
> Is there a way to put these in a file and then just include this
> file in the headers of an autoreply msg?
> 

In the framework of your earlier recipe you could have:

...
* !^Precedence:.*list
{
  SUBJECT="Subject: I'm on vacation [Re:`formail -xSubject:`]"
  FROM=`formail -rtxTo:`   #
  EXTRA_AUTOREPLY_HEADERS="$HOME/.procmail/autoreply_headers"
  ALREADYSENT="$HOME/.procmail/vacation.db"   #vacation database

  :0 c:
  * !? fgrep -e "$FROM" $ALREADYSENT
  | echo "$FROM" >> $ALREADYSENT ; \
    (( cat $EXTRA_AUTOREPLY_HEADERS ; formail -rtI"$SUBJECT") ; \
     cat $HOME/.procmail/vacation.msg ; \
     echo "-- " ; \
     cat $HOME/.signature ; \
     ) | $SENDMAIL -oi -t
}

where $HOME/.procmail/autoreply_headers contains the extra headers (only).

---

From: [email-masked] (David W. Tamkin)
Date: Thu, 29 Dec 1994 19:46:46 -0600 (CST)

| For my autoreply messages there are a group of headers that I 
| always want to use (Organization, X-Delivered-By-Graces-Of, etc.).
| Is there a way to put these in a file and then just include this
| file in the headers of an autoreply msg?

Michael Corrigan gave a good answer; cat them in front of a formail -r[t]
command.  formail -r[t] doesn't generate a From_ header, so you'll have
a solid block of headers as the combined output.

| Question 2: What's the easiest way to remove all leading ``Re: ''s
| from the Subject of an incoming message?  Can I add a flag to
| ``formail -x'' that will do this or should I use something like sed?

formail -r[t] is not supposed to add "Re:" if there already is an initial
Re:, but there are broken mailers out there that like to keep adding Re:
after Re: or come up with nasty things like "Re[2]:" that other mailers
don't recognize as a Re: and then will put an other Re: in front of.

You want a sed command, Nancy?  Embedding newlines between sed instructions
as I like to do in shell or sed scripts can be a pain in a .procmailrc, so
there I use the -e syntax instead and as many semicolons as I can get away
with:

formail -zxSubject: | sed 's/[Rr]e: *//g; s/[Rr]e[[(][0-9]*[])]: *//g'

or, if your sed doesn't grok semicolons,

formail -zxSubject: | sed 's/[Rr]e: *//g' -e 's/[Rr]e[[(][0-9]*[])]: *//g'

Since Stephen released procmail 3.10 I prefer to do as much text manipulation
as possible with the MATCH facility instead of forking other programs, but
the MATCH operation is right-side greedy.  If it were left-side greedy we
could do this:

# This is a buggy recipe; do not paste into a real rcfile.
# :0fwh
# * ^Subject: *(Re *([[(][0-9]+[])] *)?:)+ *\/.*
# | formail -I "Subject: $MATCH"

If there were a syntax for saying "anything but this expression" [something
comparable to later kshs' !(globpattern) construction] we could do this
[where I'm using (regex)\! to say "something non-null that doesn't match the
regex"]:

# This is an even buggier recipe; do not paste into a real rcfile.
# :0fwh
# * ^Subject: *(Re *([[(][0-9]+[])] *)?:)+ *\/(Re *([[(][0-9]*[])] *)?:| )\!.*
# | formail -I "Subject: $MATCH"

Instead we need to pull a recursion trick, which probably is no better than
just forking sed and getting it over with:

  :0
  * ^Subject: *(Re *([[(][0-9]+[])] *)?:)+ *\/.*
  { NEWSUBJ=$MATCH INCLUDERC=$HOME/.stripsubrc }
  :0Afwh
  | formail -I "Subject: $NEWSUBJ"

That would strip "Subject:" and one "Re:" or "Re[number]:" or "Re(number):"
from the subject and then slide over to read code from $HOME/.stripsubrc.
$HOME/.stripsubrc would contain something like this:

  :0
  * NEWSUBJ ?? \ *Re *([[(][0-9]+[])] *)?: *\/[^ ].*
  { NEWSUBJ = $MATCH  INCLUDERC = $_ }

That would recurse until $NEWSUBJ didn't begin with Re: or Re[number]: or
Re(number): any more and finally return to the main rcfile, where the :A
recipe would change the subject line.

[The question came at a good time; I just thought of the recursion trick
in connection with another problem Monday afternoon.]

There is also a way we could remove two occurrences of Re: or Re[number]: or
Re(number): at a time, but it is REALLY hairy to type.  It could save some
recursion levels, though.

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