]> diplodocus.org Git - nmh/blob - test/imap/test-inc
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-inc
1 #!/bin/sh
2
3 testname=${0#$srcdir/}
4
5 if test -z "$MH_OBJ_DIR"; then
6 srcdir=`dirname "$0"`/../..
7 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
8 fi
9
10 . "$MH_OBJ_DIR/test/common.sh"
11
12 rm -rf "$MH_TEST_DIR/panda"
13
14 imap_cleanup() {
15 #### Save exit status to use as status for this program.
16 status=$?
17 set +e
18
19 [ -n "$imapd_pid" ] && kill $imapd_pid
20
21 for profile in $profiles; do
22 set_mh_profile $profile
23 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
24 done
25
26 # TODO have cleanup allow additional cleanup registration?
27 # Or just allow it to accept status as argument.
28 (exit $status)
29 cleanup
30 }
31
32 mkdir "$MH_TEST_DIR/panda"
33 mkdir "$MH_TEST_DIR/panda/test"
34
35 expected="$MH_TEST_DIR/$$.expected"
36 actual="$MH_TEST_DIR/$$.actual"
37
38 # TODO duplicated with test-scan
39 arith_val=1
40 message_count=11
41 cat > "$MH_TEST_DIR/panda/test/fold" <<EOF
42 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
43 Date:Sat, 24 Oct 2020 19:20:38 -0500
44 from:me
45 to:you
46 X-IMAPbase: 1603585238 $message_count testseq
47 Status: RO
48 X-Status:
49 X-Keywords:
50 X-UID: $arith_val
51
52 body
53
54 EOF
55
56 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
57 imapd_pid=$fakeinetd_pid
58
59 start() {
60 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
61 status=0
62 LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start > "$actual" 2>&1 || status=$?
63 }
64
65 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
66 install -d "$covdir"
67
68 # setup profile 2 and 1, leaving 1 as active profile
69 for i in 3 2 1; do
70 setup_test_without_data profile$i
71 trap imap_cleanup 0
72
73 # TODO Stop using mailbox-root in all but live tests once we have a local
74 # panda hacked never to look at real mailboxes.
75 cat >> "$MH" <<EOF
76 Managed-Folders: imap
77 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
78 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
79 imap-db: $MH_TEST_DIR/$profile/imap.d
80 imap-host: 127.0.0.1
81 imap-port: $fakeinetd_port
82 imap-tls: don't protect my data i know what i'm doing
83 imap-auth: PREAUTH
84 imap-mailbox-root: test/
85 imap-mailbox-exclude: excluded
86 imap-mailbox-include: excluded/re-included
87 EOF
88 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
89 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
90 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
91 fi
92 done
93
94 # 4 messages in profile 1
95 echo 'imap-max-fetch-messages-in-flight: 4' >> "$MH"
96 start
97
98 ################################################################################
99 start_test 'inc'
100
101 echo 'Incorporating new mail into imap/fold...' > "$expected.inc.full"
102 echo >> "$expected.inc.full"
103 echo " $arith_val 10/24 me <<body >>" >> "$expected.inc.full"
104
105 while [ $arith_val -lt $message_count ]; do
106 arith_eval $arith_val + 1
107 printf ' %2d U 10/24 me <<body >>\n' $arith_val >> "$expected.inc.full"
108 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
109 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
110 Date:Sat, 24 Oct 2020 19:20:38 -0500
111 from:me
112 to:you
113 Status: O
114 X-Status:
115 X-Keywords:
116 X-UID: $arith_val
117
118 body
119
120 EOF
121 arith_eval $arith_val + 1
122 printf ' %2d U 10/24 me <<body >>\n' $arith_val >> "$expected.inc.full"
123 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
124 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
125 Date:Sat, 24 Oct 2020 19:20:38 -0500
126 from:me
127 to:you
128 Status: O
129 X-Status:
130 X-Keywords:
131 X-UID: $arith_val
132
133 body
134
135 EOF
136 done
137
138 cp "$expected.inc.full" "$expected.inc"
139
140 inc +imap -form scan.unseen -width 80 > "$actual"
141 check "$actual" "$expected.inc"
142
143 ################################################################################
144 start_test 'inc after inc finds no new mail'
145
146 cat /dev/null > "$expected.inc"
147 inc +imap -form scan.unseen -width 80 > "$actual"
148 check "$actual" "$expected.inc"
149
150 ################################################################################
151 start_test 'inc after inc finds new mail'
152
153 arith_eval $arith_val + 1
154 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
155 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
156 Date:Sat, 24 Oct 2020 19:20:38 -0500
157 from:me
158 to:you
159 Status: O
160 X-Status:
161 X-Keywords:
162 X-UID: $arith_val
163
164 body
165
166 EOF
167 echo 'Incorporating new mail into imap/fold...' > "$expected.inc"
168 echo >> "$expected.inc"
169 printf ' %2d U 10/24 me <<body >>\n' $arith_val >> "$expected.inc"
170
171 # Kill the folder manager so inc will cause a re-SELECT.
172 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
173
174 inc +imap -form scan.unseen -width 80 > "$actual"
175 check "$actual" "$expected.inc"
176
177 ################################################################################
178 start_test 'child of excluded mailbox excluded'
179
180 mkdir -p "$MH_TEST_DIR/panda/test/excluded"
181 cat > "$MH_TEST_DIR/panda/test/excluded/fold" <<EOF
182 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
183 Date:Sat, 24 Oct 2020 19:20:38 -0500
184 from:me
185 to:you
186 X-IMAPbase: 1603585238 1 testseq
187 Status: RO
188 X-Status:
189 X-Keywords:
190 X-UID: 1
191
192 body
193 EOF
194
195 cat /dev/null > "$expected"
196 inc +imap > "$actual"
197 check "$actual" "$expected"
198
199 ################################################################################
200 start_test 'explicitly included child of excluded mailbox included'
201
202 cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/re-included"
203
204 cat > "$expected" <<EOF
205 Incorporating new mail into imap/excluded/re-included...
206
207 1 10/24 me <<body >>
208 EOF
209 inc +imap > "$actual"
210 check "$actual" "$expected"
211
212 ################################################################################
213 start_test 'explicitly requested child of excluded mailbox included'
214
215 cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/still-excluded"
216
217 cat > "$expected" <<EOF
218 Incorporating new mail into imap/excluded/still-excluded...
219
220 1 10/24 me <<body >>
221 EOF
222 inc +imap/excluded/still-excluded > "$actual"
223 check "$actual" "$expected"
224
225 ################################################################################
226 start_test 'fetch messages all fit in first FETCH UID'
227
228 set_mh_profile profile2
229
230 # 12 messages so go for 11 per fetch.
231 # This hits the '1d. no more UIDs to FETCH but we are still expecting FETCH UID responses from that initial fetch' case in do_inc.
232 echo 'imap-max-fetch-messages-in-flight: 11' >> "$MH"
233 start
234
235 (
236 sed 's/ U / /; s| 1 10/24 me| 1 10/24 me|' "$expected.inc.full"
237 echo ' 12 10/24 me <<body >>'
238 ) > "$expected.inc"
239
240 inc +imap/fold > "$actual"
241 check "$actual" "$expected.inc"
242
243 ################################################################################
244 start_test '1d. just one more UID to FETCH'
245
246 set_mh_profile profile3
247
248 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
249 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
250 Date:Sat, 24 Oct 2020 19:20:38 -0500
251 from:me
252 to:you
253 Status: O
254 X-Status:
255 X-Keywords:
256 X-UID: $arith_val
257
258 body
259
260 EOF
261
262 # max:6 means the first FETCH UID requests 12 leaving just one more for the 2nd FETCH UID.
263 echo 'imap-max-fetch-messages-in-flight: 6' >> "$MH"
264 start
265
266 (
267 sed 's/ U / /; s| 1 10/24 me| 1 10/24 me|' "$expected.inc.full"
268 echo ' 12 10/24 me <<body >>'
269 echo ' 13 10/24 me <<body >>'
270 ) > "$expected.inc"
271 rm -f "$expected.inc.full"
272
273 inc +imap/fold > "$actual"
274 check "$actual" "$expected.inc"
275
276 ################################################################################
277 start_test 'one message in page 2'
278
279 set_mh_profile profile1
280
281 # Still using max-fetch-messages-in-flight:4
282 # The first FETCH UID requests 1:8 (pages 1 and 2).
283 # We provide a mailbox with messages 1-9.
284
285 genmailbox() {
286 cat <<EOF
287 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
288 Date:Sat, 24 Oct 2020 19:20:38 -0500
289 from:me
290 to:you
291 X-IMAPbase: 1626040083 $1
292 Status: O
293 X-Status:
294 X-Keywords:
295 X-UID: 1
296
297 body
298
299 EOF
300 arith_val=2
301 while [ $arith_val -le $1 ]; do
302 cat <<EOF
303 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
304 Date:Sat, 24 Oct 2020 19:20:38 -0500
305 from:me
306 to:you
307 Status: O
308 X-Status:
309 X-Keywords:
310 X-UID: $arith_val
311
312 body
313
314 EOF
315 arith_eval $arith_val + 1
316 done
317 }
318
319 genmailbox 13 > $MH_TEST_DIR/panda/test/omp2
320
321 cat > "$expected.inc" <<EOF
322 Incorporating new mail into imap/omp2...
323
324 1 U 10/24 me <<body >>
325 2 U 10/24 me <<body >>
326 3 U 10/24 me <<body >>
327 4 U 10/24 me <<body >>
328 5 U 10/24 me <<body >>
329 6 U 10/24 me <<body >>
330 7 U 10/24 me <<body >>
331 8 U 10/24 me <<body >>
332 9 U 10/24 me <<body >>
333 10 U 10/24 me <<body >>
334 11 U 10/24 me <<body >>
335 12 U 10/24 me <<body >>
336 13 U 10/24 me <<body >>
337 EOF
338
339 inc +imap/omp2 -form scan.unseen -width 80 > "$actual" || :
340 check "$actual" "$expected.inc"
341
342 ################################################################################
343 start_test 'UID gap with one remaining'
344
345 set_mh_profile profile3
346
347 # Still using max-fetch-messages-in-flight:6
348 # The first FETCH UID requests 1:12.
349 # We provide a mailbox with a UID gap though; only these are present:
350 # 1, 3, 13
351
352 cat > $MH_TEST_DIR/panda/test/uidgap1 <<EOF
353 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
354 Date:Sat, 24 Oct 2020 19:20:38 -0500
355 from:me
356 to:you
357 X-IMAPbase: 1626040083 13
358 Status: O
359 X-Status:
360 X-Keywords:
361 X-UID: 1
362
363 body
364
365 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
366 Date:Sat, 24 Oct 2020 19:20:38 -0500
367 from:me
368 to:you
369 Status: O
370 X-Status:
371 X-Keywords:
372 X-UID: 3
373
374 body
375
376 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
377 Date:Sat, 24 Oct 2020 19:20:38 -0500
378 from:me
379 to:you
380 Status: O
381 X-Status:
382 X-Keywords:
383 X-UID: 13
384
385 body
386
387 EOF
388
389 cat > "$expected.inc" <<EOF
390 Incorporating new mail into imap/uidgap1...
391
392 1 U 10/24 me <<body >>
393 2 U 10/24 me <<body >>
394 3 U 10/24 me <<body >>
395 EOF
396
397 inc +imap/uidgap1 -form scan.unseen -width 80 > "$actual" || :
398 check "$actual" "$expected.inc"
399
400 ################################################################################
401 start_test 'UID gap with two remaining'
402
403 set_mh_profile profile3
404
405 # Still using max-fetch-messages-in-flight:6
406 # The first FETCH UID requests 1:12.
407 # We provide a mailbox with many UID gaps though; only these are present:
408 # 1, 3, 20, 30
409 # oh hey! what happens when there's HUGE gaps?!
410 # we'll keep making dumb requests for sequences like 13:18 for no gain, as this test demonstrates
411 # is there a better way to discover UIDs?
412 # even if there is, these tests are worth having
413 # nothing obvious. we can move the FLAGS request to the FETCH BODY though
414
415 cat > $MH_TEST_DIR/panda/test/uidgap2 <<EOF
416 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
417 Date:Sat, 24 Oct 2020 19:20:38 -0500
418 from:me
419 to:you
420 X-IMAPbase: 1626040083 30
421 Status: O
422 X-Status:
423 X-Keywords:
424 X-UID: 1
425
426 body
427
428 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
429 Date:Sat, 24 Oct 2020 19:20:38 -0500
430 from:me
431 to:you
432 Status: O
433 X-Status:
434 X-Keywords:
435 X-UID: 3
436
437 body
438
439 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
440 Date:Sat, 24 Oct 2020 19:20:38 -0500
441 from:me
442 to:you
443 Status: O
444 X-Status:
445 X-Keywords:
446 X-UID: 20
447
448 body
449
450 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
451 Date:Sat, 24 Oct 2020 19:20:38 -0500
452 from:me
453 to:you
454 Status: O
455 X-Status:
456 X-Keywords:
457 X-UID: 30
458
459 body
460
461 EOF
462
463 cat > "$expected.inc" <<EOF
464 Incorporating new mail into imap/uidgap2...
465
466 1 U 10/24 me <<body >>
467 2 U 10/24 me <<body >>
468 3 U 10/24 me <<body >>
469 4 U 10/24 me <<body >>
470 EOF
471
472 inc +imap/uidgap2 -form scan.unseen -width 80 > "$actual" || :
473 check "$actual" "$expected.inc"
474
475 finish_test
476 exit ${failed:-0}