interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / tests / scenarios / 60-imap.txt

289 lines · 20056 bytes Raw Blame History
1# IMAP sync (ImapSync): mailhand sync against the fake IMAP server "srv imap" (tests/srv/imap.om),
2# over real TLS 1.3 (omtls from DEPS; host name mail.test, the omtls test certificates). Synthetic mail only.
3# Each server run picks a random loopback port in 19000..19999; "srv acct" waits for it and writes
4# the accounts file (mode 0600, "connect 127.0.0.1"). Maildir names are deterministic:
5# INTERNALDATE.V<UIDVALIDITY>U<UID>F<first 8 hex of SHA-256(local folder name)>.mailhand
6# INTERNALDATE "05-Nov-2026 12:00:00 +0100" = 1793876400 (Wolfram: UnixTime of 2026-11-05 11:00 UTC);
7# SHA-256 prefixes: INBOX 83ecb521, Work 104ab921, Lists.Omega 2a0fa0bb.
8mkdir @S/Mail
9run 0 - -- mh setup --home @S/h --maildir @S/Mail --me alice@example.test --name Alice
10# the credentials live outside the homes here (config "accounts PATH"), so the leak scan below can
11# cover every file under the homes; 55-creds checks the default HOME/accounts
12mkdir @S/c
13append @S/h/config accounts @S/c/accounts\n
14
15#
16# first_sync: two new messages; the \Seen one goes to cur/ with :2,S, the other to new/;
17# the bytes are the server's bytes; AUTHENTICATE PLAIN with SASL-IR over TLS
18mkdir @S/s1
19write @S/s1/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nbox Archive 9\nbox Work 11\nmsg INBOX 1 S @R/tests/fixtures/imap/m1.eml\nmsg INBOX 2 - @R/tests/fixtures/imap/m2.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
20bg srv imap @S/s1
21run 0 - -- srv acct @S/c/accounts @S/s1 work imaps mail.test alice@example.test s3cret-SYNTH-pw 600
22run 0 - -- mh sync --home @S/h --account work
23out-has "op":"sync","folder":"INBOX","ok":true,"uidvalidity":7,"fetched":2,"flags_pushed":0,"moves_pushed":0
24out-not s3cret-SYNTH-pw
25err-not s3cret-SYNTH-pw
26wait 0
27file-eq @S/Mail/cur/1793876400.V7U1F83ecb521.mailhand:2,S tests/fixtures/imap/m1.eml
28file-eq @S/Mail/new/1793876400.V7U2F83ecb521.mailhand tests/fixtures/imap/m2.eml
29file-has @S/Mail/mailhand-imap uidvalidity 7
30file-has @S/Mail/mailhand-imap last 2
31file-has @S/Mail/mailhand-imap m 1 1793876400.V7U1F83ecb521.mailhand S
32file-has @S/Mail/mailhand-imap m 2 1793876400.V7U2F83ecb521.mailhand -
33file-has @S/s1/log AUTH OK
34file-has @S/s1/log A5 UID FETCH 1:* (FLAGS)
35file-has @S/s1/log A6 UID FETCH 1 (UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[])
36run 0 - -- mh list --home @S/h
37out-has Lunch on Friday
38out-has Report {draft} (v2)
39#
40# push_back: mark-read and move locally, then sync: UID STORE +FLAGS.SILENT and UID MOVE (with
41# COPYUID: the destination's state gets a "c" record); a new \Flagged message lands in cur/ :2,F
42run 0 - -- mh mark-read --home @S/h --id INBOX/1793876400.V7U2F83ecb521.mailhand
43run 0 - -- mh move --home @S/h --id INBOX/1793876400.V7U1F83ecb521.mailhand --folder Archive
44mkdir @S/s2
45write @S/s2/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nbox Archive 9\nbox Work 11\nmsg INBOX 1 S @R/tests/fixtures/imap/m1.eml\nmsg INBOX 2 - @R/tests/fixtures/imap/m2.eml\nmsg INBOX 3 F @R/tests/fixtures/imap/m3.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
46bg srv imap @S/s2
47run 0 - -- srv acct @S/c/accounts @S/s2 work imaps mail.test alice@example.test s3cret-SYNTH-pw 600
48run 0 - -- mh sync --home @S/h --account work
49out-has "fetched":1,"flags_pushed":1,"moves_pushed":1
50wait 0
51file-has @S/s2/log A5 UID MOVE 1 "Archive"
52file-has @S/s2/log A6 UID STORE 2 +FLAGS.SILENT (\Seen)
53file-has @S/s2/log A7 UID FETCH 3:* (FLAGS)
54file-has @S/s2/state.out msg Archive 1 S
55file-has @S/s2/state.out msg INBOX 2 S
56file-eq @S/Mail/cur/1793876400.V7U3F83ecb521.mailhand:2,F tests/fixtures/imap/m3.eml
57file-has @S/Mail/.Archive/mailhand-imap c 9 1 1793876400.V7U1F83ecb521.mailhand S
58file-not @S/Mail/mailhand-imap V7U1F
59file-has @S/Mail/mailhand-imap m 2 1793876400.V7U2F83ecb521.mailhand S
60#
61# copyuid_adopt: syncing Archive turns the "c" record into an "m" record: nothing is fetched twice
62mkdir @S/s3
63write @S/s3/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nbox Archive 9\nmsg Archive 1 S @R/tests/fixtures/imap/m1.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
64bg srv imap @S/s3
65run 0 - -- srv acct @S/c/accounts @S/s3 work imaps mail.test alice@example.test s3cret-SYNTH-pw 600
66run 0 - -- mh sync --home @S/h --account work --folder Archive
67out-has "folder":"Archive","ok":true,"uidvalidity":9,"fetched":0
68wait 0
69file-has @S/Mail/.Archive/mailhand-imap m 1 1793876400.V7U1F83ecb521.mailhand S
70file-not @S/s3/log BODY.PEEK
71#
72# move_uidplus: no MOVE, UIDPLUS: UID COPY, UID STORE \Deleted, UID EXPUNGE of that UID only;
73# no SASL-IR: AUTHENTICATE PLAIN answers the server's continuation
74run 0 - -- mh move --home @S/h --id INBOX/1793876400.V7U3F83ecb521.mailhand --folder Work
75mkdir @S/s4
76write @S/s4/state caps IMAP4rev1 AUTH=PLAIN UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nbox Work 11\nmsg INBOX 2 S @R/tests/fixtures/imap/m2.eml\nmsg INBOX 3 F @R/tests/fixtures/imap/m3.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
77bg srv imap @S/s4
78run 0 - -- srv acct @S/c/accounts @S/s4 work imaps mail.test alice@example.test s3cret-SYNTH-pw 600
79run 0 - -- mh sync --home @S/h --account work
80out-has "moves_pushed":1
81out-not "risk"
82wait 0
83file-has @S/s4/log AUTH OK
84file-has @S/s4/log UID COPY 3 "Work"
85file-has @S/s4/log UID STORE 3 +FLAGS.SILENT (\Deleted)
86file-has @S/s4/log UID EXPUNGE 3
87file-has @S/s4/state.out msg Work 1 F
88file-has @S/Mail/.Work/mailhand-imap c 11 1 1793876400.V7U3F83ecb521.mailhand F
89#
90# move_no_uidplus: no MOVE, no UIDPLUS, no AUTH=PLAIN: LOGIN (quoted string with \" and \\),
91# COPY + STORE \Deleted + EXPUNGE, reported as a risk: the EXPUNGE also removed UID 4, which was
92# already \Deleted on the server. No COPYUID: the destination gets a pending "p" record.
93run 0 - -- mh move --home @S/h --id INBOX/1793876400.V7U2F83ecb521.mailhand --folder Work
94mkdir @S/s5
95write @S/s5/state caps IMAP4rev1\nuser alice@example.test\npass pa"ss\word-SYNTH\nbox INBOX 7\nbox Work 11\nmsg INBOX 2 S @R/tests/fixtures/imap/m2.eml\nmsg INBOX 4 T @R/tests/fixtures/imap/m3.eml\nmsg Work 1 F @R/tests/fixtures/imap/m3.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
96bg srv imap @S/s5
97run 0 - -- srv acct @S/c/accounts @S/s5 work imaps mail.test alice@example.test pa"ss\word-SYNTH 600
98run 0 - -- mh sync --home @S/h --account work
99out-has "moves_pushed":1
100out-has "risk":"expunge_without_uidplus
101out-not pa"ss
102wait 0
103file-has @S/s5/log AUTH OK
104file-has @S/s5/log UID COPY 2 "Work"
105file-has @S/s5/log EXPUNGED 2
106file-has @S/s5/log EXPUNGED 4
107file-has @S/Mail/.Work/mailhand-imap p 1793876400.V7U2F83ecb521.mailhand
108#
109# pending_adopt: syncing Work fetches UID 2, finds the same bytes in the pending local message and
110# adopts it (no second copy); LOGIN with a literal (the password has bytes a quoted string cannot carry)
111mkdir @S/s6
112write @S/s6/state caps IMAP4rev1\nuser alice@example.test\npass pässwörd-SYNTH\nbox Work 11\nmsg Work 1 F @R/tests/fixtures/imap/m3.eml\nmsg Work 2 S @R/tests/fixtures/imap/m2.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
113bg srv imap @S/s6
114run 0 - -- srv acct @S/c/accounts @S/s6 work imaps mail.test alice@example.test pässwörd-SYNTH 600
115run 0 - -- mh sync --home @S/h --account work --folder Work
116out-has "folder":"Work","ok":true,"uidvalidity":11,"fetched":0,"flags_pushed":0,"moves_pushed":0,"adopted":1
117wait 0
118file-has @S/s6/log AUTH OK
119absent @S/Mail/.Work/cur/1793876400.V11U2F104ab921.mailhand:2,S
120exists @S/Mail/.Work/cur/1793876400.V7U2F83ecb521.mailhand:2,S
121file-has @S/Mail/.Work/mailhand-imap m 2 1793876400.V7U2F83ecb521.mailhand S
122file-has @S/Mail/.Work/mailhand-imap m 1 1793876400.V7U3F83ecb521.mailhand F
123file-not @S/Mail/.Work/mailhand-imap p 1793876400
124#
125# auth_refused: a wrong password is a defined refusal (exit 3), nothing is selected
126mkdir @S/s7
127write @S/s7/state caps IMAP4rev1 AUTH=PLAIN SASL-IR\nuser alice@example.test\npass another-SYNTH\nbox INBOX 7\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
128bg srv imap @S/s7
129run 0 - -- srv acct @S/c/accounts @S/s7 work imaps mail.test alice@example.test s3cret-SYNTH-pw 600
130run 3 - -- mh sync --home @S/h --account work
131out-has "refused":"authentication_refused"
132wait 0
133file-has @S/s7/log AUTH REFUSED
134file-not @S/s7/log SELECT
135#
136# second account, second Maildir: UIDVALIDITY change, NO/BAD replies, literals, timeouts
137mkdir @S/Mail2
138run 0 - -- mh setup --home @S/h2 --maildir @S/Mail2 --me alice@example.test --name Alice
139mkdir @S/c2
140append @S/h2/config accounts @S/c2/accounts\n
141
142mkdir @S/t1
143write @S/t1/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nmsg INBOX 1 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 2 R @R/tests/fixtures/imap/m2.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
144bg srv imap @S/t1
145run 0 - -- srv acct @S/c2/accounts @S/t1 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
146run 0 - -- mh sync --home @S/h2 --account home
147out-has "fetched":2
148wait 0
149#
150# uidvalidity_changed: refused (exit 3) before anything is fetched; the state is unchanged
151mkdir @S/t2
152write @S/t2/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nmsg INBOX 5 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 6 R @R/tests/fixtures/imap/m2.eml\nmsg INBOX 7 - @R/tests/fixtures/imap/m3.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
153bg srv imap @S/t2
154run 0 - -- srv acct @S/c2/accounts @S/t2 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
155run 3 - -- mh sync --home @S/h2 --account home
156out-has "ok":false,"refused":"uidvalidity_changed","uidvalidity":8,"uidvalidity_was":7
157wait 0
158file-not @S/t2/log FETCH
159file-has @S/Mail2/mailhand-imap uidvalidity 7
160#
161# resync: every record becomes pending and is matched by content: two adopted, one new, no duplicate
162mkdir @S/t3
163write @S/t3/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nmsg INBOX 5 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 6 R @R/tests/fixtures/imap/m2.eml\nmsg INBOX 7 - @R/tests/fixtures/imap/m3.eml\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
164bg srv imap @S/t3
165run 0 - -- srv acct @S/c2/accounts @S/t3 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
166run 0 - -- mh sync --home @S/h2 --account home --resync
167out-has "uidvalidity":8,"uidvalidity_was":7,"fetched":1,"flags_pushed":0,"moves_pushed":0,"adopted":2
168wait 0
169file-has @S/Mail2/mailhand-imap uidvalidity 8
170file-has @S/Mail2/mailhand-imap m 5 1793876400.V7U1F83ecb521.mailhand -
171file-has @S/Mail2/mailhand-imap m 6 1793876400.V7U2F83ecb521.mailhand R
172file-has @S/Mail2/mailhand-imap m 7 1793876400.V8U7F83ecb521.mailhand -
173absent @S/Mail2/new/1793876400.V8U5F83ecb521.mailhand
174run 0 - -- mh stats --home @S/h2
175out-has "messages":3
176#
177# select_no: a tagged NO to SELECT is a defined refusal
178mkdir @S/t4
179write @S/t4/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nopt select-no INBOX\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
180bg srv imap @S/t4
181run 0 - -- srv acct @S/c2/accounts @S/t4 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
182run 3 - -- mh sync --home @S/h2 --account home
183out-has "refused":"select_refused"
184wait 0
185#
186# fetch_bad: a tagged BAD to one message FETCH: refused (exit 3), counted, and "last" stays below it
187mkdir @S/t5
188write @S/t5/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nmsg INBOX 5 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 6 R @R/tests/fixtures/imap/m2.eml\nmsg INBOX 7 - @R/tests/fixtures/imap/m3.eml\nmsg INBOX 9 - @R/tests/fixtures/imap/m3.eml\nopt fetch-bad 9\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
189bg srv imap @S/t5
190run 0 - -- srv acct @S/c2/accounts @S/t5 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
191run 3 - -- mh sync --home @S/h2 --account home
192out-has "fetched":0
193out-has "refused_by_server":1
194wait 0
195file-has @S/Mail2/mailhand-imap last 7
196#
197# store_no: a refused UID STORE keeps the old flags in the state, so the next sync tries again
198run 0 - -- mh mark-read --home @S/h2 --id INBOX/1793876400.V8U7F83ecb521.mailhand
199mkdir @S/t6
200write @S/t6/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nmsg INBOX 5 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 6 R @R/tests/fixtures/imap/m2.eml\nmsg INBOX 7 - @R/tests/fixtures/imap/m3.eml\nopt store-no\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
201bg srv imap @S/t6
202run 0 - -- srv acct @S/c2/accounts @S/t6 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
203run 0 - -- mh sync --home @S/h2 --account home
204out-has "flags_pushed":0
205out-has "refused_by_server":1
206wait 0
207file-has @S/Mail2/mailhand-imap m 7 1793876400.V8U7F83ecb521.mailhand -
208#
209# literals: mailbox names as literals, BODY[] before UID in the FETCH reply, the reply written in
210# 7-byte pieces, a message whose text looks like IMAP syntax; --folder all maps "Lists/Omega" to the
211# Maildir++ folder .Lists.Omega
212mkdir @S/t7
213write @S/t7/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nbox Lists/Omega 12\nmsg INBOX 5 - @R/tests/fixtures/imap/m1.eml\nmsg INBOX 6 R @R/tests/fixtures/imap/m2.eml\nmsg INBOX 7 - @R/tests/fixtures/imap/m3.eml\nmsg Lists/Omega 1 - @R/tests/fixtures/imap/m2.eml\nopt literal-names\nopt body-first\nopt split-literal\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
214bg srv imap @S/t7
215run 0 - -- srv acct @S/c2/accounts @S/t7 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
216run 0 - -- mh sync --home @S/h2 --account home --folder all
217out-lines 2
218out-has "folder":"Lists.Omega","ok":true,"uidvalidity":12,"fetched":1
219wait 0
220file-eq @S/Mail2/.Lists.Omega/new/1793876400.V12U1F2a0fa0bb.mailhand tests/fixtures/imap/m2.eml
221file-has @S/t7/log SELECT "Lists/Omega"
222#
223# refused handshakes (real TLS 1.3, omtls): the server presents a certificate for another name, an
224# expired one, or one from a root that is not in the trust store. Each is a defined refusal (exit 6,
225# connection_failed, the omtls reason on stderr) before any command: the server logs nothing, so no
226# credential was sent.
227mkdir @S/r1
228write @S/r1/state caps IMAP4rev1 AUTH=PLAIN SASL-IR\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-other.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
229bg srv imap @S/r1
230run 0 - -- srv acct @S/c2/accounts @S/r1 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
231run 6 - -- mh sync --home @S/h2 --account home
232out-has "refused":"connection_failed"
233err-has sync: TLS: certificate does not match the host name
234wait 0
235absent @S/r1/log
236mkdir @S/r2
237write @S/r2/state caps IMAP4rev1 AUTH=PLAIN SASL-IR\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-expired.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
238bg srv imap @S/r2
239run 0 - -- srv acct @S/c2/accounts @S/r2 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
240run 6 - -- mh sync --home @S/h2 --account home
241err-has sync: TLS: certificate expired or not yet valid
242wait 0
243absent @S/r2/log
244mkdir @S/r3
245write @S/r3/state caps IMAP4rev1 AUTH=PLAIN SASL-IR\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 7\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-untrusted.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
246bg srv imap @S/r3
247run 0 - -- srv acct @S/c2/accounts @S/r3 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
248run 6 - -- mh sync --home @S/h2 --account home
249err-has sync: TLS: certificate not issued by a trusted root
250wait 0
251absent @S/r3/log
252#
253# roots_missing: a trust store that cannot be loaded is refused (exit 6, trust_store_failed) before any
254# connection; the server (good certificate, waits for one connection) is then served by a normal sync
255mkdir @S/r4
256write @S/r4/state caps IMAP4rev1 AUTH=PLAIN SASL-IR\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @S/no-such-roots.pem\n
257bg srv imap @S/r4
258run 0 - -- srv acct @S/c2/accounts @S/r4 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
259run 6 - -- mh sync --home @S/h2 --account home
260out-has "refused":"trust_store_failed"
261append @S/c2/accounts roots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
262run 0 - -- mh sync --home @S/h2 --account home
263wait 0
264file-has @S/r4/log AUTH OK
265#
266# timeout: io_timeout 1 against a server that stalls 3 s on SELECT: the sync fails with exit 6
267append @S/h2/config io_timeout 1\n
268mkdir @S/t8
269write @S/t8/state caps IMAP4rev1 AUTH=PLAIN SASL-IR MOVE UIDPLUS\nuser alice@example.test\npass s3cret-SYNTH-pw\nbox INBOX 8\nopt stall\nchain @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-good.der\nkey @R/build/deps/omtlsfix/tests/fixtures/srv/leaf-key.txt\nroots @R/build/deps/omtlsfix/tests/fixtures/srv/root.pem\n
270bg srv imap @S/t8
271run 0 - -- srv acct @S/c2/accounts @S/t8 home imaps mail.test alice@example.test s3cret-SYNTH-pw 600
272run 6 - -- mh sync --home @S/h2 --account home
273out-has "refused":"connection_failed"
274err-has sync: TLS: timed out
275max-ns 2900000000
276wait 0
277#
278# credential_leak_scan: neither the synthetic passwords nor the AUTH PLAIN blob of the first one
279# appear in any file mailhand wrote (homes, Maildirs, audit logs, states) or in its last outputs
280tree-not @S/h s3cret-SYNTH-pw
281tree-not @S/h2 s3cret-SYNTH-pw
282tree-not @S/Mail s3cret-SYNTH-pw
283tree-not @S/Mail2 s3cret-SYNTH-pw
284tree-not @S/Mail pa"ss\word
285tree-not @S/Mail pässwörd
286tree-not @S/h AGFsaWNlQGV4YW1wbGUudGVzdABzM2NyZXQtU1lOVEgtcHc=
287tree-not @S/h2 AGFsaWNlQGV4YW1wbGUudGVzdABzM2NyZXQtU1lOVEgtcHc=
288file-not @S/h/audit.log s3cret
289file-has @S/h/audit.log sync