#!/bin/sh testname=${0#$srcdir/} if test -z "$MH_OBJ_DIR"; then srcdir=`dirname "$0"`/../.. MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR fi . "$MH_OBJ_DIR/test/common.sh" rm -rf "$MH_TEST_DIR/panda" imap_cleanup() { #### Save exit status to use as status for this program. status=$? set +e [ -n "$imapd_pid" ] && kill $imapd_pid for profile in $profiles; do set_mh_profile $profile "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown done # TODO have cleanup allow additional cleanup registration? # Or just allow it to accept status as argument. (exit $status) cleanup } mkdir "$MH_TEST_DIR/panda" mkdir "$MH_TEST_DIR/panda/test" expected="$MH_TEST_DIR/$$.expected" actual="$MH_TEST_DIR/$$.actual" # TODO duplicated with test-scan arith_val=1 message_count=11 cat > "$MH_TEST_DIR/panda/test/fold" < "$actual" 2>&1 || status=$? } covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname" install -d "$covdir" # setup profile 2 and 1, leaving 1 as active profile for i in 3 2 1; do setup_test_without_data profile$i trap imap_cleanup 0 # TODO Stop using mailbox-root in all but live tests once we have a local # panda hacked never to look at real mailboxes. cat >> "$MH" <> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi done # 4 messages in profile 1 echo 'imap-max-fetch-messages-in-flight: 4' >> "$MH" start ################################################################################ start_test 'inc' echo 'Incorporating new mail into imap/fold...' > "$expected.inc.full" echo >> "$expected.inc.full" echo " $arith_val 10/24 me <>" >> "$expected.inc.full" while [ $arith_val -lt $message_count ]; do arith_eval $arith_val + 1 printf ' %2d U 10/24 me <>\n' $arith_val >> "$expected.inc.full" cat >> $MH_TEST_DIR/panda/test/fold <>\n' $arith_val >> "$expected.inc.full" cat >> $MH_TEST_DIR/panda/test/fold < "$actual" check "$actual" "$expected.inc" ################################################################################ start_test 'inc after inc finds no new mail' cat /dev/null > "$expected.inc" inc +imap -form scan.unseen -width 80 > "$actual" check "$actual" "$expected.inc" ################################################################################ start_test 'inc after inc finds new mail' arith_eval $arith_val + 1 cat >> $MH_TEST_DIR/panda/test/fold < "$expected.inc" echo >> "$expected.inc" printf ' %2d U 10/24 me <>\n' $arith_val >> "$expected.inc" # Kill the folder manager so inc will cause a re-SELECT. "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown inc +imap -form scan.unseen -width 80 > "$actual" check "$actual" "$expected.inc" ################################################################################ start_test 'child of excluded mailbox excluded' mkdir -p "$MH_TEST_DIR/panda/test/excluded" cat > "$MH_TEST_DIR/panda/test/excluded/fold" < "$expected" inc +imap > "$actual" check "$actual" "$expected" ################################################################################ start_test 'explicitly included child of excluded mailbox included' cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/re-included" cat > "$expected" <> EOF inc +imap > "$actual" check "$actual" "$expected" ################################################################################ start_test 'explicitly requested child of excluded mailbox included' cp "$MH_TEST_DIR/panda/test/excluded/fold" "$MH_TEST_DIR/panda/test/excluded/still-excluded" cat > "$expected" <> EOF inc +imap/excluded/still-excluded > "$actual" check "$actual" "$expected" ################################################################################ start_test 'fetch messages all fit in first FETCH UID' set_mh_profile profile2 # 12 messages so go for 11 per fetch. # 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. echo 'imap-max-fetch-messages-in-flight: 11' >> "$MH" start ( sed 's/ U / /; s| 1 10/24 me| 1 10/24 me|' "$expected.inc.full" echo ' 12 10/24 me <>' ) > "$expected.inc" inc +imap/fold > "$actual" check "$actual" "$expected.inc" ################################################################################ start_test '1d. just one more UID to FETCH' set_mh_profile profile3 cat >> $MH_TEST_DIR/panda/test/fold <> "$MH" start ( sed 's/ U / /; s| 1 10/24 me| 1 10/24 me|' "$expected.inc.full" echo ' 12 10/24 me <>' echo ' 13 10/24 me <>' ) > "$expected.inc" rm -f "$expected.inc.full" inc +imap/fold > "$actual" check "$actual" "$expected.inc" ################################################################################ start_test 'one message in page 2' set_mh_profile profile1 # Still using max-fetch-messages-in-flight:4 # The first FETCH UID requests 1:8 (pages 1 and 2). # We provide a mailbox with messages 1-9. genmailbox() { cat < $MH_TEST_DIR/panda/test/omp2 cat > "$expected.inc" <> 2 U 10/24 me <> 3 U 10/24 me <> 4 U 10/24 me <> 5 U 10/24 me <> 6 U 10/24 me <> 7 U 10/24 me <> 8 U 10/24 me <> 9 U 10/24 me <> 10 U 10/24 me <> 11 U 10/24 me <> 12 U 10/24 me <> 13 U 10/24 me <> EOF inc +imap/omp2 -form scan.unseen -width 80 > "$actual" || : check "$actual" "$expected.inc" ################################################################################ start_test 'UID gap with one remaining' set_mh_profile profile3 # Still using max-fetch-messages-in-flight:6 # The first FETCH UID requests 1:12. # We provide a mailbox with a UID gap though; only these are present: # 1, 3, 13 cat > $MH_TEST_DIR/panda/test/uidgap1 < "$expected.inc" <> 2 U 10/24 me <> 3 U 10/24 me <> EOF inc +imap/uidgap1 -form scan.unseen -width 80 > "$actual" || : check "$actual" "$expected.inc" ################################################################################ start_test 'UID gap with two remaining' set_mh_profile profile3 # Still using max-fetch-messages-in-flight:6 # The first FETCH UID requests 1:12. # We provide a mailbox with many UID gaps though; only these are present: # 1, 3, 20, 30 # oh hey! what happens when there's HUGE gaps?! # we'll keep making dumb requests for sequences like 13:18 for no gain, as this test demonstrates # is there a better way to discover UIDs? # even if there is, these tests are worth having # nothing obvious. we can move the FLAGS request to the FETCH BODY though cat > $MH_TEST_DIR/panda/test/uidgap2 < "$expected.inc" <> 2 U 10/24 me <> 3 U 10/24 me <> 4 U 10/24 me <> EOF inc +imap/uidgap2 -form scan.unseen -width 80 > "$actual" || : check "$actual" "$expected.inc" finish_test exit ${failed:-0}