5 if test -z "$MH_OBJ_DIR"; then
6 srcdir
=`dirname "$0"`/..
/..
7 MH_OBJ_DIR
=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
10 .
"$MH_OBJ_DIR/test/common.sh"
12 rm -rf "$MH_TEST_DIR/panda"
15 #### Save exit status to use as status for this program.
19 [ -n "$imapd_pid" ] && kill $imapd_pid
21 for profile
in $profiles; do
22 set_mh_profile
$profile
23 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
26 # TODO have cleanup allow additional cleanup registration?
27 # Or just allow it to accept status as argument.
32 mkdir "$MH_TEST_DIR/panda"
33 mkdir "$MH_TEST_DIR/panda/test"
35 expected
="$MH_TEST_DIR/$$.expected"
36 actual
="$MH_TEST_DIR/$$.actual"
38 # TODO duplicated with test-scan
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
46 X-IMAPbase: 1603585238 $message_count testseq
56 start_fakeinetd env
"HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
57 imapd_pid
=$fakeinetd_pid
60 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
62 LLVM_PROFILE_FILE
="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start
> "$actual" 2>&1 || status
=$?
65 covdir
="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
68 # setup profile 2 and 1, leaving 1 as active profile
70 setup_test_without_data profile
$i
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.
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
81 imap-port: $fakeinetd_port
82 imap-tls: don't protect my data i know what i'm doing
84 imap-mailbox-root: test/
85 imap-mailbox-exclude: excluded
86 imap-mailbox-include: excluded/re-included
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"
94 # 4 messages in profile 1
95 echo 'imap-max-fetch-messages-in-flight: 4' >> "$MH"
98 ################################################################################
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"
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
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
138 cp "$expected.inc.full" "$expected.inc"
140 inc
+imap
-form scan.unseen
-width 80 > "$actual"
141 check
"$actual" "$expected.inc"
143 ################################################################################
144 start_test
'inc after inc finds no new mail'
146 cat /dev
/null
> "$expected.inc"
147 inc
+imap
-form scan.unseen
-width 80 > "$actual"
148 check
"$actual" "$expected.inc"
150 ################################################################################
151 start_test
'inc after inc finds new mail'
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
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"
171 # Kill the folder manager so inc will cause a re-SELECT.
172 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
174 inc
+imap
-form scan.unseen
-width 80 > "$actual"
175 check
"$actual" "$expected.inc"
177 ################################################################################
178 start_test
'child of excluded mailbox excluded'
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
186 X-IMAPbase: 1603585238 1 testseq
195 cat /dev
/null
> "$expected"
196 inc
+imap
> "$actual"
197 check
"$actual" "$expected"
199 ################################################################################
200 start_test
'explicitly included child of excluded mailbox included'
202 cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/re-included"
204 cat > "$expected" <<EOF
205 Incorporating new mail into imap/excluded/re-included...
209 inc
+imap
> "$actual"
210 check
"$actual" "$expected"
212 ################################################################################
213 start_test
'explicitly requested child of excluded mailbox included'
215 cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/still-excluded"
217 cat > "$expected" <<EOF
218 Incorporating new mail into imap/excluded/still-excluded...
222 inc
+imap
/excluded
/still-excluded
> "$actual"
223 check
"$actual" "$expected"
225 ################################################################################
226 start_test
'fetch messages all fit in first FETCH UID'
228 set_mh_profile profile2
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"
236 sed 's/ U / /; s| 1 10/24 me| 1 10/24 me|' "$expected.inc.full"
237 echo ' 12 10/24 me <<body >>'
240 inc
+imap
/fold > "$actual"
241 check
"$actual" "$expected.inc"
243 ################################################################################
244 start_test
'1d. just one more UID to FETCH'
246 set_mh_profile profile3
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
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"
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 >>'
271 rm -f "$expected.inc.full"
273 inc
+imap
/fold > "$actual"
274 check
"$actual" "$expected.inc"
276 ################################################################################
277 start_test
'one message in page 2'
279 set_mh_profile profile1
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.
287 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
288 Date:Sat, 24 Oct 2020 19:20:38 -0500
291 X-IMAPbase: 1626040083 $1
301 while [ $arith_val -le $1 ]; do
303 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
304 Date:Sat, 24 Oct 2020 19:20:38 -0500
315 arith_eval
$arith_val + 1
319 genmailbox
13 > $MH_TEST_DIR/panda
/test
/omp2
321 cat > "$expected.inc" <<EOF
322 Incorporating new mail into imap/omp2...
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 >>
339 inc
+imap
/omp2
-form scan.unseen
-width 80 > "$actual" || :
340 check
"$actual" "$expected.inc"
342 ################################################################################
343 start_test
'UID gap with one remaining'
345 set_mh_profile profile3
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:
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
357 X-IMAPbase: 1626040083 13
365 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
366 Date:Sat, 24 Oct 2020 19:20:38 -0500
376 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
377 Date:Sat, 24 Oct 2020 19:20:38 -0500
389 cat > "$expected.inc" <<EOF
390 Incorporating new mail into imap/uidgap1...
392 1 U 10/24 me <<body >>
393 2 U 10/24 me <<body >>
394 3 U 10/24 me <<body >>
397 inc
+imap
/uidgap1
-form scan.unseen
-width 80 > "$actual" || :
398 check
"$actual" "$expected.inc"
400 ################################################################################
401 start_test
'UID gap with two remaining'
403 set_mh_profile profile3
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:
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
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
420 X-IMAPbase: 1626040083 30
428 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
429 Date:Sat, 24 Oct 2020 19:20:38 -0500
439 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
440 Date:Sat, 24 Oct 2020 19:20:38 -0500
450 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
451 Date:Sat, 24 Oct 2020 19:20:38 -0500
463 cat > "$expected.inc" <<EOF
464 Incorporating new mail into imap/uidgap2...
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 >>
472 inc
+imap
/uidgap2
-form scan.unseen
-width 80 > "$actual" || :
473 check
"$actual" "$expected.inc"