Michael Helm <helm(_at_)fionn(_dot_)es(_dot_)net> wrote:
I'm trying to deal with a mailing list that has some subscribers
with problem user mail agents. These prefix the subject with
various junk strings that trip up threading & sorting in conventional
mailers, eg Re[8]: my subject or Sv: My subject or FW: stuff
I hate those stupid numbered subjects. I have considered writing
a nastygram generator that autoresponds to them saying get a real
MUA.
What's worse is that they combine like a genetics experiment:
Often see Re: Re[2]: Sv: FW: nothing
I can get rid of these junk strings separately, but what I want to
do is process an incoming message until they are *all* gone.
Use perl.
:0 fh
* ^Subject: *((re\-+)|(sv\:+)) *\/.*
| formail -I "Subject: Re: $MATCH"
Hopeless. Procmail's regexps are too broken.
For just the numbered ones, I have used this:
:0fh
* ^Subject: Re[[]
| perl -pe 's/^subject: (re(\[\d\])?: ?)*/Subject: Re: /i;'
Since perl will have *real greedy* regexps for the whole line,
instead of procmail's just after the \/, this will eat a whole
chain of "Re[128]: Re: Re[126]: Re: <...> Re[2]: subject" replacing
it with just "Re: subject". For the Sv and FW stuff it gets a
little more complicated, I tried this out on a few sample messages
and it seems to work.
:0fh
* ^Subject:
| perl -pe 's/^subject:\s((?:(?:re(?:\[\d\])?|Sv|FW):\s?)*)/\
"Subject:" . (($1=~m,\bre[[:],i)?" Re: ":" ")/ixe;
And here's that in a commented fashion (which, I hasten to add, is
fully legal in perl but will likely have line folding problems in a
procmailrc `perl -e` version):
s/^subject:\s # Match a line starting with subject and whitespace
( # Capturing & grouping parens
(?: # Grouping parens
(?: # Grouping parens
re # The text "re"
(?: # Grouping parens
\[\d+\] # The text "[number]"
)? # The number is optional
|Sv # The text "Sv"
|FW # The text "FW"
): # Any of "Re[number]" "Re" "Sv" or "FW" followed by a :
\s? # And an optional whitespace char
)* # Any number of repeats of that pattern
) # Capture the whole string
/ # End matching portion, start substitution portion
"Subject:" # The text "Subject:"
.( # Concatenated with
($1=~ # Use captured text for
m,\bre[[:],i # A test of matching for "re" followed by : or [
# the test being Insensitive to case
)? # If found
" Re: " # The text " Re: "
: # Else
" " # The text " "
) # Close paren
/ixe; # Insensitive to case, eXtended format, Execute sub portion
I love perl. :^)
Someday soon you will probably be able to do this directly in procmail,
using a 'p' filter flag. This is once I finish my perlembed hacks on it.
Elijah
------
Please do not CC me when replying to the list. It is not my responsibility to
prove to you my mail is not spam, if mail to you bounces it will not be resent.
------
#!/usr/bin/perl -w
$_="<j!y~f^v* >h(_dot_)g=c+m\(_at_)q[p;r} ?x/t|d:l#
)e\\p.d-s]p{c<,\n";$j=0;while(
s"[^\w\s,](.*)"($u=$1,$u=~s;(\w);(($s=ord($1)-97),chr((($s+$j++)%26)+97
));gex,$u)"ex){}exit !print;#18/5/97:etb