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/src/cfg.om # 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 / src / cfg.om` 200 lines ยท 3981 bytes Raw Blame History 1 note ======== src/cfg.om: home directory, config file, the human's own addresses ======== 2 note Home: --home DIR, else $MAILHAND_HOME, else $HOME/.mailhand. Config: HOME/config, lines 3 note "key value" (# starts a comment line): maildir PATH, me ADDRESS (repeatable; the first is 4 note the From of drafts), name TEXT, smtp unix:/PATH or smtp 127.0.0.1:PORT, helo NAME. 5 const VCFO ulong 64 6 const VCFN ulong 65 7 text kmhome "MAILHAND_HOME=" 8 text khomev "HOME=" 9 text kdotmh "/.mailhand" 10 text khomek "home" 11 text kcfgf "/config" 12 text kmaildir "maildir" 13 text kme "me" 14 text kerrhome "no home directory: give --home DIR or set MAILHAND_HOME or HOME" 15 text kerrmd "config has no usable maildir line" 16 17 18 note cf_home: fill gh; false when no home can be found or it does not fit PATH_MAX 19 fn cf_home to bool 20 if q_get khomek 21 n = get gv VQN 22 if or eq n 0 gt n 3000 23 ret false 24 end 25 for i ulong n bound 4096 26 put gh i s_get S_REQ add get gv VQO i 27 end 28 put gv VHL n 29 ret true 30 end 31 b = new uchar 131072 0 32 r = env_find kmhome b 33 if gt r 0 34 ret cf_sethome part b 0 ulong r 35 end 36 r = env_find khomev b 37 if le r 0 38 ret false 39 end 40 if gt r 3000 41 ret false 42 end 43 for i ulong len kdotmh 44 put b add ulong r i get kdotmh i 45 end 46 ret cf_sethome part b 0 add ulong r len kdotmh 47 end 48 49 fn cf_sethome b view uchar * to bool 50 if gt len b 3000 51 ret false 52 end 53 for i ulong len b bound 4096 54 if eq get b i 0 55 ret false 56 end 57 put gh i get b i 58 end 59 put gv VHL len b 60 ret true 61 end 62 63 note cf_line_end: offset of the end of the line starting at p in S_CFG 64 fn st_eol s ulong p ulong to ulong 65 n = s_len s 66 q = p 67 while lt q n bound `9223372036854775807` 68 if eq s_get s q 10 69 ret q 70 end 71 q = add q 1 72 end 73 ret n 74 end 75 76 note st_trim: [p, e) without trailing CR, spaces and tabs; returns the new end 77 fn st_rtrim s ulong p ulong e ulong to ulong 78 q = e 79 while gt q p bound `9223372036854775807` 80 c = s_get s sub q 1 81 if and ne c 13 and ne c 32 ne c 9 82 ret q 83 end 84 q = sub q 1 85 end 86 ret q 87 end 88 89 fn st_skipws s ulong p ulong e ulong to ulong 90 q = p 91 while lt q e bound `9223372036854775807` 92 c = s_get s q 93 if and ne c 32 ne c 9 94 ret q 95 end 96 q = add q 1 97 end 98 ret q 99 end 100 101 note st_kv: line [p, e) of store s is "key VALUE"; on success VCFO / VCFN hold the value range 102 fn st_kv s ulong p ulong e ulong k view uchar * to bool 103 if le sub e p len k 104 ret false 105 end 106 if not s_eqt s p len k k 107 ret false 108 end 109 c = s_get s add p len k 110 if and ne c 32 ne c 9 111 ret false 112 end 113 v = st_skipws s add p len k e 114 w = st_rtrim s v e 115 put gv VCFO v 116 put gv VCFN sub w v 117 ret true 118 end 119 120 note cf_getk: the k-th (0-based) "key value" line of the config; value at S_CFG[VCFO, +VCFN) 121 fn cf_getk k view uchar * idx ulong to bool 122 n = s_len S_CFG 123 p = ulong 0 124 c = ulong 0 125 while lt p n bound `9223372036854775807` 126 e = st_eol S_CFG p 127 if st_kv S_CFG p e k 128 if eq c idx 129 ret true 130 end 131 c = add c 1 132 end 133 p = add e 1 134 end 135 ret false 136 end 137 138 fn cf_get k view uchar * to bool 139 ret cf_getk k 0 140 end 141 142 note cf_init: home, config, mail root, me list; returns 0, ENOSETUP (no config) or EUSAGE 143 fn cf_init to int 144 if not cf_home 145 diag kerrhome 146 ret EUSAGE 147 end 148 p_reset 149 p_h 150 p_t kcfgf 151 r = s_file S_CFG 152 if lt r 0 153 ret ENOSETUP 154 end 155 if not cf_get kmaildir 156 diag kerrmd 157 ret ENOSETUP 158 end 159 if or eq get gv VCFN 0 gt get gv VCFN 3000 160 diag kerrmd 161 ret ENOSETUP 162 end 163 for i ulong get gv VCFN bound 4096 164 put gr i s_get S_CFG add get gv VCFO i 165 end 166 put gv VRL get gv VCFN 167 s_reset S_ME 168 i = ulong 0 169 while cf_getk kme i bound `9223372036854775807` 170 for j ulong get gv VCFN bound `9223372036854775807` 171 z = s_add S_ME lc s_get S_CFG add get gv VCFO j 172 end 173 z = s_add S_ME 10 174 i = add i 1 175 end 176 ret EOK 177 end 178 179 180 note me_is: address [off, off+n) of store s is one of the human's own (case-insensitive) 181 fn me_is s ulong off ulong n ulong to bool 182 ret st_inlist S_ME s off n 183 end 184 185 note st_inlist: the store range equals (ignoring ASCII case) one "\n"-terminated line of list store l 186 fn st_inlist l ulong s ulong off ulong n ulong to bool 187 m = s_len l 188 p = ulong 0 189 while lt p m bound `9223372036854775807` 190 e = st_eol l p 191 w = st_rtrim l p e 192 if eq sub w p n 193 if s_eqss l p n s off n 194 ret true 195 end 196 end 197 p = add e 1 198 end 199 ret false 200 end