procmail
[Top] [All Lists]

Re: Counting lines

2000-02-28 23:42:14
On 28 February 2000, Andrew Edelstein <andrew(_at_)infonent(_dot_)com> wrote:
On Sat, Feb 26, 2000 at 04:40:38AM +0200, Liviu Daia wrote:
However, they both expect a message produced by

    mail daia </dev/null

to have a "Lines: 0", and one sent with

    echo | mail daia

to have a "Lines: 1", while the recipe above produces "Lines: 1"
and "Lines: 2" respectively.  If Procmail is counting the header
separator, this didn't use to happen before, as David pointed out.

I read this and began experimenting. Using the above two commands,
and the followin recipe, I got what you got: /dev/null produced
"Lines: 1", while echo produced "Lines: 2", and delivered to my inbox.

:0 Bf
* 1^1  ^.*$
|/usr/bin/formail -A "Lines: $="

    You didn't, with your recipe I get "Lines: 2" and "Lines: 3"
respectively.  As it turned out, that's because my MTA adds a trailing
newline when piping to external commands.

    As for why you get 1 and 2 instead of 0 and 1, you're counting the
putative newlines --- see David Tamkin's excellent explanation earlier
in this thread.

However, with this recipe:

:0 B
*  1^1  ^.*$
{
        :0f
        |/usr/bin/formail -A "Lines: $="

        :0
        /home/andrew/testing
}

Both commands produced "Lines: 0" and delivered to my testing box.
I'm at a loss to explain why they should produce different output.

    According to "man 5 procmailsc":

:MISCELLANEOUS
:       You can query the final score of all the conditions  on  a
:       recipe from the environment variable $=.  This variable is
:       set every time just after procmail has parsed  all  condi­
:       tions  on  a  recipe (even if the recipe is not being exe­
:       cuted).

    The score is re-evaluated in the inner recipes.  Since you have no
rules that affect the score in the inner recipes you'll always get 0, no
matter what message you feed to Procmail.

I also noticed that if I tried
|/usr/bin/formail -A "Lines: $=" >> /home/andrew/mail/testing

I got "Lines: $=" (a literal "$=") header, instead of a count of the
number of lines. This is why I began experimenting with the latter
recipe above.  Thoughts? Explanations? "Alms for a poor wretched
procmail beginner?" :)

    I don't know, I suppose this one is a bug.  Philip?

    Regards,

    Liviu Daia

-- 
Dr. Liviu Daia               e-mail:   Liviu(_dot_)Daia(_at_)imar(_dot_)ro
Institute of Mathematics     web page: http://www.imar.ro/~daia
of the Romanian Academy      PGP key:  http://www.imar.ro/~daia/daia.asc

<Prev in Thread] Current Thread [Next in Thread>