Reworked counters in mboxc, mdir, org

This commit is contained in:
Adrian C. (anrxc) 2009-10-04 00:31:12 +02:00
parent b185e96494
commit b65d509380
3 changed files with 24 additions and 38 deletions

View File

@ -17,34 +17,30 @@ module("vicious.mboxc")
-- {{{ Mbox count widget type -- {{{ Mbox count widget type
local function worker(format, mbox) local function worker(format, mbox)
-- Initialise counters -- Initialise counters
local count = { local count = { old = 0, total = 0, new = 0 }
old = 0,
total = 0,
new = 0
}
-- Get data from mbox files -- Get data from mbox files
for i=1, #mbox do for i=1, #mbox do
local f = io.open(mbox[i]) local f = io.open(mbox[i])
while true do while true do
-- Read the mbox line by line, if we are going to read some -- Read the mbox line by line, if we are going to read some
-- *HUGE* folders then switch to reading chunks -- *HUGE* folders then switch to reading chunks
local lines = f:read("*line") local lines = f:read("*line")
if not lines then break end if not lines then break end
-- Find all messages -- Find all messages
-- * http://www.jwz.org/doc/content-length.html -- * http://www.jwz.org/doc/content-length.html
local _, from = string.find(lines, "^From[%s]") local _, from = string.find(lines, "^From[%s]")
if from ~= nil then count.total = count.total + 1 end if from ~= nil then count.total = count.total + 1 end
-- Read messages have the Status header -- Read messages have the Status header
local _, status = string.find(lines, "^Status:[%s]RO$") local _, status = string.find(lines, "^Status:[%s]RO$")
if status ~= nil then count.old = count.old + 1 end if status ~= nil then count.old = count.old + 1 end
-- Skip the folder internal data -- Skip the folder internal data
local _, intdata = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA") local _, int = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA")
if intdata ~= nil then count.total = count.total - 1 end if int ~= nil then count.total = count.total - 1 end
end end
f:close() f:close()
end end

View File

@ -17,24 +17,19 @@ module("vicious.mdir")
-- {{{ Maildir widget type -- {{{ Maildir widget type
local function worker(format, mdir) local function worker(format, mdir)
-- Initialise counters -- Initialise counters
local newcount = 0 local count = { new = 0, cur = 0 }
local curcount = 0
-- Recursively find new messages -- Recursively find new messages
local fnew = io.popen("find " .. mdir .. " -type f -wholename '*/new/*'") local f = io.popen("find " .. mdir .. " -type f -wholename '*/new/*'")
for line in fnew:lines() do for line in f:lines() do count.new = count.new + 1 end
newcount = newcount + 1 f:close()
end
fnew:close()
-- Recursively find "old" messages lacking the Seen flag -- Recursively find "old" messages lacking the Seen flag
local fcur = io.popen("find " .. mdir .. " -type f -regex '.*/cur/.*2,[^S]*$'") local f = io.popen("find " .. mdir .. " -type f -regex '.*/cur/.*2,[^S]*$'")
for line in fcur:lines() do for line in f:lines() do count.cur = count.cur + 1 end
curcount = curcount + 1 f:close()
end
fcur:close()
return {newcount, curcount} return {count.new, count.cur}
end end
-- }}} -- }}}

View File

@ -27,12 +27,7 @@ local function worker(format, files)
local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
-- Initialise counters -- Initialise counters
local count = { local count = { past = 0, today = 0, soon = 0, future = 0 }
past = 0,
today = 0,
soon = 0,
future = 0
}
-- Get data from agenda files -- Get data from agenda files
for i=1, #files do for i=1, #files do