mbox: add scrolling support and truncate control

Widget argument can now be a string (full path to the mbox) or a
table. In case of a table 1st field is full path to the mbox and 2nd
is maximum text lenght after which it will be truncated. If there is a
third field scrolling will be used - if so, 3rd field should be the
widget name.
This commit is contained in:
Adrian C. (anrxc) 2009-11-03 01:28:37 +01:00
parent 5ff8927b4b
commit 9e91408ccb
1 changed files with 13 additions and 8 deletions

View File

@ -4,6 +4,7 @@
---------------------------------------------------
-- {{{ Grab environment
local type = type
local io = { open = io.open }
local setmetatable = setmetatable
local string = { gfind = string.gfind }
@ -16,10 +17,11 @@ module("vicious.mbox")
-- {{{ Mailbox widget type
local function worker(format, mbox)
local function worker(format, warg)
if type(warg) ~= "table" then mbox = warg end
-- mbox could be huge, get a 30kb chunk from EOF
-- * attachments could be much bigger than this
local f = io.open(mbox)
local f = io.open(mbox or warg[1])
f:seek("end", -30720)
local txt = f:read("*all")
f:close()
@ -32,13 +34,16 @@ local function worker(format, mbox)
subject = i
end
-- Spam sanitize only the last subject
subject = helpers.escape(subject)
-- Check if we should scroll, or maybe truncate
if type(warg) == "table" then
if warg[3] ~= nil then
subject = helpers.scroll(subject, warg[2], warg[3])
else
subject = helpers.truncate(subject, warg[2])
end
end
-- Don't abuse the wibox, truncate
subject = helpers.truncate(subject, 22)
return {subject}
return {helpers.escape(subject)}
end
-- }}}