procmail
[Top] [All Lists]

FW: problems with subject replacement recipe

2001-03-16 08:35:52
Yesterday I got a private reply from Era, long sorely missed
here publicly.  He was responding to some partially erroneous
advice I offered Vince the previous day.  I wrote Era back and
suggested he cc. the list, assuring him that my ego can
stand public correction when I'm wrong.  He suggested in
return that I forward this to the list.  So that's what I'm
doing.

By the way, I suppose it's age, but lately I feel less able
to concentrate hard for extended periods.  Either for that
reason, or for reasons of being generally on overwhelm for
the last few months (or both), I find that I sometimes
have trouble following what others are doing with procmail
nowadays when it used to slide right into my noggin.  Hmm.

dman

-----Original Message-----
From: era eriksson [mailto:era(_at_)iki(_dot_)fi]
Sent: Thursday, 15 March 2001 8:51 AM
To: Dallman Ross
Cc: vjl(_at_)cullasaja(_dot_)com
Subject: Re: problems with subject replacement recipe


On Wed, 14 Mar 2001 04:58:00 -0500 (EST), Dallman Ross 
<dman(_at_)nomotek(_dot_)com>
wrote:
I'm having a problem with the follow recipe under procmail v3.10

(That's an awfully old version, but I haven't been following this
thread -- or the list -- so perhaps this has been noted alrady.)

* ^Subject: *\/.*$
No need for the trailing `$', though it doesn't change anything
except perhaps the slowing of things down by a tiny, tiny
increment.

Actually, it will include the trailing newline in MATCH, which may or
may not be what you're after. But the " *" before the \/ doesn't skip
any spaces. That's because the \/ operator changes how things are
matched. You probably want "^Subject:[  ]*\/[^  ].*" with tabs and
spaces in between the square brackets.

 $ cat <<'HERE' >~/scratch/r
SHELL=/bin/sh
:0
* ^Subject: *\/.*
{ LOG="MATCH='$MATCH'
" }
:0
/dev/null
HERE

 $ while read subject; do
  echo "Subject: $subject" | procmail ~/scratch/r
done <<'HERE'
 subject
subject

this is a test
HERE
 MATCH=' subject'
 MATCH=' subject'
 MATCH=' '
 MATCH=' this is a test'

{    # strip off any leading "Re: " strings
CURSUB=`echo $MATCH | sed -e 's/^ *R[Ee]: *//g'`
The above line is a problem. You are telling sed to find multiple
instances of a line's beginning, for one; but there will only be
one match of a line's beginning. So the g-flag is useless with the
leading caret.

I'd imagine the intent is to remove repeated Re: prefixes. The regular
expression asks for space or beginning of line immediately before the
R, which is not captured by your updated proposal.

Try this instead:

  CURSUB=`echo "$MATCH" | sed -e 's/^\(R[Ee]:[          ]*\)*//'`


It looks for and replaces repeated "Re: " prefixes at beginning of
line (i.e beginning of the extracted, now hopefully canonicalized
Subject).

Second, you've already stripped away leading spaces up above in your
original match of the subject.  So we don't need the ` *' after the
caret that we also didn't need.

(No, that was not true with the earlier regex. See above.)

Btw, sed doesn't need an -e for just one expression - though it
doesn't hurt anything.

(I use it routinely because it's easy to forget later if you make
modifications to the sed script.)

My second cup of coffee has not helped me wake up enough to allow me to
have had light shed on what you're doing here exactly.  I see in general
terms, but don't follow your heuristic that requires munging the subject
both in the main recipe and in the "Else" (E-flag) recipe.  Maybe a
flow-chart on the back of a napkin would help - either you or me, or both
of us.  :-)  Basically, though, try to think through an algorithm that
only needs that mess once.  :-)
   ^^^^^^^^^^^^^^^^^^^^^^^^^
Agree with this.

I believe Eli the Bearded once posted a recipe which basically solved
this even for pathological cases -- I'd go to the archives for a
solution; this is by no means a new topic.

Hope this helps,

/* era */

--
 Too much to say to fit into this .signature anyway:
<http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition


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