--- Utility functions ---
-local function print_table (t, lev)
+local function write_object (fh, obj, lev)
lev = lev or 0
local ind = string.rep("\t", lev)
-
- for k,v in pairs(t) do
- if type(v)=="table" then
- print(ind ..k .. "= {")
- print_table(v, lev+1)
- print(ind .. "}")
- else
- print(ind .. k .. "=" .. tostring(v))
+
+ if type(obj)=="table" then
+ fh:write("{\n")
+ for k,v in pairs(obj) do
+ fh:write(ind .. "\t[" .. string.format("%q",k) .. "]=")
+ write_object(fh, v, lev+1)
+ fh:write(",\n")
end
+ fh:write(ind .. "}")
+ else
+ fh:write(string.format("%q",obj))
end
end
+local function print_object(obj)
+ write_object(io.stdout, obj)
+end
+
+
local function space_pad(s, n)
return string.sub(s,1,n) .. string.rep(" ", math.max(0,n-string.len(s)))
end
return string.match(md5f_str, "^(%w+)%s")
end
---- Message database parsing ---
+
+--- Message database ---
function Message(msg)
msgs[msg.number] = msg
local qwk = {}
-function qwk.build_qwk(user_name, qwk_filename)
+function qwk.build_qwk(user_name, qwk_filename, first_unseen_msgs)
+ first_unseen_msgs = first_unseen_msgs or {}
+
local work_dir = fs.mktempdir()
-- CONTROL.DAT
-- Pack messages
- qwk.write_message(work_dir)
+ first_unseen_msgs = qwk.write_message(work_dir, first_unseen_msgs)
-- Create archive in outgoing
os.execute(qb.zip .. " -rj " .. qwk_filename .. " " .. work_dir)
fs.rmdir(work_dir, true)
+
+ return first_unseen_msgs
end
cf:close()
end
-function qwk.write_message (target_dir)
+function qwk.write_message (target_dir, first_unseen_msgs)
local mf = assert(io.open(target_dir .. "/MESSAGES.DAT", "w"))
+ -- Also write MultiMail compatible RED file
+ -- (For some reson, MM doesn't respect read status in header.)
+ local rf = assert(io.open(target_dir .. "/" .. qb.bbsid .. ".RED", "w"))
+
+ print_object(first_unseen_msgs)
+
local pkt_msg_num = 0
mf:write(space_pad("Produced by QWiKBoard.", 128))
dofile(qb.path .. "/conferences/" .. cname .. ".msgs")
for i,msg in ipairs(msgs) do
pkt_msg_num = pkt_msg_num + 1
+
+ if first_unseen_msgs[cnum]
+ and msg.number<first_unseen_msgs[cnum] then
+ msg.read = true
+ rf:write("\x01")
+ else
+ rf:write("\x00")
+ end
+
qwk.write_message_header_block(mf, cnum, pkt_msg_num, msg)
qwk.write_message_text(mf, msg)
end
+
+ first_unseen_msgs[cnum] = get_next_msg_number(cnum-1)
end
mf:close()
+ rf:close()
+
+ return first_unseen_msgs
end
function qwk.write_message_header_block(mf, conf_num, pkt_msg_num, msg)
- mf:write(" ") -- Message status flag
+ print_object(msg)
+ if msg.read then -- Message status flag
+ mf:write("-")
+ else
+ mf:write(" ")
+ end
+
mf:write(space_pad(tostring(msg.number), 7))
mf:write(msg.date) -- mm-dd-yy
mf:write(msg.time) -- hh:mm
local function store_nncp_userdata()
local fh = assert(io.open(qb.path .. "/nncp_users.lua", "w"))
for uid,tab in pairs(nncp_userdata) do
- fh:write("nncp_userdata[" .. string.format("%q",uid) .. "] = {\n")
- for k,v in pairs(tab) do
- fh:write("\t" .. k .. "=" .. string.format("%q", v) .. ",\n")
- end
- fh:write("}\n")
+ fh:write("nncp_userdata[" .. string.format("%q",uid) .. "] = ")
+ write_object(fh, tab)
+ fh:write("\n")
+ -- for k,v in pairs(tab) do
+ -- fh:write("\t" .. k .. "=" .. string.format("%q", v) .. ",\n")
+ -- end
+ -- fh:write("}\n")
end
end
local handle = string.match(input_string, "^%s*get%s+(%w+)%s*$")
if handle then
nncp_userdata[node_id].handle = handle
- store_nncp_userdata()
else
handle = nncp_userdata[node_id].handle
end
fs.rmfile(out_file_name)
local out_file_name = out_file_name .. ".qwk"
- qwk.build_qwk(handle, out_file_name)
+ nncp_userdata[node_id].next_unread_msgs =
+ qwk.build_qwk(handle, out_file_name,
+ nncp_userdata[node_id].next_unread_msgs)
print(qb.nncp_file .. " " .. out_file_name .. " " ..
node_id .. ":" .. qb.bbsid .. ".QWK")
- os.execute(qb.nncp_file .. " " .. out_file_name .. " " ..
- node_id .. ":" .. qb.bbsid .. ".QWK")
- -- fs.copy(out_file_name, qb.path .. "/blah.qwk")
+ -- os.execute(qb.nncp_file .. " " .. out_file_name .. " " ..
+ -- node_id .. ":" .. qb.bbsid .. ".QWK")
+ fs.copy(out_file_name, qb.path .. "/blah.qwk")
fs.rmfile(out_file_name)
+ store_nncp_userdata()
+
else
local handle = nncp_userdata[node_id].handle