From 8ca650847f91c09a767d9eb51593040ec54877b7 Mon Sep 17 00:00:00 2001 From: plugd Date: Wed, 21 Aug 2024 21:27:32 +0200 Subject: [PATCH] Mark downloaded msgs as "read". --- qwikboard | 91 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/qwikboard b/qwikboard index 4c91169..3d51bbd 100755 --- a/qwikboard +++ b/qwikboard @@ -38,21 +38,28 @@ end --- 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 @@ -121,7 +128,8 @@ function fs.getmd5(filename) return string.match(md5f_str, "^(%w+)%s") end ---- Message database parsing --- + +--- Message database --- function Message(msg) msgs[msg.number] = msg @@ -170,7 +178,9 @@ end 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 @@ -184,13 +194,15 @@ function qwk.build_qwk(user_name, qwk_filename) -- 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 @@ -220,9 +232,15 @@ function qwk.write_control(target_dir, user_name) 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)) @@ -232,16 +250,36 @@ function qwk.write_message (target_dir) 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