procmail
[Top] [All Lists]

Re: Removing [somelist] from subject lines

2001-01-23 17:35:46
Mike A. Harris wrote:
:0:
* ^X-BeenThere:(_dot_)*xpert(_at_)XFree86(_dot_)Org
XPERT-XFREE
...
And if it's there, you probably can count on it to have a fixed
number of spaces/tabs after the colon, so you should be able to
use that instead of ".*".

I'm not too worried about other lists matching this as it is
extremely unlikely.

Sure, actually I was rather thinking of efficiency. If you tell
procmail there's, say, exactly one space, it doesn't have to check
any further as soon as it's found there's none or more than one.

The "." could be changed to "\." though, but again, unlikely to ever
matter....

Likewise.

  :0hf
  * ^Subject:.*\[Xpert\]
  | sed 's/\[Xpert\] //'
...
looking at the above, sed would
change all occurrences of [Xpert] in the entire header the way it
is there no?

No, that would only happen if you had "g" after the last slash in the
sed script. The way you have it here only the first occurrence is
replaced.

Should change to:
sed -e 's/^Subject:(.*)\[Xpert\](.*)/Subject: \1\2/'

Which is perlish syntax..  Does sed support it?  I don't want to
use perl as it is a hog for this...

You'd need \( and \) there (and the space after the second "Subject:"
shouldn't be there), but as I said above, the change isn't necessary
anyway.

I just tested sed on the commandline and if you do not put \[, it
will treat [ as a regex metacharacter.

Yes, but its closing companion is safe without a backslash.

If there is a way of avoiding the fork/exec of sed using procmail
magic, I'd like to try if it speeds the thing up, but it isn't
extremely critical to me.

Well, Dallman and David already showed how to use formail instead if
you don't want sed; I'm afraid procmail alone can't do that, though.

The "* ^Subject..." line does now seem redundant since sed is only
getting the header, and there should only be on "Subject" line in
the header.  The /g on sed would catch 2 even if it were legal
anyways.

No, the "g" means something else: it tells sed to replace all
occurrences (not only the first) in any given line of the input. It
doesn't have any influence on what happens there are matches in
several lines. Your original recipe would already remove the first
occurrence of "[Xpert]" from all "Subject:" lines, even though it has
no "g".

The other thing is, what if more than one [Xpert] appears in the
subject?  I'd like to silence all of them.  So would the
/g take care of that, or would I have to resort to more trickery?

Ah, there we are - yup, that's what the "g" is for.

Is the last part necessary, or can I take out the :0: and move
XPERT-XFREE up?  Combining these two things would give:

:0
* ^X-BeenThere:(_dot_)*xpert(_at_)XFree86\(_dot_)Org
{
    :0 hfw
    | sed -e 's/\(^Subject:.*\)\[Xpert\]\(.*\)/\1\2/g'
    XPERT-XFREE
}

Or am I sniffing glue?

Glue, definitely. :-) You can't have two actions like this in a single
recipe. (And BTW, if you could, you wouldn't even need the braces any
longer in this case, one single recipe would do.)

OTOH, you could write sed's output to the mail folder directly, like
this:

:0 w:
| sed -e 's/\[Xpert]//g' >>XPERT-X-FREE

You'd have to pipe the entire message through sed then, though (that's
why the "h" flag has disappeared), because otherwise the body would be
missing from the output; if it contains a "Subject:" line embedded in
the body (and unquoted), that would also get changed - hm, but maybe
that would be exactly what you want?

Question to the experts: Is the "w" flag ok there? I.e., if sed fails,
will the unchanged message be written to the folder?

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