-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathii-bb.sh
executable file
·183 lines (161 loc) · 3.07 KB
/
ii-bb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/busybox sh
# ii-клиент на чистом busybox
loader="wget -q -O -"
node="http://ii-net.tk/ii/ii-point.php?q="
authstr="your_authstr"
echolist="test.15 ii.test.14"
editor="vi"
indexdir="./echo"
msgdir="./msg"
unsentdir="./toss"
outdir="./out"
index="$node/u/e"
msg="$node/m"
point="$node/u/point"
mkdir -p $indexdir
mkdir -p $msgdir
mkdir -p $unsentdir
mkdir -p $outdir
view() {
if [ "$2" = "" ]
then
echoarea="`cat $indexdir/$1`"
for msgid in $echoarea
do
echo "N=$i; id=$msgid;"
cat $msgdir/$msgid
echo ""
i=$(($i+1))
done
else
filesize=$((`stat $indexdir/$1 -c %s`))
if [ "$2" = "len" ]
then
echo $(($filesize/21))
else
number=$(($2))
echoarea="`cat $indexdir/$1`"
i=0
for msgid in $echoarea
do
if [ $i -eq $number ]
then
echo "N=$i; id=$msgid;"
cat $msgdir/$msgid
fi
i=$(($i+1))
done
fi
fi
}
nch() {
echo "$1" | dd if=/dev/stdin bs=1 count=1 skip=$2 status=none
}
urlsafe_replace() {
text=$1
len=${#text}
i=0;
while [ $i -le $len ]
do
char=`nch $text $i`
if [ "$char" = "+" ]
then
echo -n "-"
elif [ "$char" = "/" ]
then
echo -n "_"
else
echo -n $char
fi
i=$(($i+1))
done
}
base64_urlsafe() {
src=`echo "$1" | base64`
for i in $src
do
urlsafe_replace $i
done
}
reparseSubj() {
str="`echo "$1" | dd if=/dev/stdin bs=1 count=3 status=none`"
if [ "$str" != "Re:" ]
then
echo -n "Re: "
fi
echo -n $1
}
fetch() {
for echoarea in $echolist
do
msglist_query="$index/$echoarea"
echo "fetch $msglist_query"
msglist=`$loader $msglist_query`
for i in $msglist
do
if [ "$i" = "$echoarea" ]
then
continue
fi
if [ -e "$msgdir/$i" ]
then
continue
fi
msg_query="$msg/$i"
echo "fetch $msg_query"
text=`$loader $msg_query`
echo "$text" > $msgdir/$i
echo "$i" >> $indexdir/$echoarea
done
done
}
write() {
echo=$1
if [ "$2" = "" ]
then
template="$echo\nAll\n...\n\n"
# не отвечаем, а пишем новое
else
echoarea="`cat $indexdir/$echo`"
count=$(($2))
i=0
for msgid in $echoarea
do
if [ $i -eq $count ]
then
msg="`cat $msgdir/$msgid`"
echo="`head -n 2 $msgdir/$msgid | tail -n 1 -`"
user="`head -n 4 $msgdir/$msgid | tail -n 1 -`"
subj="`head -n 7 $msgdir/$msgid | tail -n 1 -`"
subj="`reparseSubj "$subj"`"
template="$echo\n$user\n$subj\n\n@repto:$msgid\n"
fi
i=$(($i+1))
done
fi
filename="$unsentdir/`date -Iseconds`"
echo -e $template > $filename
$editor $filename
}
send() {
files=`ls -1 $unsentdir`
for file in $files
do
file_contents=`cat $unsentdir/$file`
b64=`base64_urlsafe "$file_contents"`
result="`$loader $point/$authstr/$b64`"
stat=`echo "$result" | dd if=/dev/stdin bs=1 count=6 status=none`
echo "$result"
if [ "$stat" = "msg ok" ]
then
mv $unsentdir/$file $outdir/$file
fi
done
}
case $1 in
"fetch") fetch;;
"view") view $2 $3;;
"write") write $2 $3;;
"send") send;;
"") echo -e "Usage:\n\nii-bb.sh view echoarea [number]\nii-bb.sh view echoarea len\nii-bb.sh write echoarea [number]\nii-bb.sh send\nii-bb.sh fetch";;
esac