2024-10-28 07:41:53 +01:00
|
|
|
options.timeout = 120
|
|
|
|
options.create = false
|
|
|
|
options.subscribe = false
|
|
|
|
options.expunge = true
|
|
|
|
|
|
|
|
function move_mails(account, mails)
|
|
|
|
move_if_contains(account, mails, "linux-bluetooth" , "bluez" )
|
|
|
|
move_if_contains(account, mails, "coffee" , "Coffee" )
|
|
|
|
move_if_contains(account, mails, "freedesktop.org" , "FreedesktopGitlab")
|
|
|
|
move_if_contains(account, mails, "gstreamer-devel" , "gstreamer" )
|
|
|
|
move_if_contains(account, mails, "gstreamer-embedded" , "gstreamer" )
|
|
|
|
move_if_contains(account, mails, "ietf.org" , "ietf" )
|
|
|
|
move_if_contains(account, mails, "monster.com" , "Jobs" )
|
|
|
|
move_if_contains(account, mails, "naukri.com" , "Jobs" )
|
|
|
|
move_if_contains(account, mails, "lists.infradead.org" , "Linux Kernel" )
|
|
|
|
move_if_contains(account, mails, "vger.kernel.org" , "Linux Kernel" )
|
|
|
|
move_if_contains(account, mails, "u-boot@lists.denx.de", "Uboot" )
|
|
|
|
move_if_contains(account, mails, "bseindia.in" , "Zerodha" )
|
|
|
|
move_if_contains(account, mails, "cdslindia.co.in" , "Zerodha" )
|
|
|
|
move_if_contains(account, mails, "zerodha.net" , "Zerodha" )
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
function move_if_contains(account, mails, contain, mailbox)
|
|
|
|
local filtered = mails:contain_cc(contain)
|
2016-03-07 17:31:28 +01:00
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
filtered = mails:contain_from(contain)
|
2016-03-07 17:31:28 +01:00
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
filtered = mails:contain_to(contain)
|
2016-03-07 17:31:28 +01:00
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_to_gmail_trash(account, mails, mailbox)
|
2024-10-28 07:41:53 +01:00
|
|
|
local filtered = mails:select_all()
|
2016-03-07 17:31:28 +01:00
|
|
|
filtered:move_messages(account[mailbox])
|
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
function delete_trash(mails)
|
|
|
|
local filtered = mails:select_all()
|
|
|
|
filtered:delete_messages()
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
function get_password(pass_account_name)
|
|
|
|
local cmd = "pass show " .. pass_account_name
|
|
|
|
local fd = io.popen(cmd, 'r')
|
|
|
|
local pass = fd:read("*a")
|
|
|
|
fd:close()
|
|
|
|
return pass;
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
-- https://github.com/lefcha/imapfilter/issues/199
|
|
|
|
function sanitize_pwd(pwd)
|
|
|
|
pwd = string.gsub(pwd, "\n", "")
|
|
|
|
pwd = string.gsub(pwd, '%\\', '\\\\')
|
|
|
|
pwd = string.gsub(pwd, '%"', '\\"')
|
|
|
|
return pwd
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
accounts = {}
|
|
|
|
credentials = {
|
|
|
|
["sanchayanmaity.net"] = {
|
|
|
|
server = 'imap.migadu.com',
|
|
|
|
username = 'me@sanchayanmaity.net',
|
|
|
|
password = sanitize_pwd(get_password("migadu/sanchayanmaity.net")),
|
|
|
|
},
|
|
|
|
["sanchayanmaity.com"] = {
|
|
|
|
server = 'imap.migadu.com',
|
|
|
|
username = 'me@sanchayanmaity.com',
|
|
|
|
password = sanitize_pwd(get_password("migadu/sanchayanmaity.com")),
|
|
|
|
},
|
|
|
|
["fastmail"] = {
|
|
|
|
server = 'imap.fastmail.com',
|
|
|
|
username = 'maitysanchayan@fastmail.com',
|
|
|
|
password = get_password("apppass/fastmail"),
|
|
|
|
},
|
|
|
|
["gmail-sanchayan"] = {
|
|
|
|
server = 'imap.gmail.com',
|
|
|
|
username = 'maitysanchayan@gmail.com',
|
|
|
|
password = get_password("apppass/sanchayan"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function map_credentials_to_account(account_name)
|
|
|
|
accounts[account_name] = IMAP {
|
|
|
|
server = credentials[account_name].server,
|
|
|
|
username = credentials[account_name].username,
|
|
|
|
password = credentials[account_name].password,
|
|
|
|
ssl = 'auto',
|
|
|
|
}
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
function filter_mails(account_name)
|
|
|
|
local account = accounts[account_name]
|
2016-03-07 17:31:28 +01:00
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
account.INBOX:check_status()
|
|
|
|
local mails = account.INBOX:select_all()
|
|
|
|
move_mails(account, mails)
|
|
|
|
|
|
|
|
account.Sent:check_status()
|
|
|
|
local mails = account.Sent:select_all()
|
|
|
|
move_mails(account, mails)
|
|
|
|
|
|
|
|
account['Trash']:check_status()
|
|
|
|
local trash_mails = account['Trash']:select_all()
|
|
|
|
|
|
|
|
if string.find(account_name, "gmail") then
|
|
|
|
move_to_gmail_trash(account, trash_mails, '[Gmail]/Trash')
|
|
|
|
mails = account['[Gmail]/Trash']:select_all()
|
|
|
|
delete_trash(mails)
|
|
|
|
else
|
|
|
|
delete_trash(trash_mails)
|
|
|
|
end
|
2020-01-06 06:25:00 +01:00
|
|
|
end
|
|
|
|
|
2024-10-28 07:41:53 +01:00
|
|
|
map_credentials_to_account("sanchayanmaity.net")
|
|
|
|
map_credentials_to_account("sanchayanmaity.com")
|
|
|
|
map_credentials_to_account("fastmail")
|
|
|
|
map_credentials_to_account("gmail-sanchayan")
|
|
|
|
|
|
|
|
for account_name, _ in pairs(accounts) do
|
|
|
|
filter_mails(account_name)
|
|
|
|
end
|