annotate src/lib/Mail.luan @ 48:4e1a01db19ec

add lists
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 17 Nov 2022 00:11:44 -0700
parents a17e400ddaa1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local parse = Luan.parse or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Luan_mail = require "luan:mail/Mail.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Db = require "site:/lib/Db.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Mail = {}
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 function Mail.get()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local doc = Db.get_document("type:mail")
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 return doc and doc.config
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 function Mail.sender()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local text = Mail.get()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if text == nil then
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return nil
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local info = parse(text)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 return Luan_mail.sender(info)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 function Mail.set(text)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 if text == nil then
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 Db.delete("type:mail")
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 else
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 do -- test
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 local info = parse(text)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 Luan_mail.sender(info)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local doc = Db.get_document("type:mail") or {type="mail"}
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 doc.config = text
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 Db.save(doc)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 return Mail