3 # Errors: can't live with 'em can't live without 'em
6 # 1. report comprehensible error to user
7 # 2. comprehensible log (good enough for a quality bug report)
8 # 3. clean close of IMAP connection
10 # 1. clean close if at all possible
11 # 2. if not, report failure along with the original failure
12 # - If nmh connection open:
13 # 1. write blind error
14 # 2. if that write failed log but ignore
15 # 3. Else close the socket, log+ignore error here too
16 # - If IMAP connection is open:
17 # 1. write a blind LOGOUT
18 # 2. if that write failed log but ignore
19 # 3. Else close the socket, log+ignore error here too
20 # - If error is detected at layer that has both nmh and IMAP connection
21 # available, handle nmh first; we fight for the users
22 # - In any case, finally error!(it)
26 # - open error (except ENOENT)
27 # Action: report, log, clean shutdown
29 # - either the bytes received were bytes expected or they weren't;
30 # context for logging is useful, but we don't need fine-grained types
31 # - this goes for nmh-folder-manager and IMAP protocols
32 # Action: report, log, clean shutdown
34 # A request is valid or not regardless of the state of the system.
36 # - UID FETCH without mailbox open - protocol violation: EXAMINE first
37 # - UID FETCH fred - `fred` is not a valid UID
38 # - In theory, this maps to IMAP `BAD response code, but can we rely on it?
39 # Action: Internal error, below
41 # A request must be valid before its legality may be judged.
43 # - FETCH 10 on mailbox with 9 messages - NO such message
44 # - EXAMINE nosuchmailbox - NO mailbox by that name exists
45 # - In theory, this maps to IMAP `NO response code, but can we rely on it?
46 # - These SHOULD only be caused by user action, e.g. create folder that already exists.
47 # Action: report, log, NO SHUTDOWN
49 # Action: report, log, clean shutdown
51 testname
=${0#$srcdir/}
53 if test -z "$MH_OBJ_DIR"; then
54 srcdir
=`dirname "$0"`/..
/..
55 MH_OBJ_DIR
=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
58 .
"$MH_OBJ_DIR/test/common.sh"
60 rm -rf "$MH_TEST_DIR/panda"
63 #### Save exit status to use as status for this program.
67 [ -n "$imapd_pid" ] && kill $imapd_pid
69 # TODO uh oops don't need two profiles for this one
71 set_mh_profile profile
$i
72 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
75 # TODO have cleanup allow additional cleanup registration?
76 # Or just allow it to accept status as argument.
81 covdir
="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
84 mkdir "$MH_TEST_DIR/panda"
85 mkdir "$MH_TEST_DIR/panda/test"
87 expected
="$MH_TEST_DIR/$$.expected"
88 actual
="$MH_TEST_DIR/$$.actual"
90 start_fakeinetd env
"HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
91 imapd_pid
=$fakeinetd_pid
94 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
96 LLVM_PROFILE_FILE
="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start
> "$actual" 2>&1 || status
=$?
99 # setup profile 2 and 1, leaving 1 as active profile
101 setup_test_without_data profile
$i
104 Managed-Folders: imap
105 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
106 imap-socket: $MH_TEST_DIR/profile$i/imap.d/socket
107 imap-db: $MH_TEST_DIR/profile$i/imap.d
109 imap-port: $fakeinetd_port
110 imap-tls: don't protect my data i know what i'm doing
112 imap-mailbox-root: test/
114 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
115 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
116 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
121 ################################################################################
122 start_test
'profile1: folder +imap/fold -create'
123 check_exit
'-eq 0' folder
+imap
/fold -create
125 ################################################################################
126 start_test
'profile2: folder +imap/fold -create'
128 set_mh_profile profile2
130 # TODO Oops folder -create when folder is already known LOCALLY to exist tries to create over IMAP!
132 cat > "$expected" <<EOF
133 folder: failed to create folder imap/fold: Can't create mailbox node $MH_TEST_DIR/panda/test/fold: File exists
137 folder
+imap
/fold -create > "$actual" 2>&1 || exitcode
=$?
138 check
"$actual" "$expected"
139 if [ $exitcode -ne 1 ]; then
140 fail
"folder exited $exitcode rather than 1"
143 ################################################################################
144 start_test
'profile2: inc +imap leaves imap/fold SELECTed'
147 ################################################################################
148 start_test
'profile1: rmf +imap/fold fails because profile1 has it SELECTED'
150 set_mh_profile profile1
152 rmf
+imap
/fold -nointeractive || status
=$?
153 if ! grep -q 'NO Mailbox test/fold is in use by another process' "$MH_TEST_DIR/$profile/imap.d/stderr"; then
154 cat "$MH_TEST_DIR/$profile/imap.d/stderr" >&2
155 fail
'mailbox deletion not disallowed'