procmail
[Top] [All Lists]

Re: Condition with BODY length?

1997-07-22 21:05:00
Mitsuru Furukawa <furu(_at_)009(_dot_)com> writes:
Is there any way I can control execution of action line with length of BODY?

Yes.  Look up the '>' and '<' special conditions, as described in the
procmailrc(5) manpage.


What I want to do is to 
split BODY into less-than-100-char chunks and forward them to pager.
And I certainly do not want to send out empty messages.

While this _is_ doable using a recursive INCLUDERC, it's a lot easier
to do with perl:

        :0 bw
        |forward_to_pager

Where forward_to_pager contains:

        #!/usr/local/bin/perl
        # ...or whereever
        undef $/;
        $_ = <>;
        s/\n/ /g;
        while(length($_)) {
            open(PAGER, "|pager -with -any -needed -args") or die "fork: $!";
            print substr($_, 0, 100), "\n";
            close(PAGER) or die "exec or write: $!";
            substr($_, 0, 100) = '';
        }


To comment on the recipes you did include:

   :0bfw
   | perl -pe 's/\n/ /g'

tr would probably be more efficient.

   :0bc
   BODYLEN=|formail -I ""|wc -m 

Since you're only feeding the body in to the action, the formail call
is unnecesary.  I just tried various recipes and the fastest one I
could find is:

        :0
        * B ?? 1^1 > 1
        { }
        BODYLEN = $=

Note that the 'B' and 'H' flags don't affect length conditions.


Philip Guenther