os = require "os" socket = require "socket" function shortname() local long = socket.dns.gethostname() return string.gmatch(long, '[^.]+')() end function get_queue(mbox) --TODO: try to get tail return mbox.FILTER_QUEUE:is_newer(84) end function _notifirc1(subj, from, body) --notify about message using (pre-configured) notifirc local fd = assert(io.popen('notifirc -f - "message preview:"', "w")) local fmt = "> %s\n> %s\n> BODY: %s" fd:write(fmt:format(subj, from, body)) fd:close() end function notifirc_all(seq) for _, mesg in ipairs(seq) do mbox, uid = table.unpack(mesg) subj = mbox[uid]:fetch_field('Subject') from = mbox[uid]:fetch_field('From') body = mbox[uid]:fetch_body() _notifirc1(subj, from, body) end end function _partinf_compare(a, b) if not type(a) == type(b) then return false end if type(a) == 'number' then return a == b elseif type(a) == 'string' then return a:lower() == b:lower() end end function has_part_like(query, structure) if structure == nil then return false end for partid, partinf in pairs(structure) do local part_answer = true -- check all query parts for qkey, qvalue in pairs(query) do value = partinf[qkey] if not _partinf_compare(value, qvalue) then part_answer = false break end end if part_answer then return true end end return false end function filter_part_like(query, seq) result = Set {} for _, mesg in ipairs(seq) do mbox, uid = table.unpack(mesg) structure = mbox[uid]:fetch_structure() if has_part_like(query, structure) then table.insert(result, mesg) end end return result end