aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-01 11:46:28 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-01 11:46:28 +0200
commit5dac6a44fd38a8f599ed8ad73f98a963123c49fd (patch)
treef5fc2e4e3c0c296553b7ab2c074a20d338471b5a
parent32fe7703c0bed48aa95095dfcd25cefa4e739846 (diff)
downloadvicious-legacy-5dac6a44fd38a8f599ed8ad73f98a963123c49fd.tar.xz
mboxc: support for multiple mbox files
Widget takes a table with full paths to mbox files as an argument.
-rw-r--r--README4
-rw-r--r--mboxc.lua61
2 files changed, 35 insertions, 30 deletions
diff --git a/README b/README
index 0332f88..3945479 100644
--- a/README
+++ b/README
@@ -168,8 +168,8 @@ vicious.widgets.mbox
- takes the full path to the mbox as an argument
vicious.widgets.mboxc
- - provides the count of total, old and new messages in a mbox
- - takes the full path to the mbox as an argument
+ - provides the count of total, old and new messages in mbox files
+ - takes a table with full paths to mbox files as an argument
vicious.widgets.mdir
- provides a number of new and unread messages in a Maildir
diff --git a/mboxc.lua b/mboxc.lua
index 0f45dc3..b254144 100644
--- a/mboxc.lua
+++ b/mboxc.lua
@@ -10,44 +10,49 @@ local string = { find = string.find }
-- }}}
--- Mboxc: provides the count of total, old and new messages in a mbox
+-- Mboxc: provides the count of total, old and new messages in mbox files
module("vicious.mboxc")
-- {{{ Mbox count widget type
local function worker(format, mbox)
-- Initialise counters
- local old = 0
- local total = 0
-
- -- Open the mbox
- local f = io.open(mbox)
-
- 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 total = total + 1 end
-
- -- Read messages have the Status header
- local _, status = string.find(lines, "^Status:[%s]RO$")
- if status ~= nil then old = old + 1 end
-
- -- Skip the folder internal data
- local _, intdata = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA")
- if intdata ~= nil then total = total -1 end
+ 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
+ end
+ f:close()
end
- f:close()
-- Substract total from old to get the new count
- local new = total - old
+ count.new = count.total - count.old
- return {total, old, new}
+ return {count.total, count.old, count.new}
end
-- }}}