Hi,
Thanks for the response and tutorial. I'm learning
a lot, but there's still one thing unresolved...
On Tue, 4 Feb 1997, David W. Tamkin wrote:
| I'd like to count the '@' signs in the header fields, and use
| the results in a score. I've asked this question before, and
| appreciate the help, but previous responses posted here can't do
| this with internal egrep, they only count the number of LINES
| with '@' in them, which is not enough.
Those responses were wrong, Ken, or perhaps you misunderstood them.
Procmail's internal egrep most certainly can count the @-signs.
They were wrong. The original contained:
* 1^0 ^(Resent-)?To:
* 1^1 ^(Resent-)?To:.*,
* 1^0 ^(Resent-)?Cc:
* 1^1 ^(Resent-)?Cc:.*,
To count commas. The left anchor botched the rule. I just assumed
that the internal egrep only counted lines after playing with it
a little.
That still leaves a problem with the internal Egrep, and that's counting
commas or '@'s in ONE FIELD. (Actually two fields, To: and Cc:) To do
that, I'll still have to resort to an external program like countat. One
might extract a field using formail first, but that still means
launching another external prog!
| According to the procmail manual, I should be able to run
| an external program and use the return code as a score
| if I "negate" it. It gives no examples (that I can find).
That is true, but you coded it incorrectly.
Yes, I knew that, :) but there was no example or grammar given! :O
That's why I turned to you all... :(
| I've tried:
|
| :0 h c
| * -15^0
| * !? /usr/kmarsh/bin/countat
Er, no. The weights and the condition have to be on the same line, as
Lars Kellogg-Stedman explained. The way you have it now, it says this:
Is there anywhere in the manual pages that I was supposed to divine
this syntax? I'll admit guilt if it's in there somewhere...
By the way, "h" is meaningless on a recipe whose action line is to launch
a brace nest. If you want any or all recipes inside the braces to act only
on the head, they need their own h's: flags are not inherited.
The procmailrc man page says that the "H" flag means to egrep only
the header. Since I didn't want the rule acting on the body, and
I had started with the internal egrep, I had the H flag. The body
might have a bunch of @'s in it that I don't want to count.
By another way, if you have a $HOME/bin directory, you probably call a lot
of executables from it and ought to add it to your procmailrc's PATH.
Thanks, I simplified the rule greatly for this example. I use variables
for paths and such. :)
| :0 h c
| * -15^0
| * -? /usr/kmarsh/bin/countat
"-?" is illegal syntax.
As I quickly discovered.
Now, if you really want to count all @-signs in the head and allow for
fifteen legit ones (From:, Message-Id:, a few Received:), here's how
you code it without outside programs:
:0c # Are you sure you want a clone here?
* 1^1 @
* -15^0
{
whatever you had in the braces
}
Wow, so achingly simple... :) Of course, I had to go and write C code...
But wait, it still doesn't allow me to count @'s (or commas) within one
particular header line.
Note that that counts @-signs, not lines with @-signs. If you actually had
wanted to count lines with @-signs you could have done that this way:
* 1^1 ^(_dot_)*(_at_)(_dot_)*$
OK, but can I make sure that it only counts @'s in the header? You
deprecated by use of H, but I think I'll need it to prevent counting
@'s in Mime attachments, for example.
Thanks for the help!
Ken.
-------------------------------------------------------------------------
Mail: kmarsh(_at_)charm(_dot_)net | Edit a binary .INI file, then
tell
WWW: http://www.charm.net/~kmarsh | me that UNIX is too complicated.
-------------------------------------------------------------------------