aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-04 00:31:12 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-04 00:31:12 +0200
commitb65d5093803ec81f89f286c90807a44fa219c733 (patch)
treeaec5114ef7a8dfdc6c67c8aaebe6d308fa741f28
parentb185e964945cf4bb58606a154922e5e7f079b0c0 (diff)
downloadvicious-legacy-b65d5093803ec81f89f286c90807a44fa219c733.tar.xz
Reworked counters in mboxc, mdir, org
-rw-r--r--mboxc.lua40
-rw-r--r--mdir.lua21
-rw-r--r--org.lua7
3 files changed, 27 insertions, 41 deletions
diff --git a/mboxc.lua b/mboxc.lua
index b254144..1861b15 100644
--- a/mboxc.lua
+++ b/mboxc.lua
@@ -17,34 +17,30 @@ module("vicious.mboxc")
-- {{{ Mbox count widget type
local function worker(format, mbox)
-- Initialise counters
- local count = {
- old = 0,
- total = 0,
- new = 0
- }
+ local count = { old = 0, total = 0, new = 0 }
-- Get data from mbox files
for i=1, #mbox do
local f = io.open(mbox[i])
while true do
- -- Read the mbox line by line, if we are going to read some
- -- *HUGE* folders then switch to reading chunks
- local lines = f:read("*line")
- if not lines then break end
-
- -- Find all messages
- -- * http://www.jwz.org/doc/content-length.html
- local _, from = string.find(lines, "^From[%s]")
- if from ~= nil then count.total = count.total + 1 end
-
- -- Read messages have the Status header
- local _, status = string.find(lines, "^Status:[%s]RO$")
- if status ~= nil then count.old = count.old + 1 end
-
- -- Skip the folder internal data
- local _, intdata = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA")
- if intdata ~= nil then count.total = count.total - 1 end
+ -- Read the mbox line by line, if we are going to read some
+ -- *HUGE* folders then switch to reading chunks
+ local lines = f:read("*line")
+ if not lines then break end
+
+ -- Find all messages
+ -- * http://www.jwz.org/doc/content-length.html
+ local _, from = string.find(lines, "^From[%s]")
+ if from ~= nil then count.total = count.total + 1 end
+
+ -- Read messages have the Status header
+ local _, status = string.find(lines, "^Status:[%s]RO$")
+ if status ~= nil then count.old = count.old + 1 end
+
+ -- Skip the folder internal data
+ local _, int = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA")
+ if int ~= nil then count.total = count.total - 1 end
end
f:close()
end
diff --git a/mdir.lua b/mdir.lua
index abe3aa0..5aafdd1 100644
--- a/mdir.lua
+++ b/mdir.lua
@@ -17,24 +17,19 @@ module("vicious.mdir")
-- {{{ Maildir widget type
local function worker(format, mdir)
-- Initialise counters
- local newcount = 0
- local curcount = 0
+ local count = { new = 0, cur = 0 }
-- Recursively find new messages
- local fnew = io.popen("find " .. mdir .. " -type f -wholename '*/new/*'")
- for line in fnew:lines() do
- newcount = newcount + 1
- end
- fnew:close()
+ local f = io.popen("find " .. mdir .. " -type f -wholename '*/new/*'")
+ for line in f:lines() do count.new = count.new + 1 end
+ f:close()
-- Recursively find "old" messages lacking the Seen flag
- local fcur = io.popen("find " .. mdir .. " -type f -regex '.*/cur/.*2,[^S]*$'")
- for line in fcur:lines() do
- curcount = curcount + 1
- end
- fcur:close()
+ local f = io.popen("find " .. mdir .. " -type f -regex '.*/cur/.*2,[^S]*$'")
+ for line in f:lines() do count.cur = count.cur + 1 end
+ f:close()
- return {newcount, curcount}
+ return {count.new, count.cur}
end
-- }}}
diff --git a/org.lua b/org.lua
index cdf73c3..ea50db9 100644
--- a/org.lua
+++ b/org.lua
@@ -27,12 +27,7 @@ local function worker(format, files)
local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
-- Initialise counters
- local count = {
- past = 0,
- today = 0,
- soon = 0,
- future = 0
- }
+ local count = { past = 0, today = 0, soon = 0, future = 0 }
-- Get data from agenda files
for i=1, #files do