procmail
[Top] [All Lists]

Re: Brain dead Re^2 killer?

1997-07-23 14:50:00
Ben Stuyts wrote,

| Does anybody have a nice sed script to kill those brain dead "Re^2: blah"  
| that one sees here every now and then?

Ideally, since procmail's regexp matching is more powerful than sed's and
we're only going to end up using formail anyway to replace the subject line,
we should do it without sed.  sed would have a hell of a time looking for
as many appearances as it can find of Re: *OR* Re^number: *OR* Re[number]:.

This is the basic setup: ideally we would filter the head to extract what
is the base subject after all appearances of any variation on Re:, and unless
the only one is a single appearance of plain old proper "Re:", we change the
subject line to "Subject: Re: base subject."

The problem is that procmail's extraction is left-stingy and right-greedy.
No matter how long a string of Re:-equivalents there are, that will take
off only one of them.  Unless someone comes up with a regexp that will match
anything *except* an equivalent to Re:, we're looking at a recursive
INCLUDERC arrangement again.  Yecch; I have written those on occasion, but
I do hate them.

In the main rcfile:

      :0
      * ^Subject:[      ]*(Re(\^[0-9]+|\[[0-9]+])?:[:   ]*)+\/[^:       ].*
      { BASE_SUBJECT="$MATCH" INCLUDERC=.condense_re_rc }

and in .condense_re_rc:

      :0 # We know that the first condition will match; will the second too?
      * BASE_SUBJECT ?? ^^(Re(\^[0-9]+|\[[0-9]+])?:[:   ]*)+\/[^:       ].*
      * MATCH ?? ^^Re(\^[0-9]+|\[[0-9]+])?:
      { # If the second condition also matches, we still have at least one
        # more to strip off, so recurse again.
        BASE_SUBJECT="$MATCH" INCLUDERC=$_ }

      # When we get here, we know that $MATCH does not begin with another
      # equivalent of Re:.  If there was only one to start, and it was
      # a straight literal "Re:" with no nonsense, no change is needed.

      :0Efwh
      * $ ! ^Subject: Re: $\MATCH
      | formail -I "Subject: Re: $MATCH"

It needs some tweaking to deal with the case of having no real subject after
all the Re-equivalents; I am not positive of what we want in that situation,
so I haven't gone ahead with that provision.  As written, it will accept a
closing Re-equivalent with nothing else after it as a valid base subject.

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