Subject: Re: remail with a twist

From: "John Ladwig" <[email-masked]>
Date: Thu, 9 Sep 93 06:37:44 CDT

Edward Vielmetti <[email-masked]> writes on 08 September 1993 at 21:15:36 -0400

 > What I'd like to do is munge up the Subject lines of the
 > remailed articles so that it's clear just what it is that
 > got matched, e.g. rewrite
 > 	Subject: this is something neat to grab
 > to
 > 	Subject: [FTP] this is something neat to grab
 >
 > Anyone doing this?  

Yep.  An excerpt from the .procmailrc script I use for emailed gopher
submissions:

  # Grab the item title from the Subject: line, ignoring keywords
  :0 hc
  SUBJECT= |sed -n -e 's/^Subject: .*[0-9]*\/[A-Za-z_]*[: ]\(.*\)/\1/p'

This cuts out a title from a subject line, ignoring keywords:

    Subject: 5610/announce: This is the title

produces SUBJECT="This is the title"

  # If we did (note 'a' flag below)get a valid name, 
  # file it, prepending to existing mbox file
  :0 a:.lock
  |formail -I "Subject: $SUBJECT" [...]

replaces the existing Subject: header with a new one containing the
original, keywordless, subject/title, giving us:

    Subject: This is the title

Since you don't need to cut out keywords, you can use formail instead
of sed, so it could be (though I haven't tested it):

  # Grab the item title from the Subject: line
  :0 hc
  SUBJECT= |formail -x "Subject: "

  :0 A
  |formail -I "To: ftp" -I "Subject: [FTP] $SUBJECT" \
  | $SENDMAIL -oi -t

---

From: [email-masked] (David W. Tamkin)
Date: Sat, 11 Sep 1993 16:51:20 -0500 (CDT)

Ed Vielmetti was thinking,

| I have a couple of mailing lists set up to reforward off to a
| particular site if something gets matched in the body of the
| text, e.g.
| 
| :Bc
| ftp
| ! ftp-lovers
| 
| What I'd like to do is munge up the Subject lines of the
| remailed articles so that it's clear just what it is that
| got matched, e.g. rewrite
| 	Subject: this is something neat to grab
| to
| 	Subject: [FTP] this is something neat to grab
| Anyone doing this?  I suspect that "formail" could be
| twisted to do such a thing, but the examples talk
| more about replacing headers than munging in place.

Hmm.  Two calls to formail will do it, one to extract the subject and one to
replace it:

:B # c flag is necessary until 2.80 or thereabouts, though
ftp
OLDSUBJECT=|formail -x Subject:
 :Af
 |formail -I "Subject: [FTP] $OLDSUBJECT"
 :Ac
 ! ftp-lovers

or to shorten it a little,

:B
ftp
OLDSUBJECT=|formail -x Subject:
 :Ac
 |formail -I "Subject: [FTP] $OLDSUBJECT" | $SENDMAIL ftp-lovers

There is a difference between the two, though: the first will eventually file
your own copy with the "[FTP]" added to the subject, but the second will file
it with the original subject unchanged.  You can change the first version's
results by filing your own copy first and then massaging and remailing it
(and of course dropping the c flag from the last recipe in the group).

Instead of two calls to formail, one call to sed will do the job as well:

:Bf
ftp
| sed -e '/^$/,$ b' -e 's/^Subject: /&[FTP] /'
 :Ac
 ! ftp-lovers

or

:Bc
ftp
| sed -e '/^$/,$ b' -e 's/^Subject: /&[FTP] /' | $SENDMAIL ftp-lovers

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