First messages.dat block.
authorplugd <plugd@thelambdalab.xyz>
Sat, 3 Aug 2024 03:09:15 +0000 (05:09 +0200)
committerplugd <plugd@thelambdalab.xyz>
Sat, 3 Aug 2024 03:09:15 +0000 (05:09 +0200)
obbs

diff --git a/obbs b/obbs
index 32b6c0b..4c7e4b8 100755 (executable)
--- a/obbs
+++ b/obbs
@@ -36,6 +36,9 @@ local function print_table (t, lev)
    end
 end
 
+local function space_pad(s, n)
+   return string.sub(s,1,n) .. string.rep(" ", math.max(0,n-string.len(s)))
+end
 
 local fs = {}
 
@@ -69,6 +72,51 @@ function fs.mktempdir()
    return posix.mkdtemp("/tmp/obbs-XXXXXX")
 end
 
+--- QWK formatting ---
+
+local qwk = {}
+
+function qwk.write_control(cf, obbs, user_name)
+   cf:write(obbs.name .. "\r\n")
+   cf:write("\r\n") -- BBS location
+   cf:write("\r\n") -- BBS phone number
+   cf:write(obbs.sysop .. "\r\n")
+   cf:write("," .. obbs.bbsid .. "\r\n")
+   cf:write(os.date("%d-%m-%Y,%X") .. "\r\n") -- packet creation time
+   cf:write(user_name .. "\r\n")
+   cf:write("\r\n")
+   cf:write(0 .. "\r\n")
+   cf:write(0 .. "\r\n") -- TODO: Number of messages in packet
+   cf:write(#obbs.conferences-1 .. "\r\n") -- Index of final conference
+   for i,v in ipairs(obbs.conferences) do
+      cf:write(i-1 .. "\r\n")
+      cf:write(v .. "\r\n")
+   end
+
+   cf:write("HELLO\r\n")
+   cf:write("NEWS\r\n")
+   cf:write("GOODBYE\r\n")
+end
+
+function qwk.write_message (mf, obbs)
+   mf:write(space_pad("Produced by Qmail...Copyright (c) 1987 by Sparkware." ..
+                      "  All Rights Reserved", 128))
+
+   for cnum,cname in ipairs(obbs.conferences) do
+      for mnum,msg_fname in ipairs(posix.dir(obbs.path .. "/conferences/" .. cname)) do
+         msg = io.open(obbs.path .. "/conferences/" .. cname .. "/" .. msg_fname, "r"):read("*all")
+
+         qwk.write_message_header_block(mf, obbs, cnum, mnum, msg)
+         qwk.write_message_blocks(mf, obbs, msg)
+      end
+   end
+end
+
+function qwk.write_message_header_block(mf, obbs, conf_num, msg)
+end
+
+function qwk.write_message_blocks(mf, obbs, msg)
+end
 
 --- Commands ---
 
@@ -79,6 +127,8 @@ function cmd.newcfg ()
    print [[
 -- OBBS Configuration File
 
+obbs.path = "." -- Path to OBBS root
+
 obbs.name = "My OBBS Name"
 obbs.bbsid = "MYOBBSID" -- max 8 char
 obbs.sysop = "Sysop Name"
@@ -99,20 +149,20 @@ end
 function cmd.init ()
    load_config()
 
-   if fs.exists("conferences") or
-      fs.exists("incoming") or
-      fs.exists("outgoing") then
+   if fs.exists(obbs.path .. "/conferences") or
+      fs.exists(obbs.path .. "/incoming") or
+      fs.exists(obbs.path .. "/outgoing") then
       print("One or more OBBS directories already exist. Aborting.")
       return
    end
 
-   fs.mkdir("conferences")
+   fs.mkdir(obbs.path .. "conferences")
    for i,v in ipairs(obbs.conferences) do
-      fs.mkdir("conferences/" .. v)
+      fs.mkdir(obbs.path .. "conferences/" .. v)
    end
 
-   fs.mkdir("incoming")
-   fs.mkdir("outgoing")
+   fs.mkdir(obbs.path .. "incoming")
+   fs.mkdir(obbs.path .. "outgoing")
 end
 
 -- Pack 
@@ -131,25 +181,7 @@ function cmd.pack ()
    -- CONTROL.DAT
 
    local cf = assert(io.open(dir .. "/CONTROL.DAT", "w"))
-   cf:write(obbs.name .. "\r\n")
-   cf:write("\r\n") -- BBS location
-   cf:write("\r\n") -- BBS phone number
-   cf:write(obbs.sysop .. "\r\n")
-   cf:write("," .. obbs.bbsid .. "\r\n")
-   cf:write(os.date("%d-%m-%Y,%X") .. "\r\n") -- packet creation time
-   cf:write(user_name .. "\r\n")
-   cf:write("\r\n")
-   cf:write(0 .. "\r\n")
-   cf:write(0 .. "\r\n") -- TODO: Number of messages in packet
-   cf:write(#obbs.conferences-1 .. "\r\n") -- Index of final conference
-   for i,v in ipairs(obbs.conferences) do
-      cf:write(i-1 .. "\r\n")
-      cf:write(v .. "\r\n")
-   end
-
-   cf:write("HELLO\r\n")
-   cf:write("NEWS\r\n")
-   cf:write("GOODBYE\r\n")
+   qwk.write_control(cf, obbs, user_name)
    cf:close()
 
    -- Copy BBS welcome, news and goodbye files
@@ -174,9 +206,15 @@ function cmd.pack ()
 
    -- Pack messages
 
+   local mf = assert(io.open(dir .. "/MESSAGES.DAT", "w"))
+   qwk.write_message(mf, obbs)
+   mf:close()
+
    -- Create archive in outgoing
 
-   os.execute("zip -rj outgoing/" .. obbs.bbsid .. ".qwk " .. dir)
+   os.execute("zip -rj " .. obbs.path ..
+              "/outgoing/" .. obbs.bbsid ..
+              ".qwk " .. dir)
 
    fs.rmdir(dir)
 end