1  #!/u/bin/bsh -p
  2
  3  Hosts='
  4  pop.t-online.de . "."^M
  5  pop.t-online.de x "."^M
  6  '"$KUNDENSERVER"'^M
  7  pop.gmx.net . "."^M
  8  pop.gmx.net u "."^M
  9  '
 10  Cols=090
 11
 12
 13  Help='^M
 14   I holt nur die Anzahl und ByteSumme^M
 15   i holt die komplette Info-Liste^M
 16   ^M
 17   Versteckte Menü-Punkte:^M
 18    help^M
 19    H host (pop.t-online.de)^M
 20    H ? {Host-Liste; siehe Hosts='' im Script}^M
 21    H n {Selektiert Host/User/Pass n}^M
 22    U user (.)^M
 23    P pass (.)^M
 24    q quiet^M
 25    B bodylines (0)^M
 26    C columns (80)^M
 27    All^M
 28    ed (Unix:vi, Win:notepad)^M
 29   (Voreinstellungen)^M
 30  '
 31
 32  [ $# -eq 1 ] &&
 33     expr "$1" :: '[?/]' &|
 34     expr "$1" :: '^-[hH]' && {
 35   echo " pop.bsh^M
 36   pop.bsh Host^M
 37   pop.bsh Host User^M
 38   pop.bsh Host User 'Password'^M
 39   $Help"
 40   exit
 41  }
 42
 43  set -f
 44
 45  set Z:.1200
 46  set Subj:.512
 47  set From:.512
 48  #Tmp=/tmp/bsh_pop3
 49  mktemp Tmp
 50  echo "$Tmp"
 51  Nmax=00000
 52  Body='       '
 53  Q=1
 54  Trans=0000000
 55  Size=0000000000
 56
 57  [ $# -gt 0 -a "$1" != '-a' ] && Host="$1" shift
 58  [ $# -gt 0 -a "$1" != '-a' ] && User="$2" shift
 59  [ $# -gt 0 -a "$1" != '-a' ] && Pass="$3" shift
 60  ifset Host || Host="pop.t-online.de"
 61  ifset User || User=.
 62  ifset Pass || Pass=.
 63
 64
 65  # hostname
 66  Hostaddr()  {
 67     IP="???.???.???.???"
 68     [ $# -ne 1 ] && return 1
 69     hostaddr "$1" | {
 70        [ $? -ne 0 ] && return 2
 71        while readl Z
 72        do
 73           [ Q -eq 0 ] && catv Z /%j
 74           expr "$Z" :IP '^addr: %([0-9.]%{7,15}%)' && break
 75        done
 76     }
 77     expr "$IP" :: '^[0-9.]%{7,15}$' || return 3
 78     return 0
 79  }
 80  Hostaddr $Host || { print -u2 "'$Host'?!"; exit 1; }
 81
 82
 83  # ? | n
 84  Hosts()  {
 85     local n=000
 86     catv Hosts | {
 87        while readl Z
 88        do
 89           expr "$Z" :: '[a-zA-Z0-9.-]%{4,}' || continue
 90           let ++n
 91           [ "$1" == '?' ] && { catv /%t n '.: ' Z /%j; continue; }
 92           let "$1!=n" && continue
 93           expr "$Z" :Host '%([^ %t]%{4,}%)' || break
 94           expr "$Z" :User '[^ %t]%{4,}[ %t]%{1,}%([^ %t]%{1,}%)' || break
 95           expr "$Z" :Pass '[ %t]"%(.%{1,}%)"[ %t]*$'
 96           break
 97        done
 98     }
 99     return 0
100  }
101
102
103  #file n id
104  #Zapp()  {
105  #   local n=0000
106  #   cat $1 | {
107  #      > $1
108  #      while readl Z
109  #      do
110  #         expr "$Z" :n '%([0-9]%{1,}%)' || { catv Z /%n; continue; }
111  #         let "n!=$2" && { catv Z /%n; continue; }
112  #         catv Z ". $3" /%n
113  #      done
114  #      ><
115  #   }
116  #   return 0
117  #}
118
119
120  # [-s]
121  Holen()  {
122     local c=unknown n=00000 m=- t:9.1
123     Trans=0
124     3> "$Tmp"
125     pop3 $1 $Body $IP "$User" "$Pass" | {
126        while readl Z
127        do
128           #ifset Z && conv '-d^M' Z
129           let "Trans+=${#Z}+2"
130           [ Q -eq 0 ] && catv $Cols,Z /%j
131           case "$Z" in
132             QUIT|STAT|LIST|UIDL)
133                           c="$Z" conv -l c; continue;;
134             TOP% [0-9]*)  c=topn m=- expr "$Z" :n '%([0-9]%{1,}%)'
135                           [ Q -gt 0 ] && let 'n%25==0' && prints su2s6s- T "$n" "^M"
136                           continue;;
137           esac
138           case "$c" in
139             stat)  expr "$Z" :Nmax '%([0-9]%{1,}%)  *[0-9]%{1,}'
140                    expr "$Z" :Size '[0-9]%{1,}  *%([0-9]%{1,}%)' ;;
141             list)  expr "$Z" :n '^ *%([0-9]%{1,}%)  *[0-9]%{1,} *$' ||
142                       continue
143                    [ n -le 0 ] && continue
144                    [ Q -gt 0 ] && let 'n%25==0' && prints su2s6s- L "$n" "^M"
145                    prints vs-20s-75s-2s-520s-520 Z "$Z" '' - '' ''
146                    catv Z /%r%n =$(([n-1]*[20+75+2+520+520+2])),,3
147                    continue
148             ;;
149             uidl)  expr "$Z" :n '^ *%([0-9]%{1,}%)  *[!-~]%{1,} *$' ||
150                       continue
151                    [ n -le 0 ] && continue
152                    expr "$Z" :Z '^ *[0-9]%{1,}  *%([!-~]%{1,}%) *$'
153                    [ Q -gt 0 ] && let 'n%25==0' && prints su2s6s- U "$n" "^M"
154                    prints vs-75 Z "$Z"
155                    catv Z =$(([n-1]*[20+75+2+520+520+2]+20)),,3
156                    continue
157             ;;
158             topn)  expr "$Z" =:Subj '^Subject: %(.*%)$' && continue
159                    expr "$Z" =:From '^From: %(..*%)$' && continue
160                    expr "$Z" =:: '^Content-Type: text/plain' && m=t continue
161                    expr "$Z" =:: '^Content-Type: text/html' && m=H continue
162                    expr "$Z" =:: '^Content-Type: multipart/' && m=M continue
163                    expr "$Z" :: '^.$' && { c=ende
164                       let 'n>0' && let '--n'
165                       conv "-t %`t${t}%`" Subj From
166                       prints vs-2s-520s-520 Z "$m" "$Subj" "$From"
167                       catv Z =$((n*[20+75+2+520+520+2]+20+75)),,3
168                       continue
169                    }
170             ;;
171                *)  : ;;
172           esac
173        done
174     }
175     ><
176     echo
177     [ -s "$Tmp" ] || return
178     cat "$Tmp" | tr -s ' ' ' ' > "$Tmp"
179     return 0
180  }
181
182
183
184  #{l|h}  a b c d-e
185  Loeschen()  {
186     [ $# -lt 2 -o Nmax -lt 1 ] && return 20
187     local lz=tHM- t=...... von=000000000 bis=000000000
188     local a:.25
189     expr "$*" :: '^[lh]  *[1-9][0-9 -]*$' && t=vb
190     [ "$t" != vb ] && {
191        t=''
192        for a in "$2" "$3"
193        do
194           expr "$a" :: '^[tHM-]%{1,4}$' && t="${t}mt"
195           expr "$a" :bis '^%.%([0-9]%{1,}%)$' && t="${t}sz" von=0
196           expr "$a" :von '^%([0-9]%{1,}%)%.$' && t="${t}sz" bis=100000000
197           expr "$a" :: '^[0-9]%{1,}%.[0-9]%{1,}$' && t="${t}sz" &&
198              expr "$a" :von '^%([0-9]%{1,}%)' &&
199              expr "$a" :bis '%([0-9]%{1,}%)$'
200        done
201     }
202     case "$t" in
203       vb)  GetIDs vb $( MkNs $* ) | { nop && pop3 - $IP "$User" "$Pass"; }
204       ;;
205       mt)  [ "$1" == l ] && lz="$2"
206            [ "$1" == h ] && expr "$lz" :lz "[$2]" += ''
207            ifset lz || return 0
208            GetIDs mt $1 "$lz" | { nop && pop3 - $IP "$User" "$Pass"; }
209       ;;
210       sz)  GetIDs sz $1 $von $bis | { nop && pop3 - $IP "$User" "$Pass"; }
211       ;;
212       mtsz)
213            [ "$1" == l ] && lz="$2"
214            [ "$1" == h ] && expr "$lz" :lz "[$2]" += ''
215            GetIDs ts $1 $von $bis "$lz" | { nop && pop3 - $IP "$User" "$Pass"; }
216       ;;
217       szmt)
218            [ "$1" == l ] && lz="$3"
219            [ "$1" == h ] && expr "$lz" :lz "[$3]" += ''
220            GetIDs ts $1 $von $bis "$lz" | { nop && pop3 - $IP "$User" "$Pass"; }
221       ;;
222        *)  return 21 ;;
223     esac
224     Nmax=? Size=? Trans=?
225     return 0
226  }
227
228
229  #{l|h}  a b c d-e
230  MkNs()  {
231     [ $# -lt 2 ] && return 1
232     local n:010 nm=00000 nmax=$Nmax lh=$1
233     shift
234     let 'nmax>0' || return 1
235     if [ "$lh" == l ]
236     then
237        for n in $*
238        do
239           expr "$n" :: '-' || { echo "$n"; continue; }
240           expr "$n" :n '-' = ' to ' || continue
241           for n from $n repeat
242           do  echo "$n";  done
243        done
244     else
245        for nm from 1 to $nmax repeat
246        do
247           for n in $*
248           do
249              expr "$n" :: '-' || { let 'n==nm' && continue 2; continue; }
250              expr "$n" :n '-' = ' to ' || continue
251              for n from $n repeat
252              do
253                 let 'n==nm' && continue 3
254              done
255           done
256           echo "$nm"
257        done
258     fi
259     return 0
260  }
261
262
263  # id ...
264  GetIDs()  {
265     [ $# -gt 1 ] || { print -u2 narg le 0; return 1; }
266     [ -s "$Tmp" ] || { print -u2 TmpSz eq 0; return 2; }
267     local r=1 t=.. s=000000000 a:.20 id:.70
268     [ $2 == l ] && a="s>=$3 && s<=$4"
269     [ $2 == h ] && a="s<$3 || s>$4"
270     < "$Tmp"
271     case "$1" in
272       vb)  shift
273            while read s - id - - -
274            do
275               expr " $* " :: "[ %t]${s}[ %t]" && r=0 catv id /%n
276            done
277       ;;
278       mt)  while read - - id t - -
279            do
280               expr "$3" :: "$t" && r=0 catv id /%n
281            done
282       ;;
283       sz)  while read - s id - - -
284            do
285               expr "$s" :: '[^0-9]' && continue
286               let "$a" && r=0 catv id /%n
287            done
288       ;;
289       ts)  while read - s id t - -
290            do
291               expr "$s" :: '[^0-9]' && continue
292               expr "$5" :: "$t" && let "$a" && r=0 catv id /%n
293            done
294       ;;
295     esac
296     ><
297     return $r
298  }
299
300
301  Show()  {
302     [ -s "$Tmp" ] || return 1
303     local n=00000 sz:010 m=-
304     local ls=30 lf=29
305     let 'Cols>80' && let 'lf+=(Cols-80)/2' 'ls+=Cols-80-(lf-29)'
306     < "$Tmp"
307     while read n sz - m Subj From
308     do
309        conv '-t` ' Subj From
310        prints s5bs9bsbs-${ls}bss-${lf} $n $sz $m "$Subj" ' ' "$From"
311     done
312     ><
313     return 0
314  }
315
316
317  # [-a]
318  MainSwitch()  {
319     case "$Opt" in
320       i)  Holen
321           [ "$1" != '--a' ] && Show ;;
322       I)  Holen -s ;;
323       l|h)
324           ifset Arg || return 0
325           [ "$Opt" == l -a "$Arg" == '*' ] && Arg="1-$Nmax"
326           Loeschen $Opt $Arg || echo ERROR$?: Args? Info-Liste?
327           ;;
328       All)
329           read "Arg? Alles Löschen?[jJyY]: "
330           expr "$Arg" :: '^[jJyY]$' || return 0
331           pop3 -A $IP "$User" "$Pass" ;;
332       U)  User="$Arg" ;;
333       P)  Pass="$Arg" ;;
334       B)  Q=0 Body=-b$Arg ;;
335       C)  Cols="$Arg"
336           let 'Cols<80' && Cols=80 ;;
337       H)  L_ip=$IP
338           ifset Arg || Arg=pop.t-online.de
339           [ "$Arg" == '?' ] && { Hosts '?'; return 0; }
340           expr "$Arg" :: '^[0-9]%{1,2}$' && { Hosts $Arg; Arg="$Host"; }
341           Hostaddr $Arg && Host="$Arg" return 0
342           IP=$L_ip print -u2 "'$Arg'?!"
343           ;;
344       help)
345           print -rn "$Help" ;;
346       q)  let "Q^=1" ;;
347       ed)
348           [ `ver s` == dos32 ] && notepad "$Tmp"
349           [ `ver s` == unix ] && vi "$Tmp"
350           read "-? <Enter> "
351           ;;
352       E)  return 1;;
353       *)  return 0;;
354     esac
355     return 0
356  }
357
358
359
360  L_ip=000000000000000
361  L_ip=$IP
362  Nmax=? Size=? Trans=?
363
364
365  [ "$1" == '-a' ] && {
366     [ $# -lt 3 ] && { remove -s "$Tmp"; exit 0; }
367     Opt=I MainSwitch -a
368     let "Nmax>1&&Size>500000" && Opt=i MainSwitch -a &&
369     let "Nmax>1&&Size>500000" && Opt="$2" Arg="$3 $4" MainSwitch -a
370     remove -s "$Tmp"
371     exit 0
372  }
373
374
375  while prints sf_$Cols
376        echo "   $IP  $Host  $User '$Pass'  n=$Nmax b=$Size t=$Trans  q=$Q
377     Info-Liste holen :  i | I
378             Loeschen :  l  {n|v-b}... | * | tHM- | {min.max|min.|.max}
379               Halten :  h  {n|v-b}... |     tHM- | {min.max|min.|.max}
380              Beenden :  E
381                         _%b%c"
382  do
383     read Opt Arg
384     MainSwitch || break
385  done
386
387
388  remove -s "$Tmp"
389  exit 0
390
391
392