procmail
[Top] [All Lists]

Re: Removing pesky Subject line tags

1997-08-06 23:07:00
Lance Brown asked,

| Several of the mailing lists I receive have started adding those pesky
| [LISTNAME] or {listname} tags to their Subject lines.

No kidding.  They're nuisance wastes of space on the index screen of my
incoming mail, shoving the real subject out of view.  Some of you may feel
less strongly, but if you're on this mailing list, you have better ways of
identifying mail that came through a list and don't need the tags.

Worse, some tagging routines don't grok Re:, and if someone receives a
list item with "LISTNAME: real subject" as the subject and responds by
sending "Re: LISTNAME: real subject" to the listserver, the membership
receives "LISTNAME: Re: LISTNAME: real subject."  Some do grok Re: but
not the non-standard yet common variations like Re[number]: or Re^number.

One list I'm on understands "Re:" but not "RE:" if the E is capitalized.

Better arrangements -- well, arrangements that are not so bad -- do not
insert the listname if it already appears somewhere in the subject, even
if it is not first.  I do offer such tags as an option on my mailing list
[an option that right now nobody is using], but if the list name, or the
list nickname, or any of a number of possible misspellings or straight
or cutesy abbreviations should appear anywhere in the subject, no tag is
added.  If it doesn't appear already, and there is a Re: or any recognized
variant thereof at the start, the tag is inserted after Re:.

| I've developed this recipe to get rid of them but it seems rather
| inefficient.  Can anyone suggest improvements?
| 
| # Remove annoying [XXX] tag from Subject line and store in MH folder
| :0
| * ^TOxxx@
| {
|     NEW_SUBJECT=`formail -XSubject: | sed -e "s/\[XXX\] //"`
| 
|     :0 fh
|     | formail -i "$NEW_SUBJECT"
| 
|     :0    
|     xxx/.
| }

You don't need formail and sed plus a shell to pipe them together; sed alone
can do the job:

  :0fwh
  * ^Sender: (owner-)?xxx@
  | sed -e '/^Subject:/!b' -e h -e 's/^/Old-/p' -e g -e 's/\[XXX] //'
   :0A
   xxx/.

That does assume that the [XXX] will appear in the first line of a continued
subject ... but continued subjects are very very rare.

At the very least you'll need some MATCH extraction to pull out the parts
of the subject that precede (difficult) and follow (easy) the tag and then
a filter through formail to displace (if you were using -I instead of -i
I'd have said "replace") the original subject.  If we may assume that no
left brackets precede the one at the beginning of the tag,

  :0
  * ^\/Subject:.*\[XXX].+
  {
   FULL_SUBJECT=$MATCH

   :0
   * FULL_SUBJECT ?? ]\/.+
   { SUBJECT_END=$MATCH }

   :0
   * FULL_SUBJECT ?? ^\/[^[]+
   { SUBJECT_START=$MATCH }

   :0fwh
   | formail -i "$SUBJECT_START$SUBJECT_END"

   :0
   xxx/.
  }

<Prev in Thread] Current Thread [Next in Thread>