Here's a script which parses the lua-l mailing list archive


  #!/usr/bin/env ./lux

  -- Browse mailbox through CGI
  -- 13/02/2001 jcw@equi4.com

  dofile('util.lua')

  mbox={}

  function mbox.indexmethod(t,i)
    return mbox.rfc822(mmsub(t.map,t.offsets[i],t.offsets[i+1]-1))
  end

  function mbox.rfc822(s)
    local n=strfind(s,'\n\n')
    local t=linesplit(strsub(s,1,n or strlen(s)))
    local h,last={}
    assert(strsub(t[1],1,5)=='From ')
    h['(from)']=strsub(t[1],6)
    if n then h['(body)']=strsub(s,n+2) end
    for i=2,getn(t) do
      local l=t[i]
      if l=="" then break end
      local l=gsub(t[i],'%s+$','')
      local a,b,s=strfind(l,'^%s+([^%s].*)$')
      if a then
        if last then h[last]=h[last]..gsub(l,'^%s*','\n') end
      else
        local a,b,n,v=strfind(l,'^(..-):%s*(.*)')
        if a then
          n=strlower(n)
          h[n],last=v,n
        else
          last = nil
        end
      end
    end
    return h
  end

  function mbox.Open(name)
    local t={}
    settag(t,newtag())
    settagmethod(tag(t),"index",mbox.indexmethod)
    t.map=mmfile(name)
    local y=name..'.index'
    assert(not x)
    if dofile(y) and x then
      t.offsets=x
      x=nil
    else
      local s=mmsub(t.map)
      local o,n=1,strlen(s)
      t.offsets={}
      while 1 do
        local p=strfind(s,'\nFrom ',o,1)
        if not p then break end
        tinsert(t.offsets,o)
        o=p+1
      end
      tinsert(t.offsets,n+1)
      writeto(y)
      savevar('x',t.offsets)
      writeto()
    end
    t.n=getn(t.offsets)-1
    return t
  end

  print 'Content-Type: text/html'
  print ''

  _ERRORMESSAGE = function (s)
                    print "<h3>Error in cgi script</h3>"
                    print(s,getinfo(2).currentline,getinfo(3).currentline)
                  end

  env=getenv()
  if not env.PATH_INFO then
    print '<pre>'
      if argv[1]=='lua' then
        print(htmlize(fetchfile('lua-l.cgi')))
      else
        for i,v in env do print(i,v) end
      end
    print '</pre>'
    exit()
  end

  mb=mbox.Open('lua-l.mbox')

  msgnum=tonumber(strsub(env.PATH_INFO,2))

  if msgnum then
    local m=mb[tonumber(strsub(env.PATH_INFO,2))]
    write('<br><b>Subject:</b> ',m.subject or '')
    write('<br><b>From:</b> ',m.from or '')
    write('<br><b>Date:</b> ',m.date or '')
    write('<pre>',htmlize(m['(body)']),'</pre>')
  else
    for i=getn(mb),1,-1 do
      local m=mb[i]
      write('<a href=',i,'>',m.subject or '','</a> - ',m.from or '',
                  ' - <i>',m.date or '','</i><br>')
    end
    exit()
  end

  -- vim: set ft=lua :

Notes:

This code is currently (mid Feb 2001) running as demo at:

    http://mini.net/cgi-bin/lua-l/

The returned page is a huge index. Individual messages can be browsed by adding a number, e.g. http://mini.net/cgi-bin/lua-l/2899


Last modified
2001-02-14

(216.232.136.19)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated