]> diplodocus.org Git - nmh/blob - test/imap/test-refile
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-refile
1 #!/bin/sh
2
3 # TODO this must have bitrotted to oblivion...
4
5 testname=${0#$srcdir/}
6
7 # setup copied from test-scan
8
9 if test -z "$MH_OBJ_DIR"; then
10 srcdir=`dirname "$0"`/../..
11 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
12 fi
13
14 . "$MH_OBJ_DIR/test/common.sh"
15
16 setup_test_without_data Mail
17
18 rm -rf "$MH_TEST_DIR/panda"
19
20 imap_cleanup() {
21 #### Save exit status to use as status for this program.
22 status=$?
23 set +e
24
25 [ -n "$imapd_pid" ] && kill $imapd_pid
26 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
27
28 # TODO have cleanup allow additional cleanup registration?
29 # Or just allow it to accept status as argument.
30 (exit $status)
31 cleanup
32 }
33 trap imap_cleanup 0
34
35 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
36 install -d "$covdir"
37 export LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw"
38
39 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
40 imapd_pid=$fakeinetd_pid
41
42 # TODO imap-manager: $MH_LIBEXEC_DIR/folder-managers/imap
43 # TODO imap-socket: relative path
44 # TODO can we come up with reasonable default of socket path?
45 cat >> "$MH" <<EOF
46 Managed-Folders: imap
47 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
48 imap-socket: $MH_TEST_DIR/Mail/imap.d/socket
49 imap-db: $MH_TEST_DIR/Mail/imap.d
50 imap-host: 127.0.0.1
51 imap-port: $fakeinetd_port
52 imap-auth: PREAUTH
53 imap-tls: don't protect my data i know what i'm doing
54 imap-mailbox-root: test/
55 EOF
56 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
57 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
58 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
59 fi
60
61 mkdir "$MH_TEST_DIR/panda"
62 mkdir "$MH_TEST_DIR/panda/test"
63
64 expected="$MH_TEST_DIR/$$.expected"
65 actual="$MH_TEST_DIR/$$.actual"
66
67 for i in 1 2 3; do
68 cat > "$MH_TEST_DIR/panda/test/fold$i" <<EOF
69 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
70 Date:Sat, 24 Oct 2020 19:20:38 -0500
71 from:me
72 to:you
73 X-IMAPbase: 1603585238 1
74 Status: RO
75 X-Status:
76 X-Keywords:
77 X-UID: 1
78
79 initial message in fold$i
80
81 EOF
82 done
83
84 start_test 'initial inc'
85
86 cat > "$expected.inc" <<EOF
87 Incorporating new mail into imap/fold1...
88
89 1 10/24 me <<initial message in fold1 >>
90 Incorporating new mail into imap/fold2...
91
92 1 10/24 me <<initial message in fold2 >>
93 Incorporating new mail into imap/fold3...
94
95 1 10/24 me <<initial message in fold3 >>
96 EOF
97
98 inc +imap > "$actual"
99 check "$actual" "$expected.inc"
100
101 ################################################################################
102 start_test 'refile'
103
104 check_exit '-eq 0' refile -src +imap/fold1 1 +imap/fold2
105
106 start_test 'scan src folder after refile finds no messages'
107
108 cat > "$expected" <<EOF
109 scan: no messages match specification
110 EOF
111 scan -width 80 +imap/fold1 > "$actual" 2>&1 || :
112 check "$actual" "$expected"
113
114 start_test 'scan dst folder after refile finds refiled message'
115
116 cat > "$expected" <<EOF
117 1 10/24 me <<initial message in fold2 >>
118 2+ 10/24 me <<initial message in fold1 >>
119 EOF
120 scan -width 80 +imap/fold2 > "$actual"
121 check "$actual" "$expected"
122
123 ################################################################################
124 start_test 'refile -link -file'
125
126 refiled_file="$MH_TEST_DIR/$$.refiled-file"
127 cat > "$refiled_file" <<EOF
128 Date:Sat, 24 Oct 2020 19:20:38 -0500
129 from:me
130 to:you
131
132 refile-link file
133 EOF
134 check_exit '-eq 0' refile -link -file "$refiled_file" +imap/fold1
135 if [ -e "$refiled_file" ]; then
136 rm "$refiled_file"
137 else
138 fail "$refiled_file missing after refile -link"
139 fi
140
141 start_test 'scan dst folder after refile -link -file finds refiled message'
142
143 cat > "$expected" <<EOF
144 1+ 10/24 me <<refile-link file >>
145 EOF
146 scan -width 80 +imap/fold1 > "$actual"
147 check "$actual" "$expected"
148
149 ################################################################################
150 start_test 'refile -file'
151
152 refiled_file="$MH_TEST_DIR/$$.refiled-file"
153 cat > "$refiled_file" <<EOF
154 Date:Sat, 24 Oct 2020 19:20:38 -0500
155 from:me
156 to:you
157
158 refiled file
159 EOF
160 check_exit '-eq 0' refile -file "$refiled_file" +imap/fold3
161 if [ -e "$refiled_file" ]; then
162 rm -f "$refiled_file" || :
163 fail "$refiled_file missing after refile"
164 fi
165
166 start_test 'scan dst folder after refile -file finds refiled message'
167
168 cat > "$expected" <<EOF
169 1 10/24 me <<initial message in fold3 >>
170 2+ 10/24 me <<refiled file >>
171 EOF
172 scan -width 80 +imap/fold3 > "$actual"
173 check "$actual" "$expected"
174
175 ################################################################################
176 start_test 'rebuild local from scratch'
177
178 rm -rf "$MH_TEST_DIR/Mail/imap" "$MH_TEST_DIR/Mail/imap.d/imap"
179
180 cat > "$expected.inc" <<EOF
181 Incorporating new mail into imap/fold1...
182
183 1 10/24 me <<refile-link file >>
184 Incorporating new mail into imap/fold2...
185
186 1 10/24 me <<initial message in fold2 >>
187 2 10/24 me <<initial message in fold1 >>
188 Incorporating new mail into imap/fold3...
189
190 1 10/24 me <<initial message in fold3 >>
191 2 10/24 me <<refiled file >>
192 EOF
193
194 inc +imap > "$actual"
195 check "$actual" "$expected.inc"
196
197 finish_test
198 exit ${failed:-0}