From: plugd Date: Wed, 7 Aug 2024 11:25:31 +0000 (+0200) Subject: Rep file msg format parsing almost complete. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=c081b142c44d47d252e81e59b738f9bac18782c3;p=qwikboard.git Rep file msg format parsing almost complete. --- diff --git a/obbs b/obbs index 8b524b7..a2876a2 100755 --- a/obbs +++ b/obbs @@ -140,8 +140,7 @@ function qwk.write_message (target_dir, obbs) local pkt_msg_num = 0 - mf:write(space_pad("Produced by Qmail...Copyright (c) 1987 by Sparkware." .. - " All Rights Reserved", 128)) + mf:write(space_pad("Produced by OBBS.", 128)) for cnum,cname in ipairs(obbs.conferences) do msgs = {} @@ -149,7 +148,7 @@ function qwk.write_message (target_dir, obbs) for i,msg in ipairs(msgs) do pkt_msg_num = pkt_msg_num + 1 qwk.write_message_header_block(mf, obbs, cnum, pkt_msg_num, msg) - qwk.write_message_blocks(mf, obbs, msg) + qwk.write_message_text(mf, obbs, msg) end end @@ -181,7 +180,7 @@ function qwk.write_message_header_block(mf, obbs, conf_num, pkt_msg_num, msg) mf:write(" ") -- No network tag-line present end -function qwk.write_message_blocks(mf, obbs, msg) +function qwk.write_message_text(mf, obbs, msg) mf:write((string.gsub(msg.text, "\n", "\xe3"))) local padding = (128 - (string.len(msg.text) % 128)) % 128 @@ -190,17 +189,61 @@ end function qwk.read_message(archive_dir, obbs, user_name) - local msg_filename = work_dir .. "/" .. obbs.bbsid .. ".MSG" + local msg_filename = archive_dir .. "/" .. obbs.bbsid .. ".MSG" if not fs.exists(msg_filename) then print("Error: MSG file not found.") - return + return false + end + + local mf = assert(io.open(msg_filename, "r")) + local block = mf:read(128) + + if not string.find(block, obbs.bbsid .. " *") then + print("Error: Failed to match BBSID in first block.") + return false + end + + while mf:read(0) do + qwk.read_message_header(mf, obbs) end +end - local mf = asert(io.open(msg_filename, "r")) +function qwk.read_message_header(mf, obbs) + local msg = {} + + mf:read(1) -- Message status (ignore for now) + local conf_num = tonumber(mf:read(7)) + msg.date = mf:read(8) + msg.time = mf:read(5) + msg.to = mf:read(25) + msg.from = mf:read(25) + msg.subject = mf:read(25) + mf:read(12) -- Password (unused) + msg.replyto = tonumber(mf:read(8)) + + local nblocks = tonumber(mf:read(6)) + + mf:read(1) -- flag (ignore for now) + mf:read(2) -- conference number (already have this) + mf:read(2) -- message number in packet (unused) + mf:read(1) -- network tag flag (ignore) + + msg.text = "" + for b=2,nblocks do + msg.text = msg.text .. mf:read(128) + end + msg.text = string.gsub(msg.text, "\xe3", "\n") + print("Message{") + for k,v in pairs(msg) do + print("\t" .. k .. "=\'" .. v .. "',") + end + print("}") end +function qwk.read_message_text(mf, obbs, msg) +end --- Commands ---