mail: Move rollup data to XDG data dir
Moved the file containing sender addresses to filter to the XDG_DATA_HOME directory (usually `~/.local/share/imapfilter/`) where it will look for a `rollup.txt` file. This is to separate the configuration values (the filters themselves) somewhat from the data they act on (values to filter and searches to accomplish).
This commit is contained in:
parent
2b289a953b
commit
b176b61b52
1 changed files with 23 additions and 7 deletions
|
@ -1,21 +1,37 @@
|
||||||
function sendToFolder(folderFrom, folderTo, senders)
|
function sendToFolder(folderFrom, folderTo, senders)
|
||||||
|
local messages = folderFrom:select_all()
|
||||||
for _, sender in pairs(senders) do
|
for _, sender in pairs(senders) do
|
||||||
messages = folderFrom:contain_from(sender)
|
local filtered=messages:contain_from(sender)
|
||||||
messages:mark_seen()
|
filtered:mark_seen()
|
||||||
messages:move_messages(folderTo)
|
filtered:move_messages(folderTo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function getSenderList(file)
|
-- 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)
|
||||||
local rollupSenders={}
|
local rollupSenders={}
|
||||||
|
|
||||||
local file = io.open(file)
|
local file = io.open(rollupfile)
|
||||||
if file then
|
if file then
|
||||||
for line in file:lines() do
|
for line in file:lines() do
|
||||||
table.insert(rollupSenders, line)
|
table.insert(rollupSenders, line)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("ERROR: rollup did not find rollup.txt file containing mail addresses.")
|
print("ERROR: rollup did not find rollup.txt file containing mail addresses at " .. rollupfile or "" )
|
||||||
end
|
end
|
||||||
return rollupSenders
|
return rollupSenders
|
||||||
end
|
end
|
||||||
|
@ -23,5 +39,5 @@ end
|
||||||
sendToFolder (
|
sendToFolder (
|
||||||
accounts.gmail["Inbox"],
|
accounts.gmail["Inbox"],
|
||||||
accounts.gmail["Dump"],
|
accounts.gmail["Dump"],
|
||||||
getSenderList(getConfigDir() .. "/rollup.txt")
|
getSenderList(getRollupFile())
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue