diff src/lib/Mail.luan @ 4:a17e400ddaa1

add email
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Jun 2022 11:58:27 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/Mail.luan	Tue Jun 21 11:58:27 2022 -0600
@@ -0,0 +1,38 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local parse = Luan.parse or error()
+local Luan_mail = require "luan:mail/Mail.luan"
+local Db = require "site:/lib/Db.luan"
+
+
+local Mail = {}
+
+function Mail.get()
+	local doc = Db.get_document("type:mail")
+	return doc and doc.config
+end
+
+function Mail.sender()
+	local text = Mail.get()
+	if text == nil then
+		return nil
+	end
+	local info = parse(text)
+	return Luan_mail.sender(info)
+end
+
+function Mail.set(text)
+	if text == nil then
+		Db.delete("type:mail")
+	else
+		do  -- test
+			local info = parse(text)
+			Luan_mail.sender(info)
+		end
+		local doc = Db.get_document("type:mail") or {type="mail"}
+		doc.config = text
+		Db.save(doc)
+	end
+end
+
+return Mail