#!/bin/sh # Cyrus # MH_IMAP_TEST_SERVER=127.0.0.1 MH_IMAP_TEST_PORT=143 MH_IMAP_TEST_USER=test MH_IMAP_TEST_PASSWORD=test MH_IMAP_TEST_EMAIL_ADDRESS=test MH_IMAP_TEST_TLS=no MH_IMAP_TEST_MAILBOX_ROOT=test/ make check TESTS=test/imap/test-live # Dovecot # MH_IMAP_TEST_SERVER=127.0.0.1 MH_IMAP_TEST_PORT=1043 MH_IMAP_TEST_USER=test MH_IMAP_TEST_PASSWORD=testpw MH_IMAP_TEST_EMAIL_ADDRESS=test MH_IMAP_TEST_TLS=no MH_IMAP_SERVER_EATS_TRAILING_EOL=' ' make check TESTS=test/imap/test-live # Panda # MH_IMAP_TEST_SERVER=panda make check TESTS=test/imap/test-live # Gandi (looks like they use Dovecot) # MH_IMAP_TEST_SERVER=mail.gandi.net MH_IMAP_TEST_PORT=imaps MH_IMAP_TEST_USER=... MH_IMAP_TEST_PASSWORD='...' MH_IMAP_TEST_EMAIL_ADDRESS=test@pretzelnet.org MH_IMAP_TEST_TLS=implicit MH_IMAP_TEST_MAILBOX_ROOT=test/ make check TESTS=test/imap/test-live # Gmail # MH_IMAP_TEST_SERVER=gmail MH_IMAP_TEST_PORT=imaps MH_IMAP_TEST_USER=... MH_IMAP_TEST_OAUTH_FILE="/path/to/oauth-gmail" MH_IMAP_TEST_EMAIL_ADDRESS=... MH_IMAP_TEST_MAILBOX_ROOT=test/ make check TESTS=test/imap/test-live 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" if [ -z "$MH_IMAP_TEST_SERVER" ]; then test_skip 'no IMAP test server selected' fi start() { rm -f "$MH_TEST_DIR/$profile/imap.d/socket" status=0 LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start > "$actual" 2>&1 || status=$? } MH_template="$MH_TEST_DIR/template.mh_profile" components_template="$MH_TEST_DIR/template.components" scan_template="$MH_TEST_DIR/template.scan.nodate" rm -f "$MH_template" "$components_template" "$scan_template" rm -rf "$MH_TEST_DIR/dovecot" "$MH_TEST_DIR/panda" rm -rf "$MH_TEST_DIR"/*/imap.d imap_cleanup() { #### Save exit status to use as status for this program. status=$? set +e if [ -z "$MH_TEST_NOCLEANUP" ]; then for i in $test_folders; do rmf +$i -nointeractive done fi [ -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 } if [ "$MH_IMAP_TEST_SERVER" = 'panda' ]; then # TODO It seems drafts are born unseen on Cyrus and GMail. MH_IMAP_SERVER_DRAFT_BORN_UNSEEN=' ' # TODO Why is Cyrus eating the trailing CRLF? # I'm planning to use refile -file instead of comp anyway; will that help? MH_IMAP_SERVER_EATS_TRAILING_EOL=' ' [ -z "$LOGNAME" ] && fail 'LOGNAME not set' MH_IMAP_TEST_EMAIL_ADDRESS="$LOGNAME" mkdir "$MH_TEST_DIR/panda" # Thought creating this stopped Panda from looking at the developer's real # inbox, but it doesn't stop it from mangling /var/mail! # TODO Ship customized Panda for testing. touch "$MH_TEST_DIR/panda/mbox" start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD" imapd_pid=$fakeinetd_pid cat > "$MH_template" < "$MH_TEST_DIR/dovecot/cf" < "$MH_template" <> "$MH_template" fi elif [ -z "$MH_IMAP_TEST_PORT" ] \ || [ -z "$MH_IMAP_TEST_TLS" ] \ || [ -z "$MH_IMAP_TEST_USER" ] \ || [ -z "$MH_IMAP_TEST_PASSWORD" ] \ || [ -z "$MH_IMAP_TEST_EMAIL_ADDRESS" ]; then fail 'MH_IMAP_TEST_PORT MH_IMAP_TEST_USER MH_IMAP_TEST_PASSWORD MH_IMAP_TEST_EMAIL_ADDRESS must all be set' else case $MH_IMAP_TEST_TLS in no) MH_IMAP_TEST_TLS="don't protect my data i know what i'm doing" ;; unverified-implicit) MH_IMAP_TEST_TLS="implicit but don't verify the cert i already did out of band" ;; esac cat > "$MH_TEST_DIR/netrc" <> "$MH_template" <> "$MH_template" fi fi # it seems with cyrus everything has to go under INBOX? i probably # messed something up but whatever, let's roll with it. # * LIST (\HasChildren) "/" INBOX #* LIST (\HasNoChildren) "/" INBOX/foo imap_folder=imap/imap$(date '+%j%H%M%S') cat >> "$MH_template" < "$scan_template" <%<(unseen)U%| %>%<{replied}-%| %>\ %<(mymbox{from})%<{to}To:%(unquote(decode(friendly{to})))%>%>\ %<(zero)%(unquote(decode(friendly{from})))%> \ %(decode{subject})%<{body}<<%{body}>>%> EOF # TODO default components use '--------' to close header... cat > "$components_template" <%(void(width))%(putaddr From: ) %<{to}%(void(width))%(putaddr To: )%|To:%> %<{cc}%(void(width))%(putaddr cc: )%|cc:%> Fcc: %<{fcc}%(putstr)%|+outbox%> Subject:%<{subject} %(putstr)%> body EOF expected="$MH_TEST_DIR/$$.expected" actual="$MH_TEST_DIR/$$.actual" ################################################################################ profile=profile1 rm -rf "$MH_TEST_DIR/$profile" setup_test_without_data $profile trap imap_cleanup 0 cat "$MH_template" >> "$MH" cp "$components_template" "$MH_TEST_DIR/$profile/components" cp "$scan_template" "$MH_TEST_DIR/$profile/scan.nodate" if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi # Set this for the EHLO command echo "clientname: nosuchhost.example.com" >> "$MHMTSCONF" cat >> "$MH" < "$expected" < "$actual" check "$actual" "$expected" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent ################################################################################ start_test 'inc when nothing to fetch' cat /dev/null > "$expected" check_exit '-eq 0' inc +imap -width 80 ################################################################################ start_test 'comp creates draft in empty draft folder' check_exit '-eq 0' comp -noedit -to "$MH_IMAP_TEST_EMAIL_ADDRESS" -fcc $imap_folder/sent -subject 'testing imap' -nowhatnowproc # comp creates a message, stores a UID/msgnum pair, runs the user's editor, # creates a new message with the user's edits, and replaces the UID/msgnum pair. # So verify the integrity of the database after that. # TODO any other operations worth having this integrity check on? check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts start_test 'scan drafts after comp' cat > "$expected" <> EOF run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual" check "$actual" "$expected" start_test 'show draft after comp' cat > "$expected" < "$actual" check "$actual" "$expected" start_test 'check .mh_sequences after show after comp' cat > "$expected" < "$expected" <> 2 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<> EOF run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual" check "$actual" "$expected" start_test 'check .mh_sequences after non-empty comp' cat > "$expected" < /dev/null check_exit '-eq 0' send -server 127.0.0.1 -port $localport -draftfolder $imap_folder/drafts rm -f "$actual" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent # TODO what?! this test started out as this and evolved into something else? start_test 'scan drafts finds no messages after send' # Check draft moved to FCC folder cat > "$expected" <> EOF run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual" check "$actual" "$expected" start_test 'scan sent finds the sent messages after send' cat > "$expected" <> EOF run_prog scan -form scan.nodate +$imap_folder/sent -width 80 > "$actual" check "$actual" "$expected" ################################################################################ profile=profile2 rm -rf "$MH_TEST_DIR/$profile" setup_test_without_data $profile trap imap_cleanup 0 cat "$MH_template" >> "$MH" cp "$components_template" "$MH_TEST_DIR/$profile/components" cp "$scan_template" "$MH_TEST_DIR/$profile/scan.nodate" if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi cat >> "$MH" < "$expected" <> Incorporating new mail into $imap_folder/sent... 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<> EOF inc +imap -form scan.nodate -width 80 > "$actual" check "$actual" "$expected" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent ################################################################################ start_test 'show the sent message after inc' cat > "$expected" <> "$expected" else echo -n body >> "$expected" fi run_prog show +$imap_folder/sent 1 > "$actual" sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate rm -f "$actual" check "$actual.nodate" "$expected" ################################################################################ start_test 'mark the sent message unseen' check_exit '-eq 0' mark -add -seq unseen +$imap_folder/sent 1 start_test 'scan after mark unseen' cat > "$expected" <> EOF run_prog scan -form scan.nodate -width 80 > "$actual" check "$actual" "$expected" ################################################################################ start_test 'show the now-unseen message' check_exit '-eq 0' show all start_test 'scan after show' cat > "$expected" <> EOF run_prog scan -form scan.nodate -width 80 > "$actual" check "$actual" "$expected" ################################################################################ start_test 'refile -file' refiled_file="$MH_TEST_DIR/$$.refiled-file" cat > "$refiled_file" < "$expected" <> 2 me <> EOF scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual" check "$actual" "$expected" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts ################################################################################ start_test 'refile' check_exit '-eq 0' refile -src +$imap_folder/drafts 2 +$imap_folder/sent # TODO what?! this test started out as this and evolved into something else? start_test 'scan src folder after refile finds no messages' cat > "$expected" <> EOF scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual" check "$actual" "$expected" start_test 'scan dst folder after refile finds refiled message' cat > "$expected" <> 2 me <> EOF scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual" check "$actual" "$expected" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent ################################################################################ start_test 'mark unseen after refile' # This tests the UID update in the local database. check_exit '-eq 0' mark -add -seq unseen 2 cat > "$expected" <> 2 U me <> EOF scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual" check "$actual" "$expected" ################################################################################ start_test 'show all before rmm' cat > "$expected" <>> $imap_folder/sent:1 Date: To: $MH_IMAP_TEST_EMAIL_ADDRESS From: $MH_IMAP_TEST_EMAIL_ADDRESS Subject: testing imap MIME-Version: 1.0 EOF if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then echo 'body ' >> "$expected" else echo -n body >> "$expected" fi cat >> "$expected" <>> $imap_folder/sent:2 Date: To: you From: me EOF # TODO Why is this one unaffected?! Really need to get to the bottom of this... if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then echo refile-test >> "$expected" else echo refile-test >> "$expected" fi run_prog show +$imap_folder/sent all > "$actual" sed -e 's/^Date:.*/Date:/' "$actual" > "$actual.nodate" rm -f "$actual" check "$actual.nodate" "$expected" start_test 'check .mh_sequences after show before rmm' cat > "$expected" < "$expected" <> "$expected" else echo refile-test >> "$expected" fi run_prog show +$imap_folder/sent > "$actual" check "$actual" "$expected" start_test 'check .mh_sequences after show cur shows 2 after show all' cat > "$expected" < "$expected" <> "$expected" else echo -n body >> "$expected" fi run_prog show +$imap_folder/sent 1 > "$actual" sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate rm -f "$actual" check "$actual.nodate" "$expected" start_test 'check .mh_sequences after show 1 before rmm' cat > "$expected" < "$expected" <> "$expected" else echo -n body >> "$expected" fi run_prog show +$imap_folder/sent > "$actual" sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate rm -f "$actual" check "$actual.nodate" "$expected" start_test 'check .mh_sequences after show cur shows 1 after show 1' cat > "$expected" < "$expected" <> EOF scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual" check "$actual" "$expected" check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent ################################################################################ start_test 'inc finds messages to delete 1. create messages in profile2' for i in 2 3 4 5 6; do refiled_file="$MH_TEST_DIR/$$.refiled-file" cat > "$refiled_file" < "$expected" <> 2 me refile 2<> 3 me refile 3<> 4 me refile 4<> 5 me refile 5<> 6 me refile 6<> EOF scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual" check "$actual" "$expected" for i in $test_folders; do check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $i done ################################################################################ start_test 'inc finds messages to delete 2. inc new messages into profile1' set_mh_profile profile1 # Message numbers are one greater in profile1 than in profile2. cat > "$expected" <> 4 me refile 3<> 5 me refile 4<> 6 me refile 5<> 7 me refile 6<> EOF inc +imap -form scan.nodate -width 80 > "$actual" || : check "$actual" "$expected" ################################################################################ start_test 'inc finds messages to delete 3. rmm messages out of profile2' set_mh_profile profile2 check_exit '-eq 0' rmm -unlink 2 check_exit '-eq 0' rmm -unlink 4 check_exit '-eq 0' rmm -unlink 5 cat > "$expected" <> 3 me refile 3<> 6 me refile 6<> EOF scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual" check "$actual" "$expected" ################################################################################ start_test 'inc finds messages to delete 4. inc deletes from profile1' set_mh_profile profile1 inc +imap -form scan.nodate -width 80 > "$actual" || : check /dev/null "$actual" 'keep first' ################################################################################ start_test 'inc finds messages to delete 5. scan profile1 to see messages gone' # Message numbers are one greater in profile1 than in profile2. cat > "$expected" <> 4 me refile 3<> 7 me refile 6<> EOF scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual" check "$actual" "$expected" # TODO tests: # - refile old message into a folder with newer messages: UID validity preserved? ################################################################################ start_test 'check all folder databases one last time' for profile in $profiles; do set_mh_profile $profile for i in $test_folders; do check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $i done done finish_test exit ${failed:-0}