rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | README | LICENSE

rpcountmail (3889B)


      1 #!/bin/sh
      2 #	$NetBSD: countmail,v 1.5 2002/07/02 17:18:21 mycroft Exp $
      3 
      4 # Modified to fit rohrpost in 2011 by Christoph Lohmann <20h@r-36.net>.
      5 
      6 #
      7 # Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
      8 # All rights reserved.
      9 #
     10 # This code is derived from software contributed to The NetBSD Foundation
     11 # by Charles M. Hannum.
     12 #
     13 # Redistribution and use in source and binary forms, with or without
     14 # modification, are permitted provided that the following conditions
     15 # are met:
     16 # 1. Redistributions of source code must retain the above copyright
     17 #    notice, this list of conditions and the following disclaimer.
     18 # 2. Redistributions in binary form must reproduce the above copyright
     19 #    notice, this list of conditions and the following disclaimer in the
     20 #    documentation and/or other materials provided with the distribution.
     21 # 3. All advertising materials mentioning features or use of this software
     22 #    must display the following acknowledgement:
     23 #        This product includes software developed by the NetBSD
     24 #        Foundation, Inc. and its contributors.
     25 # 4. Neither the name of The NetBSD Foundation nor the names of its
     26 #    contributors may be used to endorse or promote products derived
     27 #    from this software without specific prior written permission.
     28 #
     29 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     30 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     31 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     32 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     33 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     34 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     35 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     36 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     37 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     38 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     39 # POSSIBILITY OF SUCH DAMAGE.
     40 #
     41 
     42 # Count the messages in your mailbox, using only POSIX shell builtins.
     43 #
     44 # Caveats:
     45 #
     46 # The read loop is horrendously slow on every implementation I've
     47 # tried.  I suggest using from(1) and wc(1) instead, though these are
     48 # not shell builtins.
     49 
     50 # for krb.
     51 #set -- `from -t`
     52 #v=$3
     53 #set -- `from | wc -l`
     54 #v=$1
     55 #v=`from | wc -l`
     56 v=$(rpstats -a)
     57 
     58 #v=0
     59 #exec 0</var/mail/$USER
     60 #while read line; do
     61 #  case "$line" in
     62 #    "From "*) v=$(($v + 1)) ;;
     63 #  esac
     64 #done
     65 #exec 0<&-
     66 
     67 set --
     68 g=0
     69 v=000$v
     70 
     71 while :; do
     72 
     73   case $v in
     74     '' | 0 | 00) break ;;
     75     *000) ;;
     76     *)
     77       case $g in
     78 	0) x= ;;
     79 	1) x=THOUSAND ;;
     80 	2) x=MILLION ;;
     81 	3) x=BILLION ;;
     82 	4) x=TRILLION ;;
     83 	5) x=QUADRILLION ;;
     84 	6) x=QUINTILLION ;;
     85 	7) x=SEXTILLION ;;
     86 	8) x=SEPTILLION ;;
     87 	*)
     88 	  echo "YOU HAVE TOO MUCH MAIL!" 1>&2
     89 	  exit 1
     90 	  ;;
     91       esac
     92 
     93       case $v in
     94 	*10) y=TEN ;;
     95 	*11) y=ELEVEN ;;
     96 	*12) y=TWELVE ;;
     97 	*13) y=THIRTEEN ;;
     98 	*14) y=FOURTEEN ;;
     99 	*15) y=FIFTEEN ;;
    100 	*16) y=SIXTEEN ;;
    101 	*17) y=SEVENTEEN ;;
    102 	*18) y=EIGHTEEN ;;
    103 	*19) y=NINETEEN ;;
    104 	*2?) y=TWENTY ;;
    105 	*3?) y=THIRTY ;;
    106 	*4?) y=FORTY ;;
    107 	*5?) y=FIFTY ;;
    108 	*6?) y=SIXTY ;;
    109 	*7?) y=SEVENTY ;;
    110 	*8?) y=EIGHTY ;;
    111 	*9?) y=NINETY ;;
    112 	*) y= ;;
    113       esac
    114 
    115       case $v in
    116 	*[01]? | *?0) ;;
    117 	*) y=$y- ;;
    118       esac
    119 
    120       case $v in
    121 	*1?) ;;
    122 	*1) y=${y}ONE ;;
    123 	*2) y=${y}TWO ;;
    124 	*3) y=${y}THREE ;;
    125 	*4) y=${y}FOUR ;;
    126 	*5) y=${y}FIVE ;;
    127 	*6) y=${y}SIX ;;
    128 	*7) y=${y}SEVEN ;;
    129 	*8) y=${y}EIGHT ;;
    130 	*9) y=${y}NINE ;;
    131       esac
    132 
    133       case $v in
    134 	*1??) z=ONE ;;
    135 	*2??) z=TWO ;;
    136 	*3??) z=THREE ;;
    137 	*4??) z=FOUR ;;
    138 	*5??) z=FIVE ;;
    139 	*6??) z=SIX ;;
    140 	*7??) z=SEVEN ;;
    141 	*8??) z=EIGHT ;;
    142 	*9??) z=NINE ;;
    143 	*) z= ;;
    144       esac
    145 
    146       set $z ${z:+HUNDRED} $y $x $*
    147       ;;
    148   esac
    149 
    150   g=$(($g + 1))
    151   v=${v%%???}
    152 
    153 done
    154 
    155 p=S
    156 
    157 case "$*" in
    158   "") set ZERO ;;
    159   ONE) p= ;;
    160 esac
    161 
    162 echo "$*!
    163 
    164 $* MAIL MESSAGE$p!
    165 
    166 HAHAHAHAHA!"