tomcat(_at_)visi(_dot_)com wrote:
A suggestion I liked concerning my script was to
use sed to change the subject line, specifically
:0fhw
* ^TO_gatekeeper\+[0-9]+@
* ^Subject: *re:.*@
* Any.other.conditions.you.need??
| sed -e '/^Subject:/s/\*-.*$//'
I think I understand what sed is used for, and that
it uses regular expressions like procmail (??)
"like" here means "similar to" -- but the regexes are not quite
interchangeable. Procmail handles extended regexes, and ignores case
by default; sed handles a more limited set and I believe there's no
way to make it case-insensitive.
I don't think i have this line down 100%, here in my
own code is what I think it happening:
The subject line in the header is
"Subject: Re: MailWeb: Test A +-bozo(_at_)bozo(_dot_)com"
:0fwic
* ^Subject:[ ]+\/.*
| ( sed -e '/^Subject:/s/\*-.*$//' ; \
formail -rkb -I "From: $REALSENDER" -I "To: $ORIGINATOR" \
-I "Return-Path:$REALSENDER" -I "Sender:$REALSENDER" \
-I "Reply-To: $REALSENDER") \
| $SENDMAIL -oi $ORIGINATOR
The recipe :0
f consider the pipe as a filter
the word "filter" in the manpage doesn't mean what you seem to think
it means. What the 'f' flag means is:
Feed the message to the pipe
Replace the contents of the message by the the pipe's stdout
Continue processing!
I believe the 'c' flag is meaningless in the presence of 'f'.
w tells Procmail to hang around and wait for the script to
finish.
c operate on a copy (a copy of every email is saved in a dir)
i ignore write errors
sed -e '/^Subject:/s/\*-.*$//'
dont need the -e option?
Correct, but I'd leave it there so if you add something later, you
don't have to add another "-e" for the existing command.
/^Subject:/ match this
s sed substitution flag
/\ extract
substitute anything starting with "*-" followed by
anything any number of times up to the end of the line
with // or with nothing. Seems right to me.
You enter the recipe, change the subject line, do formail
then do sendmail. The above corrupts my mailbox.
Right.
Is this
syntax better?
:0fwci
* ^Subject:[ ]+\/.*
| sed -e '/^Subject:/s/\*-.*$//' ; \
| (formail -rkb -I "From: $REALSENDER" -I "To: $ORIGINATOR" \
-I "Return-Path:$REALSENDER" -I "Sender:$REALSENDER" \
-I "Reply-To: $REALSENDER") \
| $SENDMAIL -oi $ORIGINATOR
Uh, no.
First, a question: Does your subject contain "*-" or "+-"? Your line
above shows "+-" but the recipe is testing for "*-" -- I'll assume
"*-" is correct. This might be OK (but is UNTESTED)
1 :0 wci
2 * ^Subject:[ ]+
3 | sed -e '/^Subject:/s/\*-.*$//' \
4 | formail -rkb -I "From: $REALSENDER" -I "To: $ORIGINATOR" \
5 -I "Return-Path:$REALSENDER" -I "Sender:$REALSENDER" \
6 -I "Reply-To: $REALSENDER" \
7 | $SENDMAIL -oi $ORIGINATOR
Differences from the above:
line 1: No 'f' flag
line 2: deleted \/.* since you don't use $MATCH later
line 3: no semicolon, since you want to pass the thing through sed and
then through formail. But oops, any line containing
"Subject: <anything>*-<anything>" in the message BODY will
also get modified! Probably should fix this.
lines 4,6: removed parens, which serve no useful purpose
OK, to repair the "Subject:-in-message-body" problem, this might work
better (also UNTESTED):
1 :0c
2 * ^Subject:.*\*-
3 {
4 :0h
5 NewSubj=| formail -czXSubject: | head -1 | sed -e 's/\*-.*$//'
6
7 :0 fhw
8 | formail "-I$NewSubj"
9
10 :0 aw
11 | formail -rkb -I "From: $REALSENDER" -I "To: $ORIGINATOR" \
12 -I "Return-Path:$REALSENDER" -I "Sender:$REALSENDER" \
13 -I "Reply-To: $REALSENDER" \
14 | $SENDMAIL -oi $ORIGINATOR
15
16 LOG="Ouch! Trouble forwarding from $REALSENDER to $ORIGINATOR
17 "
18 :0
19 /dev/null
20 }
Line 1: the entire block operates on a copy
Line 2: explicitly check (in header only!) for ^subject: followed by
anything, followed by the literal character '*' followed by
'-'
lines 4-5: assign to NewSubj a massaged version of the first
"Subject:" field in the message. The 'h' flag in line 4
guarantees we will look for fields in the header
lines 7-8: replace existing subject with $NewSubj. Here we need the
'f' flag in line 7 because we want to modify the message
and continue processing. 'h' in line 7 means "only modify
the header"
line 10: the 'a' flag means "Only do this if line 8 executed
successfully"
lines 11-14: your recipe untouched
lines 16-17: put something in the log if we had any kind of problem
lines 18-19: if any error occurred, dump the copy
--
Neither I nor my employer will accept any liability for any problems
or consequential loss caused by relying on this information. Sorry.
Collin Park Not a statement of my employer.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail