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
| 1 | note ======== src/setup.om: the human's one setup command, and the digest ======== |
| 2 | note setup --maildir PATH --me ADDRESS [--name TEXT] [--smtp unix:/PATH|127.0.0.1:PORT] [--helo NAME] |
| 3 | note creates HOME (0700) with config, policy (default: nothing is sent without approval), rules |
| 4 | note (examples, all commented out), approvals, drafts/ outbox/ sent/ labels/, audit.log, and the |
| 5 | note Maildir root with INBOX, Sent, Drafts and Archive when missing. It refuses when HOME/config |
| 6 | note exists, so it never overwrites a policy the human edited. |
| 7 | text ksetup "setup" |
| 8 | text kmdarg "maildir" |
| 9 | text kmearg "me" |
| 10 | text knamearg "name" |
| 11 | text knamek "name" |
| 12 | text ksmtpk "smtp" |
| 13 | text khelok "helo" |
| 14 | text ksmtparg "smtp" |
| 15 | text kheloarg "helo" |
| 16 | text kalready "already_set_up" |
| 17 | text kbadarg "bad_argument" |
| 18 | text kpolf "/policy" |
| 19 | text kapprf "/approvals" |
| 20 | text kdraftd "/drafts" |
| 21 | text koutd "/outbox" |
| 22 | text klabd "/labels" |
| 23 | text kcfghead "# mailhand config, written by setup. One \"key value\" per line.\n" |
| 24 | text kpolicy "# mailhand send policy. Only the human edits this file; nothing in any mail changes it.\n# Default: nothing leaves without your approval of that exact draft:\n# mailhand approve --draft SHA (shows the draft, asks yes)\n# Standing permissions you may add (each covers only recipients already in your address book,\n# never attachments):\n# allow reply-known-thread replies, to known people, in threads you took part in\n# allow known any draft to known people\n# allow known max-recipients 3\ndefault approval\n" |
| 25 | text krules "# mailhand triage rules. Only the human edits this file. One rule per line:\n# if HEADER contains TEXT then label LABEL\n# Examples (remove the # to use):\n# if List-Id contains example.org then label lists\n# if Subject contains invoice then label bills\n" |
| 26 | text kfsent ".Sent" |
| 27 | text kfdraft ".Drafts" |
| 28 | text kfarch ".Archive" |
| 29 | text khomek2 "home" |
| 30 | text kmaildirk "maildir" |
| 31 | text kpolk "policy" |
| 32 | text kdefpol "default approval: nothing is sent without your approval of the exact draft" |
| 33 | text kneedabs "maildir must be an absolute path" |
| 34 | text kerrroot "cannot create the Maildir root (its parent must exist)" |
| 35 | |
| 36 | fn su_cfgline k view uchar * a view uchar * to bool |
| 37 | if not q_get a |
| 38 | ret false |
| 39 | end |
| 40 | o = get gv VQO |
| 41 | n = get gv VQN |
| 42 | for i ulong n bound 9223372036854775807 |
| 43 | c = s_get S_REQ add o i |
| 44 | if or lt c 32 eq c 127 |
| 45 | ret false |
| 46 | end |
| 47 | end |
| 48 | w_t k |
| 49 | w_b 32 |
| 50 | w_qv |
| 51 | w_b 10 |
| 52 | ret true |
| 53 | end |
| 54 | |
| 55 | note su_mkdirs: dir gp and its cur, new, tmp |
| 56 | fn su_maildir to bool |
| 57 | p_save |
| 58 | zl = p_mkdir |
| 59 | if ne p_kind 1 |
| 60 | ret false |
| 61 | end |
| 62 | for t ulong 3 |
| 63 | p_restore |
| 64 | mv_sub t |
| 65 | zl = p_mkdir |
| 66 | if ne p_kind 1 |
| 67 | ret false |
| 68 | end |
| 69 | end |
| 70 | p_restore |
| 71 | ret true |
| 72 | end |
| 73 | |
| 74 | fn su_folder f view uchar * to bool |
| 75 | p_reset |
| 76 | p_r |
| 77 | p_c 47 |
| 78 | p_t f |
| 79 | ret su_maildir |
| 80 | end |
| 81 | |
| 82 | fn su_homedir t view uchar * to bool |
| 83 | p_reset |
| 84 | p_h |
| 85 | p_t t |
| 86 | zl = p_mkdir |
| 87 | ret eq p_kind 1 |
| 88 | end |
| 89 | |
| 90 | fn su_file t view uchar * body view uchar * to long |
| 91 | w_reset |
| 92 | w_t body |
| 93 | p_reset |
| 94 | p_h |
| 95 | p_t t |
| 96 | ret f_new |
| 97 | end |
| 98 | |
| 99 | fn op_setup to int |
| 100 | if not cf_home |
| 101 | diag kerrhome |
| 102 | ret EUSAGE |
| 103 | end |
| 104 | p_reset |
| 105 | p_h |
| 106 | p_t kcfgf |
| 107 | if ne p_kind 0 |
| 108 | o_ob |
| 109 | o_ks kopk ksetup |
| 110 | o_kb kokk false |
| 111 | o_ks krefk kalready |
| 112 | o_oe |
| 113 | o_nl |
| 114 | ret EUSAGE |
| 115 | end |
| 116 | if not q_get kmdarg |
| 117 | diag2 kmissing kmdarg |
| 118 | ret EUSAGE |
| 119 | end |
| 120 | if or eq get gv VQN 0 gt get gv VQN 3000 |
| 121 | ret su_bad |
| 122 | end |
| 123 | if ne s_get S_REQ get gv VQO 47 |
| 124 | diag kneedabs |
| 125 | ret su_bad |
| 126 | end |
| 127 | for i ulong get gv VQN bound 4096 |
| 128 | put gr i s_get S_REQ add get gv VQO i |
| 129 | end |
| 130 | put gv VRL get gv VQN |
| 131 | w_reset |
| 132 | w_t kcfghead |
| 133 | if not su_cfgline kmaildirk kmdarg |
| 134 | ret su_bad |
| 135 | end |
| 136 | if not su_cfgline kme kmearg |
| 137 | diag2 kmissing kmearg |
| 138 | ret su_bad |
| 139 | end |
| 140 | z = su_cfgline knamek knamearg |
| 141 | z = su_cfgline ksmtpk ksmtparg |
| 142 | z = su_cfgline khelok kheloarg |
| 143 | p_reset |
| 144 | p_h |
| 145 | p_save |
| 146 | zl = p_mkdir |
| 147 | if ne p_kind 1 |
| 148 | ret su_bad |
| 149 | end |
| 150 | s_reset S_AUX |
| 151 | s_adds S_AUX S_W 0 s_len S_W |
| 152 | r = su_rest |
| 153 | if ne r EOK |
| 154 | ret r |
| 155 | end |
| 156 | w_reset |
| 157 | w_s S_AUX 0 s_len S_AUX |
| 158 | p_reset |
| 159 | p_h |
| 160 | p_t kcfgf |
| 161 | k = f_new |
| 162 | if lt k 0 |
| 163 | ret EIO |
| 164 | end |
| 165 | r = cf_init |
| 166 | if ne r EOK |
| 167 | ret r |
| 168 | end |
| 169 | r = op_book |
| 170 | o_ob |
| 171 | o_ks kopk ksetup |
| 172 | o_kb kokk true |
| 173 | o_k khomek2 |
| 174 | o_vbeg |
| 175 | o_b 34 |
| 176 | for i ulong get gv VHL bound 4096 |
| 177 | o_jc get gh i |
| 178 | end |
| 179 | o_b 34 |
| 180 | o_k kpolk |
| 181 | o_vs kdefpol |
| 182 | o_oe |
| 183 | o_nl |
| 184 | ret EOK |
| 185 | end |
| 186 | |
| 187 | |
| 188 | fn su_bad to int |
| 189 | o_ob |
| 190 | o_ks kopk ksetup |
| 191 | o_kb kokk false |
| 192 | o_ks krefk kbadarg |
| 193 | o_oe |
| 194 | o_nl |
| 195 | ret EUSAGE |
| 196 | end |
| 197 | |
| 198 | note su_rest: directories and default files (all created exclusively; existing ones are kept) |
| 199 | fn su_rest to int |
| 200 | if not su_homedir kdraftd |
| 201 | ret EIO |
| 202 | end |
| 203 | if not su_homedir koutd |
| 204 | ret EIO |
| 205 | end |
| 206 | if not su_homedir ksentdir |
| 207 | ret EIO |
| 208 | end |
| 209 | if not su_homedir klabd |
| 210 | ret EIO |
| 211 | end |
| 212 | zl = su_file kpolf kpolicy |
| 213 | zl = su_file krulesf krules |
| 214 | w_reset |
| 215 | p_reset |
| 216 | p_h |
| 217 | p_t kapprf |
| 218 | zl = f_new |
| 219 | p_reset |
| 220 | p_r |
| 221 | if not su_maildir |
| 222 | diag kerrroot |
| 223 | ret EIO |
| 224 | end |
| 225 | if not su_folder kfsent |
| 226 | ret EIO |
| 227 | end |
| 228 | if not su_folder kfdraft |
| 229 | ret EIO |
| 230 | end |
| 231 | if not su_folder kfarch |
| 232 | ret EIO |
| 233 | end |
| 234 | ret EOK |
| 235 | end |
| 236 |