scan.sh - rohrpost - A commandline mail client to change the world as we see it.
(HTM) git clone git://r-36.net/rohrpost
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
scan.sh (1454B)
---
1 #!/bin/bash
2
3 reset="$(tput sgr0)"
4 titleformat="$(tput bold)"
5 idformat="$(tput bold)"
6 dateformat="$(tput setaf 3)"
7 fromformat="$(tput setaf 7)"
8 subjectformat="$reset"
9
10 first=1
11
12 cols=$(tput cols)
13
14 while read -r line;
15 do
16 id=$(echo -n "$line" | cut -f 1)
17 date=$(echo -n "$line" | cut -f 2 | head -c 16)
18 from=$(utf8expr substr "$(echo -n "$line" | cut -f 3)" 1 10)
19 subject=$(echo -n "$line" | cut -f 4)
20
21 if [ $first -eq 1 ];
22 then
23 #printf "${titleformat}%8s %16s %10s %s\n" "$id" "$date" \
24 # "$from" "$subject"
25 first=0
26 else
27 ostr="$(printf "${dateformat}%10s${reset}" "$date")"
28 flen=$(($(utf8expr length "$date") + 2))
29 ostr="${ostr} $(printf "${fromformat}%10s${reset}" "$from")"
30 flen=$(($flen + 10 + 2))
31 ostr="${ostr} $(printf "${idformat}%s${reset}" "$id")"
32 flen=$(($flen + $(utf8expr length "$id") + 2))
33 scols=$(($cols - $flen))
34
35 printf "%s " "${ostr}"
36 slen=$(utf8expr length "$subject")
37 if [ $scols -lt 1 ] || [ $scols -gt $slen ];
38 then
39 printf "${subjectformat}%s${reset}\n" "$subject"
40 else
41 pos=1
42 while [ $slen -gt 0 ];
43 do
44 if [ $slen -gt $scols ];
45 then
46 sslen=$scols
47 else
48 sslen=$slen
49 fi
50
51 sstr=$(utf8expr substr "$subject" $pos \
52 $sslen | sed 's,^[[:space:]]*,,g')
53 if [ $pos -gt 1 ];
54 then
55 printf "%${flen}s" " "
56 fi
57 printf "${subjectformat}%s${reset}\n" \
58 "$sstr"
59
60 pos=$(($pos + $sslen))
61 slen=$(($slen - $sslen))
62 done
63 fi
64 fi
65 done
66