From 61bdeffe62cfc5fb72773dbf98570033557e5b8c Mon Sep 17 00:00:00 2001 From: plugd Date: Wed, 21 Aug 2024 22:38:07 +0200 Subject: [PATCH] Added export command. --- qwikboard | 83 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/qwikboard b/qwikboard index 57af5f1..fa0aba1 100755 --- a/qwikboard +++ b/qwikboard @@ -173,6 +173,28 @@ local function append_new_msg(conf_num, msg) cf:close() end +local function export_messages(handle, output_file_name) + + local fh = assert(io.open(output_file_name, "w")) + + for cnum,cname in ipairs(qb.conferences) do + msgs = {} + dofile(qb.path .. "/conferences/" .. cname .. ".msgs") + for i,msg in ipairs(msgs) do + if string.match(string.lower(msg.from), "^%s*" .. string.lower(handle) .. "%s*$") then + fh:write("MessageArea: " .. cname .. "\n") + fh:write("MessageNum: " .. msg.number .. "\n") + fh:write("From: " .. msg.from .. "\n") + fh:write("To: " .. msg.to .. "\n") + fh:write("Subject: " .. msg.subject .. "\n") + fh:write("Date: " .. msg.date .. "\n") + fh:write("Time: " .. msg.time .. "\n") + fh:write("---\n") + fh:write(msg.text .. "\n\n") + end + end + end +end --- QWK formatting --- @@ -564,6 +586,7 @@ exec: { store_nncp_userdata() else + local handle = nncp_userdata[node_id].handle if not handle then @@ -571,34 +594,50 @@ exec: { return false end - print("Accepting REP packet from user '" .. handle .. "'") - -- Accept REP packet + if string.match(input_string, "^%s*export") then + -- Constructing text file for export - local rep_file_name = os.tmpname() - fs.rmfile(rep_file_name) - local rep_file_name = rep_file_name .. ".rep" + local out_file_name = os.tmpname() - local rf = assert(io.open(rep_file_name, "w")) - rf:write(input_string) - rf:close() + export_messages(handle, out_file_name) - if qb.md5sum then - -- Check for duplicate REP submissions - - local md5 = fs.getmd5(rep_file_name) - local stored_md5 = nncp_userdata[node_id].md5 - if stored_md5 and md5 == stored_md5 then - print("Error: Duplicate REP submission detected. Skipping.") - return false - end + print(qb.nncp_file .. " " .. out_file_name .. " " .. + node_id .. ":" .. qb.bbsid .. ".export.txt") + -- os.execute(qb.nncp_file .. " " .. out_file_name .. " " .. + -- node_id .. ":" .. qb.bbsid .. ".export.txt") - nncp_userdata[node_id].md5 = md5 - store_nncp_userdata() - end + fs.rmfile(out_file_name) - qwk.import_rep(handle, rep_file_name) + else + print("Accepting REP packet from user '" .. handle .. "'") + -- Accept REP packet + + local rep_file_name = os.tmpname() + fs.rmfile(rep_file_name) + local rep_file_name = rep_file_name .. ".rep" + + local rf = assert(io.open(rep_file_name, "w")) + rf:write(input_string) + rf:close() + + if qb.md5sum then + -- Check for duplicate REP submissions + + local md5 = fs.getmd5(rep_file_name) + local stored_md5 = nncp_userdata[node_id].md5 + if stored_md5 and md5 == stored_md5 then + print("Error: Duplicate REP submission detected. Skipping.") + return false + end + + nncp_userdata[node_id].md5 = md5 + store_nncp_userdata() + end - fs.rmfile(rep_file_name) + qwk.import_rep(handle, rep_file_name) + + fs.rmfile(rep_file_name) + end end end -- 2.20.1