2020-09-18 10:25:49 +00:00
|
|
|
function sendToFolder(folderFrom, folderTo, senders)
|
2020-09-21 07:44:20 +00:00
|
|
|
local messages = folderFrom:select_all()
|
2020-09-17 17:49:53 +00:00
|
|
|
for _, sender in pairs(senders) do
|
2020-09-21 07:44:20 +00:00
|
|
|
local filtered=messages:contain_from(sender)
|
|
|
|
filtered:mark_seen()
|
|
|
|
filtered:move_messages(folderTo)
|
2020-09-17 17:49:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-21 07:44:20 +00:00
|
|
|
-- will set filters to be grabbed from XDG-compliant filter directory
|
|
|
|
-- can be overridden with env var IMAPFILTER_ROLLUPFILE
|
|
|
|
function getRollupFile(fname)
|
|
|
|
local f
|
|
|
|
local fname=fname or "rollup.txt"
|
|
|
|
if os.getenv("IMAPFILTER_ROLLUPFILE") then
|
|
|
|
f=os.getenv("IMAPFILTER_ROLLUPFILE")
|
|
|
|
elseif os.getenv("XDG_DATA_HOME") then
|
|
|
|
f=os.getenv("XDG_DATA_HOME") .. "/imapfilter/" .. fname
|
|
|
|
else
|
|
|
|
f=os.getenv("HOME") .. "/.local/share/imapfilter/" .. fname
|
|
|
|
end
|
|
|
|
return f
|
|
|
|
end
|
|
|
|
|
|
|
|
function getSenderList(rollupfile)
|
2020-09-18 15:10:19 +00:00
|
|
|
local rollupSenders={}
|
|
|
|
|
2020-09-21 07:44:20 +00:00
|
|
|
local file = io.open(rollupfile)
|
2020-09-18 15:10:19 +00:00
|
|
|
if file then
|
|
|
|
for line in file:lines() do
|
|
|
|
table.insert(rollupSenders, line)
|
|
|
|
end
|
|
|
|
else
|
2020-09-21 07:44:20 +00:00
|
|
|
print("ERROR: rollup did not find rollup.txt file containing mail addresses at " .. rollupfile or "" )
|
2020-09-18 15:10:19 +00:00
|
|
|
end
|
|
|
|
return rollupSenders
|
2020-09-17 17:49:53 +00:00
|
|
|
end
|
2020-09-18 15:10:19 +00:00
|
|
|
|
|
|
|
sendToFolder (
|
|
|
|
accounts.gmail["Inbox"],
|
|
|
|
accounts.gmail["Dump"],
|
2020-09-21 07:44:20 +00:00
|
|
|
getSenderList(getRollupFile())
|
2020-09-18 15:10:19 +00:00
|
|
|
)
|