File: scmail-commands

package info (click to toggle)
scmail 1.3-4.1
  • links: PTS
  • area: main
  • in suites: bullseye, forky, sid, trixie
  • size: 592 kB
  • sloc: lisp: 1,535; sh: 178; makefile: 145
file content (268 lines) | stat: -rwxr-xr-x 7,948 bytes parent folder | download | duplicates (2)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#! /bin/sh

if test ! -d Mail -o ! -d Maildir; then
    echo "please prepare mailboxes"
    exit 1
fi

if test ! -d test.Mail -o ! -d test.Maildir; then
    echo "Please run scmail.scm test first."
    exit 1
fi

SCMAIL_REFILE="gosh -I. -I.. -l dummy-socket.scm ../scmail-refile"

check_nfiles() {
    if test `find $1  -type f -print |wc -l` != \
            `find $2 -type f -print |wc -l`; then
        echo "Number of files differs: $1 and $2"
        exit 1
    fi
}

scbayes_common() {
    task=$1
    config=$2
    shift
    shift

    echo -n "scbayes ${task}ing... "
    gosh -I.. ../scbayes -d $PWD/test.scmail -q -c $config $* --$task-spam spam
    gosh -I.. ../scbayes -d $PWD/test.scmail -q -c $config $* --$task-nonspam from.foo ml.test-ml-example-org
    echo "done."
}

scbayes_learn() {
    scbayes_common learn $*
}

scbayes_unlearn() {
    scbayes_common unlearn $*
}

scbayes_learn3() {
    for i in 1 2 3; do
        scbayes_learn $*
    done
}

scbayes_check() {
    if gosh -I.. ../scbayes -c $1  --check-spam spam; then
        echo "spam filtering succeeded"
    else
        echo "ERROR: spam filtering failed"
        exit 1
    fi
    gosh -I.. ../scbayes -c test.config --check-mail 5 || exit 1

    if gosh -I.. ../scbayes -c $1  --check-nonspam from.foo; then
        echo "nonspam filtering succeeded"
    else
        echo "ERROR: nonspam filtering failed"
        exit 1
    fi
    gosh -I.. ../scbayes -c test.config --check-mail 1 || exit 1
}

rm -f test.scmail-deliver
rm -rf test.Mail2 test.Maildir2
cp -rp Mail test.Mail2
cp -rp Maildir test.Maildir2
inode_before=`ls -i test.Maildir2/cur/1000000001.localhost:abc | awk '{print $1}'`
rm -rf test.scmail
mkdir test.scmail

rm -rf test.scmail
mkdir test.scmail

cat <<EOF > test.config
(
 :smtp-host "localhost"
 :log-file  "$PWD/test.scmail/log"
 :umask     #o007

 :token-table   "$PWD/test.scmail/token-table.dbm"
 :digest       "$PWD/test.scmail/digest.dbm"

 :size-limit 1024

 ;; for MH
 :mailbox   "$PWD/test.Mail2"
 :inbox     "inbox"
 :spam      "spam"   ; a folder for spam mails
 :mailbox-type  mh
 )
EOF

cat <<EOF > test.config2
(
 :smtp-host "localhost"
 :log-file  "$PWD/test.scmail/log"
 :umask     #o007

 :token-table   "$PWD/test.scmail/token-table.dbm"
 :digest       "$PWD/test.scmail/digest.dbm"

 :size-limit 1024

 ;; for Maildir
 :mailbox   "$PWD/test.Maildir2"
 :inbox     ""
 :spam      "spam"   ; a folder for spam mails
 :mailbox-type  maildir
 )
EOF

gosh -ugauche.test -e '(test-start "scmail-refile --dry-run")' -Eexit
$SCMAIL_REFILE -d $PWD/test.scmail -c test.config  -r test-rules -n |tee test.log.dryrun
diff -r Mail test.Mail2 || exit 1

$SCMAIL_REFILE -d $PWD/test.scmail -c test.config2  -r test-rules -n |tee test.log.dryrun2
diff -r Maildir test.Maildir2 || exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scmail-refile/scmail-deliver for MH")' -Eexit
$SCMAIL_REFILE -d $PWD/test.scmail -c test.config  -r test-rules |tee test.log.normal
diff -r test.Mail test.Mail2 || exit 1

# log files to stdout must be same
diff test.log.dryrun test.log.normal

# dry run
cat 5 | gosh -I.. ../scmail-deliver -d $PWD/test.scmail -c test.config -r test-rules -n >> test.scmail-deliver

# must be stored in test.Mail2/spam/3

cat 5 | gosh -I.. ../scmail-deliver -d $PWD/test.scmail -c test.config  -r test-rules

diff test.Mail2/spam/2 test.Mail2/spam/3 || exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scbayes for MH")' -Eexit

scbayes_learn3 test.config --force
scbayes_check test.config


# must be stored in test.Mail2/spam/4
echo '(add-bayesian-filter-rule!)' > test.test-rules
cat 4 | gosh -I .. ../scmail-deliver -d $PWD/test.scmail -c test.config  -r test.test-rules >> test.scmail-deliver
diff test.Mail2/spam/1 test.Mail2/spam/4 || exit 1


gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scmail-refile/scmail-deliver for Maildir")' -Eexit

rm -rf test.scmail
mkdir test.scmail

$SCMAIL_REFILE -d $PWD/test.scmail -c test.config2  -r test-rules | tee test.log.normal2
# log files to stdout must be same
diff test.log.dryrun2 test.log.normal2

check_nfiles test.Maildir test.Maildir2

# must be stored in spam folder.
cat 5 | gosh -I.. ../scmail-deliver -d $PWD/test.scmail -c test.config2  -r test-rules >> test.scmail-deliver

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scbayes for Maildir")' -Eexit

scbayes_learn3 test.config2 --force
scbayes_check test.config2

# must be stored in spam folder.
echo '(add-bayesian-filter-rule!)' > test.test-rules
cat 4 | gosh -I .. ../scmail-deliver -d $PWD/test.scmail -c test.config2  -r test.test-rules >> test.scmail-deliver

check_nfiles test.Mail2/spam test.Maildir2/spam

gosh -I.. ../scbayes -c test.config2 --table-stat > test.stat1

gosh -ugauche.test -e '(test-end)' -Eexit


gosh -ugauche.test -e '(test-start "scbayes --force")' -Eexit

# without --force, the token table must not be changed.
scbayes_learn test.config2
gosh -I.. ../scbayes -c test.config2 --table-stat > test.stat2
cmp test.stat1 test.stat2 || exit 1

# with --force, the token table must be changed.
scbayes_learn test.config2 --force
gosh -I.. ../scbayes -c test.config2 --table-stat > test.stat3
cmp test.stat1 test.stat3 > /dev/null && exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scbayes --unlearn-spam/nonspam")' -Eexit

rm -rf test.scmail
mkdir test.scmail

scbayes_learn test.config2
scbayes_unlearn test.config2
gosh -I.. ../scbayes -c test.config2 --table-stat > test.stat4

tail -n +2 test.stat4 > test.stat4.1
grep ' 0w/ .* 0m .* 0w/ .* 0m' test.stat4 > test.stat4.2
cmp test.stat4.1 test.stat4.2 || exit 1

# they must be empty
gosh -I.. ../scbayes -c test.config2 --dump-table > test.table
gosh -I.. ../scbayes -c test.config2 --dump-digest > test.digest
cmp test.table /dev/null || exit 1
cmp test.digest /dev/null || exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scmail-deliver: output must be empty")' -Eexit

# scmail-deliver must not output anything.
cmp test.scmail-deliver /dev/null || exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "scbayes --flush-interval")' -Eexit

scbayes_learn test.config2 --table test.table-1.dbm --digest test.digest-1.dbm
scbayes_learn test.config2 --flush-interval 1 --table test.table-2.dbm --digest test.digest-2.dbm

# they must have the same content.
gosh -I.. ../scbayes -c test.config2 --digest test.digest-1.dbm --dump-digest | sort | awk '{ print $ 1}' > test.digest-1
gosh -I.. ../scbayes -c test.config2 --digest test.digest-2.dbm --dump-digest | sort | awk '{ print $ 1}' > test.digest-2

gosh -I.. ../scbayes -c test.config2 --table test.table-1.dbm --dump-table | sort > test.table-1
gosh -I.. ../scbayes -c test.config2 --table test.table-2.dbm --dump-table | sort > test.table-2

cmp test.table-1 test.table-2 || exit 1
cmp test.digest-1 test.digest-2 || exit 1

gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "umask")' -Eexit
test `ls -ld test.Mail2/backup |awk '{print $1}'` = drwxr-x--- || exit 1
test `ls -l test.Mail2/backup/1 |awk '{print $1}'` = -rw-rw---- || exit 1
gosh -ugauche.test -e '(test-end)' -Eexit

gosh -ugauche.test -e '(test-start "maildir refile: sys-rename is used?")' -Eexit

inode_after=`ls -i test.Maildir2/from.foo/cur/1000000001.localhost:abc | awk '{print $1}'`

test "$inode_before" -a "$inode_before" = "$inode_after"
gosh -ugauche.test -e '(test-end)' -Eexit


gosh -ugauche.test -e '(test-start "scmail-deliver to Maildir/new")' -Eexit
cat 7 | gosh -I .. ../scmail-deliver -d $PWD/test.scmail -c test.config2  -r test.test-rules
file=`tail -1 test.scmail/log |perl -nle 'print $1 if /refile: \(stdin\) -> (new\/.*)$/'`
diff 7 test.Maildir2/$file || exit 1
gosh -ugauche.test -e '(test-end)' -Eexit


exit 0