procmail
[Top] [All Lists]

Re^2: Condition with BODY length?

1997-07-22 22:27:00

Thanks for the valuable suggestions and codes.

Philip Guenther <guenther(_at_)gac(_dot_)edu> wrote:

<snip>

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

Frankly, I need to study perl little bit more to understand this.
So meanwhile could you comment on my version of recipe below?
It works fine in one-byte world, but not in my two-byte world emails.
I need to figure out some way to avoid cutting two-byte char 
in the middle. Any idea?
I heard substr in jperl does not support two-byte char but split does.
Anyway, I prefer to solve it using "domestic" perl by
probably comparing the last byte with char-code-range and ......

-----
# split body of mail into 100 byte(actually 96 to leave 4 for SEQ) files
# THIS WORKS FINE IN ONE-BYTE WORLD!!!!!!!!!!!!!!
# use sh control flow with external files

   YMDHMSP=`date "+%y%m%d.%H%M%S.$$"`
   :0bfw         # remove empty lines, leading whitespace, quoted lines
   | sed -e '/^[        ]*$/d' -e 's/^[         ]*//' \
   -e '/^[      ]*>.*$/d'
   :0bfw         # more efficient to use tr > THANKS TO PHILIP.
    | perl -pe 's/\n/ /g' 
   :0bcw
   | split -b96 - $YMDHMSP
   SPLITFILES=`ls -1 $YMDHMSP*`
   COUNT=`echo $SPLITFILES | wc -w`
   :0
   * $ ? test -f $SPLITFILES
   | i=1 ;\
     for file in $SPLITFILES; do \
        (echo "Subject: paging from splitcharloop.rc [$i/$COUNT]" ; \
         echo "To: mynumber(_at_)pager(_dot_)domain" ; \
         echo "From: furu(_at_)009(_dot_)com" ; \
         echo "Cc: furu(_at_)009(_dot_)com" ; \
         echo "X-Loop: furu(_at_)009(_dot_)com" ; \
         echo "$i>" ; cat "$file" ; \
         ) | $SENDMAIL -oi -t ; \
         i=`expr $i + 1` ; \
     done ; \
     rm -f "$YMDHMSP"*
-----

<snip>

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

I understand condition line such as * 1^1 . counts up length of search area.
But I do not understand how 1^1 > 1 counts up length.
Or is it B which puts length value in $= ?
Could you explain?
TIA.

_/_/_/      Mitsuru FURUKAWA      _/_/_/
_/_/_/        Tokyo, Japan        _/_/_/
_/_/_/     mailto:furu(_at_)009(_dot_)com    _/_/_/
_/_/_/  http://www.009.com/furu/  _/_/_/