--- Message database parsing ---
-local msgs = {}
function Message(msg)
msgs[msg.number] = msg
end
+local function get_next_msg_number(obbs, conf_num)
+ local msgnum_filename = obbs.path .. "/conferences/" ..
+ obbs.conferences[conf_num+1] .. ".next"
+ local mnf = assert(io.open(msgnum_filename, "r"))
+ local next_num = tonumber(mnf:read("*all"))
+ mnf:close()
+ return next_num
+end
+
+local function set_next_msg_number(obbs, conf_num, next_num)
+ local msgnum_filename = obbs.path .. "/conferences/" ..
+ obbs.conferences[conf_num+1] .. ".next"
+ local mnf = assert(io.open(msgnum_filename, "w"))
+ mnf:write(next_num)
+ mnf:close()
+end
+
+local function append_new_msg(obbs, conf_num, msg)
+ local cf = assert(io.open(obbs.path .. "/conferences/" ..
+ obbs.conferences[conf_num+1] .. ".msgs", "a+"))
+ cf:write("\n")
+ cf:write("Message{\n")
+ cf:write("\tnumber=" .. msg.number .. ",\n")
+ cf:write("\tto=" .. string.format("%q", msg.to) .. ",\n")
+ cf:write("\tfrom=" .. string.format("%q", msg.from) .. ",\n")
+ cf:write("\tsubject=" .. string.format("%q", msg.subject) .. ",\n")
+ cf:write("\treplyto=" .. msg.replyto .. ",\n")
+ cf:write("\tdate=" .. string.format("%q", msg.date) .. ",\n")
+ cf:write("\ttime=" .. string.format("%q", msg.time) .. ",\n")
+ cf:write("\ttext=" .. string.format("%q",msg.text) .. "\n")
+ cf:write("}\n")
+ cf:close()
+end
+
+
--- QWK formatting ---
local qwk = {}
mf:write(string.rep("\0",padding))
end
-function qwk.read_message(archive_dir, obbs, user_name)
+function qwk.process_replies(archive_dir, obbs, user_name)
local msg_filename = archive_dir .. "/" .. obbs.bbsid .. ".MSG"
end
while mf:read(0) do
- qwk.read_message_header(mf, obbs)
+ qwk.process_reply(mf, obbs)
end
end
-function qwk.read_message_header(mf, obbs)
+function qwk.process_reply(mf, obbs)
local msg = {}
mf:read(1) -- Message status (ignore for now)
end
msg.text = string.gsub(msg.text, "\xe3", "\n")
- print("Message{")
- for k,v in pairs(msg) do
- print("\t" .. k .. "=\'" .. v .. "',")
- end
- print("}")
+ msg.number = get_next_msg_number(obbs, conf_num)
+ set_next_msg_number(obbs, conf_num, msg.number+1)
+
+ append_new_msg(obbs, conf_num, msg)
+
+ print("Processed message for conference " .. obbs.conferences[conf_num+1] .. ".")
+
+ -- print("Message{")
+ -- for k,v in pairs(msg) do
+ -- print("\t" .. k .. "=\'" .. v .. "',")
+ -- end
+ -- print("}")
end
--- Commands ---
fs.copy(rep_filename, work_dir .. "/repfile.rep")
os.execute("unzip " .. work_dir .. "/repfile.rep -d " .. work_dir)
- qwk.read_message(work_dir, obbs, user_name)
+ qwk.process_replies(work_dir, obbs, user_name)
fs.rmdir(work_dir, true)