]> diplodocus.org Git - nmh/blob - test/imap/test-uidvalidity
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-uidvalidity
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 # TODO uh oops don't need two profiles for this one
22 for i in 1 2; do
23 set_mh_profile profile$i
24 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
25 done
26
27 if [ -z "$MH_TEST_NOCLEANUP" ]; then
28 rm -rf "$MH_TEST_DIR/panda"
29 for i in 1 2; do
30 rm -rf "$MH_TEST_DIR/profile$i"
31 done
32 fi
33
34 # TODO have cleanup allow additional cleanup registration?
35 # Or just allow it to accept status as argument.
36 (exit $status)
37 cleanup
38 }
39
40 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
41 install -d "$covdir"
42
43 mkdir "$MH_TEST_DIR/panda"
44 mkdir "$MH_TEST_DIR/panda/test"
45
46 expected="$MH_TEST_DIR/$$.expected"
47 actual="$MH_TEST_DIR/$$.actual"
48
49 uidvalidity=1503585238
50 cat > $MH_TEST_DIR/panda/test/fold <<EOF
51 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
52 Date:Sat, 24 Oct 2020 19:20:38 -0500
53 from:me
54 to:you
55 X-IMAPbase: $uidvalidity 1 testseq
56 Status: RO
57 X-Status:
58 X-Keywords:
59 X-UID: 1
60
61 body
62
63 EOF
64
65 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
66 imapd_pid=$fakeinetd_pid
67
68 start() {
69 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
70 status=0
71 LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start > "$actual" 2>&1 || status=$?
72 }
73
74 # setup profile 2 and 1, leaving 1 as active profile
75 for i in 2 1; do
76 setup_test_without_data profile$i
77 trap imap_cleanup 0
78 cat >> "$MH" <<EOF
79 Managed-Folders: imap
80 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
81 imap-socket: $MH_TEST_DIR/profile$i/imap.d/socket
82 imap-db: $MH_TEST_DIR/profile$i/imap.d
83 imap-host: 127.0.0.1
84 imap-port: $fakeinetd_port
85 imap-tls: don't protect my data i know what i'm doing
86 imap-auth: PREAUTH
87 imap-mailbox-root: test/
88 EOF
89 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
90 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
91 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
92 fi
93 start
94 done
95
96 ################################################################################
97 start_test '1. inc from profile1'
98
99 echo 'Incorporating new mail into imap/fold...' > "$expected.inc"
100 echo >> "$expected.inc"
101 printf ' 1 10/24 me <<body >>\n' >> "$expected.inc"
102
103 inc +imap -form scan.unseen -width 80 > "$actual"
104 check "$actual" "$expected.inc"
105
106 ################################################################################
107 # 2. rebuild mailbox
108 uidvalidity=1603585238
109 cat > $MH_TEST_DIR/panda/test/fold <<EOF
110 From nmh@example.com Sat Oct 25 19:20:38 2020 -0500
111 Date:Sat, 25 Oct 2020 19:20:38 -0500
112 from:me
113 to:you
114 X-IMAPbase: $uidvalidity 1 testseq
115 Status: RO
116 X-Status:
117 X-Keywords:
118 X-UID: 1
119
120 body
121
122 EOF
123
124 ################################################################################
125 start_test '3. inc after rebuilt mailbox goes BOOM'
126
127 # Kill the folder manager so inc will cause a re-SELECT.
128 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
129
130 # TODO plumb this error out to inc
131
132 check_exit '-eq 1' inc +imap
133 if ! grep -q 'UIDVALIDITY changed' "$MH_TEST_DIR/profile$i/imap.d/stderr"; then
134 cat "$MH_TEST_DIR/profile$i/imap.d/stderr" >&2
135 fail "'UIDVALIDITY changed' not in $MH_TEST_DIR/profile$i/imap.d/stderr"
136 fi
137
138 finish_test
139 exit ${failed:-0}