]> diplodocus.org Git - nmh/blob - test/imap/test-live
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-live
1 #!/bin/sh
2
3 # Cyrus
4 # 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
5 # Dovecot
6 # 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
7 # Panda
8 # MH_IMAP_TEST_SERVER=panda make check TESTS=test/imap/test-live
9 # Gandi (looks like they use Dovecot)
10 # 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
11 # Gmail
12 # 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
13
14 testname=${0#$srcdir/}
15
16 if test -z "$MH_OBJ_DIR"; then
17 srcdir=`dirname "$0"`/../..
18 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
19 fi
20
21 . "$MH_OBJ_DIR/test/common.sh"
22
23 if [ -z "$MH_IMAP_TEST_SERVER" ]; then
24 test_skip 'no IMAP test server selected'
25 fi
26
27 start() {
28 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
29 status=0
30 LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start > "$actual" 2>&1 || status=$?
31 }
32
33 MH_template="$MH_TEST_DIR/template.mh_profile"
34 components_template="$MH_TEST_DIR/template.components"
35 scan_template="$MH_TEST_DIR/template.scan.nodate"
36
37 rm -f "$MH_template" "$components_template" "$scan_template"
38 rm -rf "$MH_TEST_DIR/dovecot" "$MH_TEST_DIR/panda"
39
40 rm -rf "$MH_TEST_DIR"/*/imap.d
41
42 imap_cleanup() {
43 #### Save exit status to use as status for this program.
44 status=$?
45 set +e
46
47 if [ -z "$MH_TEST_NOCLEANUP" ]; then
48 for i in $test_folders; do
49 rmf +$i -nointeractive
50 done
51 fi
52
53 [ -n "$imapd_pid" ] && kill $imapd_pid
54
55 for profile in $profiles; do
56 set_mh_profile $profile
57 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
58 done
59
60 # TODO have cleanup allow additional cleanup registration?
61 # Or just allow it to accept status as argument.
62 (exit $status)
63 cleanup
64 }
65
66 if [ "$MH_IMAP_TEST_SERVER" = 'panda' ]; then
67 # TODO It seems drafts are born unseen on Cyrus and GMail.
68 MH_IMAP_SERVER_DRAFT_BORN_UNSEEN=' '
69 # TODO Why is Cyrus eating the trailing CRLF?
70 # I'm planning to use refile -file instead of comp anyway; will that help?
71 MH_IMAP_SERVER_EATS_TRAILING_EOL=' '
72 [ -z "$LOGNAME" ] && fail 'LOGNAME not set'
73 MH_IMAP_TEST_EMAIL_ADDRESS="$LOGNAME"
74 mkdir "$MH_TEST_DIR/panda"
75 # Thought creating this stopped Panda from looking at the developer's real
76 # inbox, but it doesn't stop it from mangling /var/mail!
77 # TODO Ship customized Panda for testing.
78 touch "$MH_TEST_DIR/panda/mbox"
79 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
80 imapd_pid=$fakeinetd_pid
81 cat > "$MH_template" <<EOF
82 imap-host: 127.0.0.1
83 imap-port: $fakeinetd_port
84 imap-auth: PREAUTH
85 imap-tls: don't protect my data i know what i'm doing
86 imap-mailbox-root: test/
87 EOF
88 elif [ "$MH_IMAP_TEST_SERVER" = dovecot ]; then
89 # TODO dovecot "-Fc$MH_TEST_DIR/dovecot/cf"
90 # currently starting manually before running tests:
91 # rm -rf .o/std/dovecot && mkdir .o/std/dovecot && dovecot -Fcdocs/imap/testing/dovecot.conf &
92 cat > "$MH_TEST_DIR/dovecot/cf" <<EOF
93 base_dir = $MH_TEST_DIR/dovecot
94 state_dir = $MH_TEST_DIR/dovecot/db
95 log_path = $MH_TEST_DIR/dovecot/log
96
97 default_internal_user = $LOGNAME
98 default_login_user = $LOGNAME
99 default_internal_group = $LOGNAME
100
101 mail_location = mbox:$MH_TEST_DIR/dovecot/db/mail/%d/%1n/%n:INDEX=$MH_TEST_DIR/dovecot/db/indexes/%d/%1n/%n
102
103 protocols = imap
104 listen = 127.0.0.1
105
106 passdb {
107 driver = static
108 args = password=test
109 }
110
111 namespace inbox {
112 inbox = yes
113 }
114
115 service anvil {
116 chroot =
117 }
118
119 service imap-login {
120 chroot =
121 inet_listener imap {
122 port = 1043
123 }
124 inet_listener imaps {
125 port = 1044
126 }
127 }
128 EOF
129 elif [ "$MH_IMAP_TEST_SERVER" = 'gmail' ]; then
130 # * LIST (\All \HasNoChildren) "/" "[Gmail]/All Mail"
131 cat > "$MH_template" <<EOF
132 oauth-gmail-credential-file: $MH_IMAP_TEST_OAUTH_FILE
133 imap-host: imap.gmail.com
134 imap-port: imaps
135 imap-user: $MH_IMAP_TEST_USER
136 imap-tls: implicit
137 imap-auth: SASL
138 imap-saslmech: xoauth2
139 imap-authservice: gmail
140 EOF
141 if [ -n "$MH_IMAP_TEST_MAILBOX_ROOT" ]; then
142 echo "imap-mailbox-root: $MH_IMAP_TEST_MAILBOX_ROOT" >> "$MH_template"
143 fi
144 elif [ -z "$MH_IMAP_TEST_PORT" ] \
145 || [ -z "$MH_IMAP_TEST_TLS" ] \
146 || [ -z "$MH_IMAP_TEST_USER" ] \
147 || [ -z "$MH_IMAP_TEST_PASSWORD" ] \
148 || [ -z "$MH_IMAP_TEST_EMAIL_ADDRESS" ]; then
149 fail 'MH_IMAP_TEST_PORT MH_IMAP_TEST_USER MH_IMAP_TEST_PASSWORD MH_IMAP_TEST_EMAIL_ADDRESS must all be set'
150 else
151 case $MH_IMAP_TEST_TLS in
152 no)
153 MH_IMAP_TEST_TLS="don't protect my data i know what i'm doing"
154 ;;
155 unverified-implicit)
156 MH_IMAP_TEST_TLS="implicit but don't verify the cert i already did out of band"
157 ;;
158 esac
159 cat > "$MH_TEST_DIR/netrc" <<EOF
160 machine $MH_IMAP_TEST_SERVER login $MH_IMAP_TEST_USER password $MH_IMAP_TEST_PASSWORD
161 EOF
162 cat >> "$MH_template" <<EOF
163 credentials: file-nopermcheck:$MH_TEST_DIR/netrc
164 imap-host: $MH_IMAP_TEST_SERVER
165 imap-port: $MH_IMAP_TEST_PORT
166 imap-user: $MH_IMAP_TEST_USER
167 imap-auth: SASL
168 imap-tls: $MH_IMAP_TEST_TLS
169 EOF
170 if [ -n "$MH_IMAP_TEST_MAILBOX_ROOT" ]; then
171 echo "imap-mailbox-root: $MH_IMAP_TEST_MAILBOX_ROOT" >> "$MH_template"
172 fi
173 fi
174
175 # it seems with cyrus everything has to go under INBOX? i probably
176 # messed something up but whatever, let's roll with it.
177 # * LIST (\HasChildren) "/" INBOX
178 #* LIST (\HasNoChildren) "/" INBOX/foo
179
180 imap_folder=imap/imap$(date '+%j%H%M%S')
181
182 cat >> "$MH_template" <<EOF
183 Unseen-Sequence: unseen
184 Local-Mailbox: $MH_IMAP_TEST_EMAIL_ADDRESS
185 Draft-Folder: $imap_folder/drafts
186 Managed-Folders: imap
187 rmm: -unlink
188 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
189 EOF
190
191 cat > "$scan_template" <<EOF
192 %4(msg)%<(cur)+%| %>%<(unseen)U%| %>%<{replied}-%| %>\
193 %<(mymbox{from})%<{to}To:%(unquote(decode(friendly{to})))%>%>\
194 %<(zero)%(unquote(decode(friendly{from})))%> \
195 %(decode{subject})%<{body}<<%{body}>>%>
196 EOF
197
198 # TODO default components use '--------' to close header...
199 cat > "$components_template" <<EOF
200 %<{from}%|%(void(localmbox))%>%(void(width))%(putaddr From: )
201 %<{to}%(void(width))%(putaddr To: )%|To:%>
202 %<{cc}%(void(width))%(putaddr cc: )%|cc:%>
203 Fcc: %<{fcc}%(putstr)%|+outbox%>
204 Subject:%<{subject} %(putstr)%>
205
206 body
207 EOF
208
209 expected="$MH_TEST_DIR/$$.expected"
210 actual="$MH_TEST_DIR/$$.actual"
211
212 ################################################################################
213 profile=profile1
214 rm -rf "$MH_TEST_DIR/$profile"
215 setup_test_without_data $profile
216 trap imap_cleanup 0
217
218 cat "$MH_template" >> "$MH"
219 cp "$components_template" "$MH_TEST_DIR/$profile/components"
220 cp "$scan_template" "$MH_TEST_DIR/$profile/scan.nodate"
221 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
222 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
223 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
224 fi
225
226 # Set this for the EHLO command
227 echo "clientname: nosuchhost.example.com" >> "$MHMTSCONF"
228
229 cat >> "$MH" <<EOF
230 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
231 imap-db: $MH_TEST_DIR/$profile/imap.d
232 EOF
233
234 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
235 install -d "$covdir"
236
237 start
238 ################################################################################
239
240 ################################################################################
241 start_test 'folder -create'
242
243 cat > "$expected" <<EOF
244 $imap_folder/drafts+ has no messages.
245 $imap_folder/sent+ has no messages.
246 EOF
247 test_folders="$imap_folder/drafts $imap_folder/sent"
248 (run_prog folder +$imap_folder/drafts -create \
249 && run_prog folder +$imap_folder/sent -create) > "$actual"
250 check "$actual" "$expected"
251
252 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
253 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent
254
255 ################################################################################
256 start_test 'inc when nothing to fetch'
257
258 cat /dev/null > "$expected"
259 check_exit '-eq 0' inc +imap -width 80
260
261 ################################################################################
262 start_test 'comp creates draft in empty draft folder'
263
264 check_exit '-eq 0' comp -noedit -to "$MH_IMAP_TEST_EMAIL_ADDRESS" -fcc $imap_folder/sent -subject 'testing imap' -nowhatnowproc
265
266 # comp creates a message, stores a UID/msgnum pair, runs the user's editor,
267 # creates a new message with the user's edits, and replaces the UID/msgnum pair.
268 # So verify the integrity of the database after that.
269 # TODO any other operations worth having this integrity check on?
270 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
271
272 start_test 'scan drafts after comp'
273 cat > "$expected" <<EOF
274 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body >>
275 EOF
276 run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual"
277 check "$actual" "$expected"
278
279 start_test 'show draft after comp'
280 cat > "$expected" <<EOF
281 (Message $imap_folder/drafts:1)
282
283 To: $MH_IMAP_TEST_EMAIL_ADDRESS
284 cc:
285 From: $MH_IMAP_TEST_EMAIL_ADDRESS
286 Subject: testing imap
287
288 Fcc: $imap_folder/sent
289
290 body
291 EOF
292 run_prog show +$imap_folder/drafts 1 > "$actual"
293 check "$actual" "$expected"
294
295 start_test 'check .mh_sequences after show after comp'
296 cat > "$expected" <<EOF
297 cur: 1
298 EOF
299 check "$MH_TEST_DIR/$profile/$imap_folder/drafts/.mh_sequences" "$expected" 'keep first'
300
301 ################################################################################
302 start_test 'comp creates draft in non-empty draft folder'
303
304 check_exit '-eq 0' comp -noedit -to "$MH_IMAP_TEST_EMAIL_ADDRESS" -fcc $imap_folder/sent -subject 'testing imap 2' -nowhatnowproc
305
306 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
307
308 start_test 'scan non-empty drafts after comp'
309 cat > "$expected" <<EOF
310 1+ To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body >>
311 2 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body >>
312 EOF
313 run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual"
314 check "$actual" "$expected"
315
316 start_test 'check .mh_sequences after non-empty comp'
317 cat > "$expected" <<EOF
318 nmh-picked: 1-2
319 cur: 1
320 EOF
321 check "$MH_TEST_DIR/$profile/$imap_folder/drafts/.mh_sequences" "$expected" 'keep first'
322
323 ################################################################################
324 start_test 'send refiles draft to fcc folder'
325
326 arith_eval 64000 + $$ % 1000
327 localport=$arith_val
328 "$MH_OBJ_DIR/test/fakesmtp" /dev/null $localport > /dev/null
329 check_exit '-eq 0' send -server 127.0.0.1 -port $localport -draftfolder $imap_folder/drafts
330 rm -f "$actual"
331
332 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
333 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent
334
335 # TODO what?! this test started out as this and evolved into something else?
336 start_test 'scan drafts finds no messages after send'
337
338 # Check draft moved to FCC folder
339 cat > "$expected" <<EOF
340 2 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body >>
341 EOF
342 run_prog scan -form scan.nodate +$imap_folder/drafts -width 80 > "$actual"
343 check "$actual" "$expected"
344
345 start_test 'scan sent finds the sent messages after send'
346
347 cat > "$expected" <<EOF
348 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body >>
349 EOF
350 run_prog scan -form scan.nodate +$imap_folder/sent -width 80 > "$actual"
351 check "$actual" "$expected"
352
353 ################################################################################
354 profile=profile2
355 rm -rf "$MH_TEST_DIR/$profile"
356 setup_test_without_data $profile
357 trap imap_cleanup 0
358
359 cat "$MH_template" >> "$MH"
360 cp "$components_template" "$MH_TEST_DIR/$profile/components"
361 cp "$scan_template" "$MH_TEST_DIR/$profile/scan.nodate"
362 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
363 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
364 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
365 fi
366
367 cat >> "$MH" <<EOF
368 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
369 imap-db: $MH_TEST_DIR/$profile/imap.d
370 EOF
371
372 start
373 ################################################################################
374
375 ################################################################################
376 start_test 'inc on empty managed folder fetches all mail in that folder'
377
378 cat > "$expected" <<EOF
379 Incorporating new mail into $imap_folder/drafts...
380
381 1 $MH_IMAP_SERVER_DRAFT_BORN_UNSEEN To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
382 Incorporating new mail into $imap_folder/sent...
383
384 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
385 EOF
386
387 inc +imap -form scan.nodate -width 80 > "$actual"
388 check "$actual" "$expected"
389
390 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
391 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent
392
393 ################################################################################
394 start_test 'show the sent message after inc'
395
396 cat > "$expected" <<EOF
397 (Message $imap_folder/sent:1)
398
399 Date:
400 To: $MH_IMAP_TEST_EMAIL_ADDRESS
401 From: $MH_IMAP_TEST_EMAIL_ADDRESS
402 Subject: testing imap
403
404 MIME-Version: 1.0
405
406
407 EOF
408 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
409 echo 'body ' >> "$expected"
410 else
411 echo -n body >> "$expected"
412 fi
413
414 run_prog show +$imap_folder/sent 1 > "$actual"
415 sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate
416 rm -f "$actual"
417 check "$actual.nodate" "$expected"
418
419 ################################################################################
420 start_test 'mark the sent message unseen'
421
422 check_exit '-eq 0' mark -add -seq unseen +$imap_folder/sent 1
423
424 start_test 'scan after mark unseen'
425
426 cat > "$expected" <<EOF
427 1+U To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
428 EOF
429 run_prog scan -form scan.nodate -width 80 > "$actual"
430 check "$actual" "$expected"
431
432 ################################################################################
433 start_test 'show the now-unseen message'
434
435 check_exit '-eq 0' show all
436
437 start_test 'scan after show'
438
439 cat > "$expected" <<EOF
440 1+ To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
441 EOF
442 run_prog scan -form scan.nodate -width 80 > "$actual"
443 check "$actual" "$expected"
444
445 ################################################################################
446 start_test 'refile -file'
447
448 refiled_file="$MH_TEST_DIR/$$.refiled-file"
449 cat > "$refiled_file" <<EOF
450 Date:Sat, 24 Oct 2020 19:20:38 -0500
451 from:me
452 to:you
453
454 refile-test
455 EOF
456 check_exit '-eq 0' refile -file "$refiled_file" +$imap_folder/drafts
457 if [ -e "$refiled_file" ]; then
458 rm -f "$refiled_file" || :
459 fail "$refiled_file missing after refile"
460 fi
461
462 start_test 'scan dst folder after refile -file finds refiled message'
463
464 cat > "$expected" <<EOF
465 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
466 2 me <<refile-test >>
467 EOF
468 scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual"
469 check "$actual" "$expected"
470
471 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
472
473 ################################################################################
474 start_test 'refile'
475
476 check_exit '-eq 0' refile -src +$imap_folder/drafts 2 +$imap_folder/sent
477
478 # TODO what?! this test started out as this and evolved into something else?
479 start_test 'scan src folder after refile finds no messages'
480
481 cat > "$expected" <<EOF
482 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
483 EOF
484 scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual"
485 check "$actual" "$expected"
486
487 start_test 'scan dst folder after refile finds refiled message'
488
489 cat > "$expected" <<EOF
490 1+ To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
491 2 me <<refile-test >>
492 EOF
493 scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual"
494 check "$actual" "$expected"
495
496 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/drafts
497 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent
498
499 ################################################################################
500 start_test 'mark unseen after refile'
501
502 # This tests the UID update in the local database.
503
504 check_exit '-eq 0' mark -add -seq unseen 2
505 cat > "$expected" <<EOF
506 1+ To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
507 2 U me <<refile-test >>
508 EOF
509 scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual"
510 check "$actual" "$expected"
511
512 ################################################################################
513 start_test 'show all before rmm'
514
515 cat > "$expected" <<EOF
516 >>> $imap_folder/sent:1
517
518
519 Date:
520 To: $MH_IMAP_TEST_EMAIL_ADDRESS
521 From: $MH_IMAP_TEST_EMAIL_ADDRESS
522 Subject: testing imap
523
524 MIME-Version: 1.0
525
526
527 EOF
528 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
529 echo 'body ' >> "$expected"
530 else
531 echo -n body >> "$expected"
532 fi
533 cat >> "$expected" <<EOF
534
535
536
537 >>> $imap_folder/sent:2
538
539
540 Date:
541 To: you
542 From: me
543
544
545 EOF
546 # TODO Why is this one unaffected?! Really need to get to the bottom of this...
547 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
548 echo refile-test >> "$expected"
549 else
550 echo refile-test >> "$expected"
551 fi
552
553 run_prog show +$imap_folder/sent all > "$actual"
554 sed -e 's/^Date:.*/Date:/' "$actual" > "$actual.nodate"
555 rm -f "$actual"
556 check "$actual.nodate" "$expected"
557
558 start_test 'check .mh_sequences after show before rmm'
559 cat > "$expected" <<EOF
560 cur: 2
561 EOF
562 check "$MH_TEST_DIR/$profile/$imap_folder/sent/.mh_sequences" "$expected" 'keep first'
563
564 ################################################################################
565 start_test 'show cur shows 2 after show all'
566
567 cat > "$expected" <<EOF
568 (Message $imap_folder/sent:2)
569
570 Date: Sat, 24 Oct 2020 19:20:38 -0500
571 To: you
572 From: me
573
574
575 EOF
576 # TODO Why is this one unaffected?! Really need to get to the bottom of this...
577 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
578 echo refile-test >> "$expected"
579 else
580 echo refile-test >> "$expected"
581 fi
582
583 run_prog show +$imap_folder/sent > "$actual"
584 check "$actual" "$expected"
585
586 start_test 'check .mh_sequences after show cur shows 2 after show all'
587 cat > "$expected" <<EOF
588 cur: 2
589 EOF
590 check "$MH_TEST_DIR/$profile/$imap_folder/sent/.mh_sequences" "$expected" 'keep first'
591
592 ################################################################################
593 start_test 'show 1 before rmm'
594
595 cat > "$expected" <<EOF
596 (Message $imap_folder/sent:1)
597
598 Date:
599 To: $MH_IMAP_TEST_EMAIL_ADDRESS
600 From: $MH_IMAP_TEST_EMAIL_ADDRESS
601 Subject: testing imap
602
603 MIME-Version: 1.0
604
605
606 EOF
607 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
608 echo 'body ' >> "$expected"
609 else
610 echo -n body >> "$expected"
611 fi
612
613 run_prog show +$imap_folder/sent 1 > "$actual"
614 sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate
615 rm -f "$actual"
616 check "$actual.nodate" "$expected"
617
618 start_test 'check .mh_sequences after show 1 before rmm'
619 cat > "$expected" <<EOF
620 cur: 1
621 EOF
622 check "$MH_TEST_DIR/$profile/$imap_folder/sent/.mh_sequences" "$expected" 'keep first'
623
624 ################################################################################
625 start_test 'show cur shows 1 after show 1'
626
627 cat > "$expected" <<EOF
628 (Message $imap_folder/sent:1)
629
630 Date:
631 To: $MH_IMAP_TEST_EMAIL_ADDRESS
632 From: $MH_IMAP_TEST_EMAIL_ADDRESS
633 Subject: testing imap
634
635 MIME-Version: 1.0
636
637
638 EOF
639 if [ -n "$MH_IMAP_SERVER_EATS_TRAILING_EOL" ]; then
640 echo 'body ' >> "$expected"
641 else
642 echo -n body >> "$expected"
643 fi
644
645 run_prog show +$imap_folder/sent > "$actual"
646 sed -e 's/^Date:.*/Date:/' "$actual" > "$actual".nodate
647 rm -f "$actual"
648 check "$actual.nodate" "$expected"
649
650 start_test 'check .mh_sequences after show cur shows 1 after show 1'
651 cat > "$expected" <<EOF
652 cur: 1
653 EOF
654 check "$MH_TEST_DIR/$profile/$imap_folder/sent/.mh_sequences" "$expected" 'keep first'
655
656 ################################################################################
657 start_test 'rmm'
658
659 check_exit '-eq 0' rmm -unlink 2
660
661 start_test 'scan after rmm'
662
663 cat > "$expected" <<EOF
664 1+ To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
665 EOF
666 scan -form scan.nodate -width 80 +$imap_folder/sent > "$actual"
667 check "$actual" "$expected"
668
669 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $imap_folder/sent
670
671 ################################################################################
672 start_test 'inc finds messages to delete 1. create messages in profile2'
673
674 for i in 2 3 4 5 6; do
675 refiled_file="$MH_TEST_DIR/$$.refiled-file"
676 cat > "$refiled_file" <<EOF
677 Date:Sat, 24 Oct 2020 19:20:38 -0500
678 from:me
679 to:you
680 subject: refile $i
681
682 refile-test $i
683 EOF
684 check_exit '-eq 0' refile -file "$refiled_file" +$imap_folder/drafts
685 if [ -e "$refiled_file" ]; then
686 rm -f "$refiled_file" || :
687 fail "$refiled_file missing after refile"
688 fi
689 done
690
691 cat > "$expected" <<EOF
692 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
693 2 me refile 2<<refile-test 2 >>
694 3 me refile 3<<refile-test 3 >>
695 4 me refile 4<<refile-test 4 >>
696 5 me refile 5<<refile-test 5 >>
697 6 me refile 6<<refile-test 6 >>
698 EOF
699 scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual"
700 check "$actual" "$expected"
701
702 for i in $test_folders; do
703 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $i
704 done
705
706 ################################################################################
707 start_test 'inc finds messages to delete 2. inc new messages into profile1'
708
709 set_mh_profile profile1
710
711 # Message numbers are one greater in profile1 than in profile2.
712 cat > "$expected" <<EOF
713 Incorporating new mail into $imap_folder/drafts...
714
715 3 me refile 2<<refile-test 2$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
716 4 me refile 3<<refile-test 3$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
717 5 me refile 4<<refile-test 4$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
718 6 me refile 5<<refile-test 5$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
719 7 me refile 6<<refile-test 6$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
720 EOF
721 inc +imap -form scan.nodate -width 80 > "$actual" || :
722 check "$actual" "$expected"
723
724 ################################################################################
725 start_test 'inc finds messages to delete 3. rmm messages out of profile2'
726
727 set_mh_profile profile2
728
729 check_exit '-eq 0' rmm -unlink 2
730 check_exit '-eq 0' rmm -unlink 4
731 check_exit '-eq 0' rmm -unlink 5
732
733 cat > "$expected" <<EOF
734 1 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
735 3 me refile 3<<refile-test 3 >>
736 6 me refile 6<<refile-test 6 >>
737 EOF
738 scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual"
739 check "$actual" "$expected"
740
741 ################################################################################
742 start_test 'inc finds messages to delete 4. inc deletes from profile1'
743
744 set_mh_profile profile1
745
746 inc +imap -form scan.nodate -width 80 > "$actual" || :
747 check /dev/null "$actual" 'keep first'
748
749 ################################################################################
750 start_test 'inc finds messages to delete 5. scan profile1 to see messages gone'
751
752 # Message numbers are one greater in profile1 than in profile2.
753 cat > "$expected" <<EOF
754 2 To:$MH_IMAP_TEST_EMAIL_ADDRESS testing imap 2<<body >>
755 4 me refile 3<<refile-test 3$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
756 7 me refile 6<<refile-test 6$MH_IMAP_SERVER_EATS_TRAILING_EOL>>
757 EOF
758 scan -form scan.nodate -width 80 +$imap_folder/drafts > "$actual"
759 check "$actual" "$expected"
760
761 # TODO tests:
762 # - refile old message into a folder with newer messages: UID validity preserved?
763
764 ################################################################################
765 start_test 'check all folder databases one last time'
766
767 for profile in $profiles; do
768 set_mh_profile $profile
769 for i in $test_folders; do
770 check_exit '-eq 0' "$MH_OBJ_DIR/target/debug/mhimap" imap check $i
771 done
772 done
773
774 finish_test
775 exit ${failed:-0}