From: plugd Date: Wed, 21 Aug 2024 20:38:07 +0000 (+0200) Subject: Added export command. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=61bdeffe62cfc5fb72773dbf98570033557e5b8c;p=qwikboard.git Added export command. --- 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