diff --git a/mail/.config/imapfilter/config.lua b/mail/.config/imapfilter/config.lua index a09e6ac..80a58e6 100644 --- a/mail/.config/imapfilter/config.lua +++ b/mail/.config/imapfilter/config.lua @@ -12,6 +12,13 @@ options.subscribe = true -- How long to wait for servers response. options.timeout = 120 +-- whether to enter IDLE mode and conintuously check +-- for new incoming mail to filter +CONTINUOUS=false +-- time to wait for next synchronization +-- only used in case server does not support IDLE mode +UPDATE_TIME=120 + -- will set filters to be grabbed from XDG-compliant filter directory -- can be overridden with env var IMAPFILTER_FILTERDIR function getConfigDir() @@ -56,4 +63,21 @@ assert(configDir, "No configuration directory found. Ensure " .. os.getenv("HOME accounts = loadfile(configDir .. "/accounts.lua")() assert(accounts, "No accounts configured. Ensure accounts.lua exists and returns a table of accounts.") +-- implement simple wait function in case server does not support IDLE mode +function sleep(n) + os.execute("sleep " .. tonumber(n)) +end + +-- immediately act on the filters once applyFilters(getFilterDir()) + +-- continuously watch for mail if needed +while CONTINUOUS==true do + local has_idle=accounts.gmail['Inbox']:enter_idle() + applyFilters(getFilterDir()) + + if has_idle == false then + print("Server does not support idle, application will be polling again in " .. UPDATE_TIME .. "minutes.") + sleep(UPDATE_TIME) + end +end