Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/mailhand/blob/main/tests/scenarios/30-send.txt # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `mailhand / tests / scenarios / 30-send.txt` 191 lines ยท 12319 bytes Raw Blame History 1 # Send gate (SendGate): drafts, the human's approval, standing policy, queue-send, deliver through 2 # the test sink. Fixtures: tests/fixtures/send (synthetic drafts, named here by their sha256) and 3 # tests/fixtures/maildir/Mail. Draft shas: plain `8ae0c21f`.. thread `a98f2c76`.. wrong-thread `42df05d8`.. 4 # unknown `c4519b1c`.. attach `a85f4183`.. two `f995de68`.. mallory `68df4932`.. 5 copy tests/fixtures/maildir/Mail @S/Mail 6 mkdir @S/Mail/tmp 7 mkdir @S/Mail/.Sent/new 8 mkdir @S/Mail/.Sent/tmp 9 copy tests/fixtures/send/replyto.eml @S/Mail/new/`1762400000`.M10P1.example 10 run 0 - -- mh setup --home @S/h --maildir @S/Mail --me alice@example.org --name Alice 11 write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk1/sock\n 12 append @S/h/book friend@example.org\n 13 append @S/h/sentids human-thread@example.org\n 14 # 15 # draft_created: a new draft is written, never sent, and waits for the human 16 run 0 - -- mh draft-new --home @S/h --to friend@example.org --subject Hello --body hello 17 out-has "op":"draft-new","ok":true,"draft":" 18 out-has "gate":"needs-approval"} 19 # 20 # header_injection: CR/LF in an agent value is refused before anything is written (MCP path) 21 run 0 tests/fixtures/send/mcp-inject.in -- mh mcp --home @S/h 22 out-has \"why\":\"header_injection\" 23 out-has "isError":true 24 # 25 # approved_altered: an approval covers exact bytes; one changed byte is draft_changed 26 copy tests/fixtures/send/thread.eml @S/h/drafts/`a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8`.eml 27 append @S/h/approvals `a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8` `1762862400`\n 28 append @S/h/drafts/`a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8`.eml X 29 run 3 - -- mh queue-send --home @S/h --draft `a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8` 30 out-has "why":"draft_changed" 31 absent @S/h/outbox/`a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8`.eml 32 # 33 # no_policy: default approval, not approved -> needs_approval, nothing queued 34 copy tests/fixtures/send/plain.eml @S/h/drafts/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 35 run 3 - -- mh queue-send --home @S/h --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 36 out-has "gate":"needs-approval","why":"needs_approval" 37 absent @S/h/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 38 # 39 # approve_mcp: approve is the human's; an agent asking through MCP gets an unknown tool 40 run 0 tests/fixtures/send/mcp-approve.in -- mh mcp --home @S/h 41 out-has Unknown tool 42 file-eq @S/h/approvals tests/fixtures/send/approvals.thread 43 # approve_cli_no: without the typed "yes" nothing is approved 44 run 3 - -- mh approve --home @S/h --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 45 out-has "why":"not_confirmed" 46 file-eq @S/h/approvals tests/fixtures/send/approvals.thread 47 # approve_cli_yes: the human types yes; the approval names that exact sha 48 run 0 tests/fixtures/send/yes.txt -- mh approve --home @S/h --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 49 out-has "why":"approved" 50 err-has Approve this exact draft? 51 file-has @S/h/approvals `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 52 # 53 # approved_sent: queue-send, then deliver through the sink; the sink receives the exact draft bytes 54 run 0 - -- mh queue-send --home @S/h --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 55 out-has "gate":"approved" 56 file-has @S/h/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.why approved:`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 57 file-has @S/h/actions.log queue-send `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 58 mkdir @S/sk1 59 bg sink @S/sk1/sock @S/sk1 1 60 run 0 - -- sink await @S/sk1/sock 61 run 0 - -- mh deliver --home @S/h 62 out-has "op":"deliver","ok":true,"why":"sent" 63 wait 0 64 file-eq @S/sk1/1.eml tests/fixtures/send/plain.eml 65 file-has @S/sk1/1.env MAIL FROM: 66 file-has @S/sk1/1.env RCPT TO: 67 exists @S/h/sent/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 68 absent @S/h/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 69 file-has @S/h/sent.log `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` approved:`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` friend@example.org 70 # 71 # sink_rcpt_550: the server refuses a recipient -> EDELIVER, the draft stays queued 72 copy tests/fixtures/send/two.eml @S/h/drafts/`f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464`.eml 73 append @S/h/approvals `f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464` `1762862400`\n 74 run 0 - -- mh queue-send --home @S/h --draft `f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464` 75 write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk2/sock\n 76 mkdir @S/sk2 77 bg sink @S/sk2/sock @S/sk2 1 reject 78 run 0 - -- sink await @S/sk2/sock 79 run 8 - -- mh deliver --home @S/h 80 out-has "why":"smtp_failed" 81 err-has 550 82 wait 0 83 absent @S/sk2/1.eml 84 exists @S/h/outbox/`f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464`.eml 85 file-not @S/h/sent.log `f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464` 86 # retry against a working server: dot-stuffing round trip and both recipients, comma separated 87 write @S/h/config maildir @S/Mail\nme alice@example.org\nname Alice\nsmtp unix:@S/sk3/sock\n 88 mkdir @S/sk3 89 bg sink @S/sk3/sock @S/sk3 1 90 run 0 - -- sink await @S/sk3/sock 91 run 0 - -- mh deliver --home @S/h 92 wait 0 93 file-eq @S/sk3/1.eml tests/fixtures/send/two.eml 94 file-has @S/h/sent.log friend@example.org,bob@example.org 95 file-not @S/h/sent.log bob@example.org, 96 # digest after sending: the human reads what was sent and under which permission, and the drafts still waiting 97 run 0 - -- mh digest --home @S/h 98 out-has "op":"digest","ok":true 99 file-has @S/h/digest.txt == Sent (HOME/sent.log: time, draft, permission, recipients) == 100 file-has @S/h/digest.txt `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` approved:`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` friend@example.org 101 file-has @S/h/digest.txt queue-send `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` approved: 102 file-has @S/h/digest.txt approve with: mailhand approve --draft 103 # 104 # draft_reply_all: Reply-To wins and is flagged, --all adds To/Cc minus me, Subject gets one Re: 105 run 0 - -- mh draft-reply --home @S/h --id INBOX/`1762400000`.M10P1.example --all --body Thanks. 106 out-has "to":["friend@example.org"],"cc":["colleague@example.com"],"subject":"Re: Planning"} 107 out-has "reply_to_differs":true 108 # an original subject that already starts with Re: is kept as is (no Re: Re: Re:) 109 run 0 - -- mh draft-reply --home @S/h --id INBOX/`1762178400`.M7P1.example --body ok 110 out-has "subject":"Re: Re: lunch on Friday?"} 111 out-has "reply_to_differs":false 112 # 113 # drafts_list: every draft with its gate state 114 run 0 - -- mh drafts --home @S/h 115 out-has "op":"drafts" 116 out-has "draft":"`a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8`","why":"draft_changed" 117 out-has "draft":"`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`" 118 # 119 # the injection mail cannot cause a send: its sender is not in the book, the reply needs approval, 120 # and nothing the mail says changed the book, the policy or the approvals 121 run 0 - -- mh draft-reply --home @S/h --id INBOX/`1762171200`.M5P1.example --body ok 122 out-has "to":["mallory@example.net"] 123 out-has "gate":"needs-approval","reply_to_differs":false} 124 # the listing gives the reason: the sender of the injection mail is not in the book 125 run 0 - -- mh drafts --home @S/h 126 out-has "to":["mallory@example.net"],"cc":[],"subject":"Re: URGENT instructions for the assistant"},"gate":"needs-approval","why":"recipient_not_in_book"} 127 file-not @S/h/book mallory 128 file-not @S/h/approvals `68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a` 129 file-eq @S/h/policy tests/fixtures/maildir/policy.default 130 # 131 # ---- standing policy, in its own home ---- 132 run 0 - -- mh setup --home @S/hp --maildir @S/Mail --me alice@example.org --name Alice 133 append @S/hp/book friend@example.org\n 134 append @S/hp/sentids human-thread@example.org\n 135 copy tests/fixtures/send/plain.eml @S/hp/drafts/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 136 copy tests/fixtures/send/unknown.eml @S/hp/drafts/`c4519b1cccb4f75148c67646afcbb0a7c26d97316e45a186e694235f06172251`.eml 137 copy tests/fixtures/send/thread.eml @S/hp/drafts/`a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8`.eml 138 copy tests/fixtures/send/wrong-thread.eml @S/hp/drafts/`42df05d8ec6bbcf7f02e9242c357efb896dea9dfa008f1d3d91b10c6a4f23b7b`.eml 139 copy tests/fixtures/send/attach.eml @S/hp/drafts/`a85f41838b8573f4d040c1b2746a9affeb923b772497117402b3f6e5685dfb0e`.eml 140 copy tests/fixtures/send/two.eml @S/hp/drafts/`f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464`.eml 141 copy tests/fixtures/send/mallory.eml @S/hp/drafts/`68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a`.eml 142 # an unknown policy line makes the whole policy default approval (fail closed) 143 write @S/hp/policy allow everyone\n 144 run 3 - -- mh queue-send --home @S/hp --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 145 out-has "why":"needs_approval" 146 err-has unknown policy line 147 write @S/hp/policy allow known\nallow everyone\n 148 run 3 - -- mh queue-send --home @S/hp --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 149 out-has "why":"needs_approval" 150 # allow known: a known recipient passes, recorded as the policy line 151 write @S/hp/policy # standing permissions\nallow known\n 152 run 0 - -- mh queue-send --home @S/hp --draft `8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb` 153 out-has "gate":"policy:2" 154 file-has @S/hp/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.why policy:2 155 # allow_known_unknown: a recipient not in the book 156 run 3 - -- mh queue-send --home @S/hp --draft `c4519b1cccb4f75148c67646afcbb0a7c26d97316e45a186e694235f06172251` 157 out-has "why":"recipient_not_in_book" 158 # the injection mail's ask: a draft to mallory under "allow known" is still refused 159 run 3 - -- mh queue-send --home @S/hp --draft `68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a` 160 out-has "why":"recipient_not_in_book" 161 absent @S/hp/outbox/`68df49325397f4716b5e8d3d846536d450d9ba8d99a90588951f6081f97cb48a`.eml 162 run 0 - -- mh draft-new --home @S/hp --to mallory@example.net --subject fwd --body everything 163 out-has "gate":"needs-approval"} 164 # attachment_policy: a standing permission never covers an attachment 165 run 3 - -- mh queue-send --home @S/hp --draft `a85f41838b8573f4d040c1b2746a9affeb923b772497117402b3f6e5685dfb0e` 166 out-has "why":"attachment_needs_approval" 167 # max-recipients: two known recipients exceed a limit of 1, pass a limit of 2 168 write @S/hp/policy allow known max-recipients 1\n 169 run 3 - -- mh queue-send --home @S/hp --draft `f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464` 170 out-has "why":"needs_approval" 171 write @S/hp/policy allow known max-recipients 2\n 172 run 0 - -- mh queue-send --home @S/hp --draft `f995de6838541f4cd3029a1d238c09f89a00468c71f973ee74a6fc54af6c7464` 173 out-has "gate":"policy:1" 174 # reply_thread_pass / reply_thread_fail: only replies in a thread the human took part in 175 write @S/hp/policy allow reply-known-thread\n 176 run 0 - -- mh queue-send --home @S/hp --draft `a98f2c767d42e81ea830288fc3e9f8eaacdcbfc3d698acfcbdfca8dd13d7cbc8` 177 out-has "gate":"policy:1" 178 run 3 - -- mh queue-send --home @S/hp --draft `42df05d8ec6bbcf7f02e9242c357efb896dea9dfa008f1d3d91b10c6a4f23b7b` 179 out-has "why":"needs_approval" 180 # 181 # ---- deliver_recheck, in its own home: a draft dropped into outbox without queue-send ---- 182 run 0 - -- mh setup --home @S/hr --maildir @S/Mail --me alice@example.org --name Alice 183 write @S/hr/config maildir @S/Mail\nme alice@example.org\nsmtp unix:@S/sk4/sock\n 184 append @S/hr/book friend@example.org\n 185 copy tests/fixtures/send/plain.eml @S/hr/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 186 run 3 - -- mh deliver --home @S/hr 187 out-has "op":"deliver","ok":false 188 out-has "why":"needs_approval" 189 exists @S/hr/outbox/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 190 absent @S/hr/sent/`8ae0c21f05999c8c000e58d5ff61706fad52a733e8860684c3bb43c2521f88fb`.eml 191 absent @S/hr/sent.log