procmail
[Top] [All Lists]

"Normalizing" Re:

2002-12-19 13:41:58
I've been using the following filters for awhile, and just updated them
this morning to deal with "Betreff:" (Reference:).  I thought others
might be interested.  I run this stuff on my own systems, so am less
cautious about resource friendliness than I would be if on someone
else's. They're probably "over the top" in terms of self-documentation,
but there's no time to clean them up now so that's left as an exercise
for anyone who wants to use them and doesn't like them as is.

For the record, I have no axe to grind against Sven, whose software
injected Betreff: this A.M..  It's a big world, and we all have
different needs. It's just that for *my* purposes, I'd rather have it my
way on my system. I suspect others might feel the same. For that matter,
it could be used to translate Re: to Betreff: just as easily.

On this morning's mail, these produced:

 Subject: Re: sendmail/procmail virtusertable/aliases problem
 X-Orig-Subj: Re: Betreff: Re: sendmail/procmail virtusertable/aliases problem
 X-Filter-Info: <1p> Re: Betreff: Re: sendmail/procmail virtusertable/aliases 
problem
 X-Filter-Info: <3p> Re: Re: Re: sendmail/procmail virtusertable/aliases problem

There is one bug that I know of.  It'll remove the trailing Re: in the
Subject: of this very message.  I accept this because it was originally
an outgrowth of messed up (user inserted) Subject: [tags] where the
Re:'s weren't always at the beginning of the field.  It messes up very
infrequently and for me it removes more annoyances than it causes. YMMV.

I have a series of Subject: munging recipes, and I want to make sure
the original Subject: header is documented so that, if I reply to the
message, I can de-munge it appropriately. I use formail -i in some
other places, so stay away from Old-Subject: in favor of X-Orig-Subj:.
I want to record the original Subject: in these recipes only if it's
not been done already.  Many messages trip multiple simlar filters. I
used to translate foreign Re: and eliminate duplicates in one recipe,
but it turned out that multiple recipes with limited function had more
utility.

The only thing that's not self-contained is the variable SUBJECT which
is assigned to in another rcfile before procmail gets here.

# <0p> msg arrived with (Old-Subject|X-Orig-Subj):
:0 fhw
* 1^0 ^Old-Subject:
* 1^0 ^X-Orig-Subj:
|formail -R Old-Subject: Old-Old-Subject: -R X-Orig-Subj: Old-X-Orig-Subj: \
         -A "X-Filter-Info: <0p> msg arrived with (Old-Subject|X-Orig-Subj):"

# <1p> translate foreign Re:
xFOREIGN = '(Réf|R¨¦f|R\(&f|AW|Betreff)'

:0
* $ SUBJECT ?? ()\<$xFOREIGN\>
{
  :0
  * ORIGSUBJECT ?? ^^^^
  { ORIGSUBJECT = "$SUBJECT" }

  OLDSUBJECT = "$SUBJECT"
  xRULE='<1p>'

  :0 fhw
  |formail -a "X-Orig-Subj: $ORIGSUBJECT"

  :0 fhw
  | perl -pe '/^Subject:/i and s,\b($ENV{xFOREIGN}(\.? ?)?:),Re:,ig;'

  # Update SUBJECT variable for succeeding recipes
  :0
  * ^Subject:[  ]*\/[^  ].*
  { SUBJECT = "$MATCH" }

  :0 fhw
  | formail -A "X-Filter-Info: $xRULE $OLDSUBJECT"
}

# <3p> get rid of multiple Re:
:0
*   1^1 SUBJECT ?? ()\<Re:
*  -1^0
{
  :0
  * ORIGSUBJECT ?? ^^^^
  { ORIGSUBJECT = "$SUBJECT" }

  OLDSUBJECT = "$SUBJECT"
  xRULE='<3p>'
  :0 fhw
  |formail -a "X-Orig-Subj: $ORIGSUBJECT"

  # I don't remember why I save then restore SHELLMETAS here,
  # and don't see any reason why it's necessary. No time to
  # figure it out now.
  xSHELLMETAS = "$SHELLMETAS"
  SHELLMETAS
  :0 fhw
  |perl -pe '$_=join("",split(/R[Ee]: */))if/^Subject:/i;' \
         -e 's/^(Subject:) */$1 Re: /i;'
  SHELLMETAS = "$xSHELLMETAS"
  xSHELLMETAS

  # Update SUBJECT variable for succeeding recipes
  :0
  * ^Subject:[  ]*\/[^  ].*
  { SUBJECT = "$MATCH" }

  :0 fhw
  | formail -A "X-Filter-Info: $xRULE $OLDSUBJECT"
}


-- 
Email address in From: header is valid  * but only for a couple of days *
This is my reluctant response to spammers' unrelenting address harvesting



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>
  • "Normalizing" Re:, Don Hammond <=