2016-03-07 17:31:28 +01:00
|
|
|
function main()
|
2021-02-11 09:46:19 +01:00
|
|
|
local fastmail = IMAP {
|
|
|
|
server = 'imap.fastmail.com',
|
|
|
|
username = 'maitysanchayan@fastmail.com',
|
|
|
|
password = get_pwd_fastmail(),
|
|
|
|
ssl = 'tls1',
|
|
|
|
}
|
|
|
|
|
|
|
|
fastmail.INBOX:check_status()
|
|
|
|
mails = fastmail.INBOX:select_all()
|
|
|
|
move_mailing_lists(fastmail, mails)
|
|
|
|
mails = fastmail.Sent:select_all()
|
|
|
|
move_mailing_lists(fastmail, mails)
|
|
|
|
mails = fastmail['Trash']:select_all()
|
2021-02-19 06:30:35 +01:00
|
|
|
delete_from_trash(fastmail, mails)
|
2021-02-11 09:46:19 +01:00
|
|
|
mails = fastmail['Spam']:select_all()
|
|
|
|
move_mailing_lists(fastmail, mails)
|
|
|
|
|
2016-03-07 17:31:28 +01:00
|
|
|
local sanchayan = IMAP {
|
|
|
|
server = 'imap.gmail.com',
|
|
|
|
username = 'maitysanchayan@gmail.com',
|
|
|
|
password = get_pwd_sanchayan(),
|
|
|
|
ssl = 'tls1',
|
|
|
|
}
|
|
|
|
|
|
|
|
sanchayan.INBOX:check_status()
|
|
|
|
-- sanchayan['[Gmail]/Trash']:check_status()
|
|
|
|
-- sanchayan['[Gmail]/Spam']:check_status()
|
|
|
|
mails = sanchayan.INBOX:select_all()
|
|
|
|
move_mailing_lists(sanchayan, mails)
|
|
|
|
mails = sanchayan.Sent:select_all()
|
|
|
|
move_mailing_lists(sanchayan, mails)
|
|
|
|
mails = sanchayan['[Gmail]/Trash']:select_all()
|
|
|
|
imap_trash = sanchayan['Trash']:select_all()
|
|
|
|
move_to_gmail_trash(sanchayan, imap_trash, '[Gmail]/Trash')
|
|
|
|
delete_from_trash(sanchayan, mails)
|
|
|
|
mails = sanchayan['[Gmail]/Spam']:select_all()
|
|
|
|
move_mailing_lists(sanchayan, mails)
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_mailing_lists(account, mails)
|
2019-10-19 19:21:22 +02:00
|
|
|
move_if_to_contains(account, mails, "gstreamer-devel@lists.freedesktop.org", "gstreamer")
|
2019-10-19 17:46:01 +02:00
|
|
|
move_if_from_contains(account, mails, "gstreamer-devel@lists.freedesktop.org", "gstreamer")
|
2019-10-19 19:21:22 +02:00
|
|
|
move_if_cc_contains(account, mails, "gstreamer-devel@lists.freedesktop.org", "gstreamer")
|
|
|
|
move_if_to_contains(account, mails, "gstreamer-embedded@lists.freedesktop.org", "gstreamer")
|
2019-10-19 17:46:01 +02:00
|
|
|
move_if_from_contains(account, mails, "gstreamer-embedded@lists.freedesktop.org", "gstreamer")
|
2019-10-19 19:21:22 +02:00
|
|
|
move_if_cc_contains(account, mails, "gstreamer-embedded@lists.freedesktop.org", "gstreamer")
|
|
|
|
move_if_to_contains(account, mails, "pulseaudio-discuss@lists.freedesktop.org", "pulseaudio")
|
2019-10-19 17:51:22 +02:00
|
|
|
move_if_from_contains(account, mails, "pulseaudio-discuss@lists.freedesktop.org", "pulseaudio")
|
2019-10-19 19:21:22 +02:00
|
|
|
move_if_cc_contains(account, mails, "pulseaudio-discuss@lists.freedesktop.org", "pulseaudio")
|
2016-03-07 17:31:28 +01:00
|
|
|
|
2020-11-12 07:11:15 +01:00
|
|
|
-- Bluetooth
|
|
|
|
move_if_to_contains(account, mails, "linux-bluetooth@vger.kernel.org", "bluez")
|
|
|
|
move_if_from_contains(account, mails, "linux-bluetooth@vger.kernel.org", "bluez")
|
|
|
|
move_if_cc_contains(account, mails, "linux-bluetooth@vger.kernel.org", "bluez")
|
|
|
|
|
2016-03-07 17:31:28 +01:00
|
|
|
-- Linux Kernel
|
|
|
|
move_if_to_contains(account, mails, "lists.infradead.org", "Linux Kernel")
|
|
|
|
move_if_from_contains(account, mails, "lists.infradead.org", "Linux Kernel")
|
|
|
|
move_if_cc_contains(account, mails, "lists.infradead.org", "Linux Kernel")
|
|
|
|
move_if_to_contains(account, mails, "vger.kernel.org", "Linux Kernel")
|
|
|
|
move_if_from_contains(account, mails, "vger.kernel.org", "Linux Kernel")
|
|
|
|
move_if_cc_contains(account, mails, "vger.kernel.org", "Linux Kernel")
|
|
|
|
|
|
|
|
-- U boot
|
|
|
|
move_if_to_contains(account, mails, "u-boot@lists.denx.de", "Uboot")
|
|
|
|
move_if_from_contains(account, mails, "u-boot@lists.denx.de", "Uboot")
|
|
|
|
move_if_cc_contains(account, mails, "u-boot@lists.denx.de", "Uboot")
|
|
|
|
|
|
|
|
-- Jobs
|
|
|
|
move_if_from_contains(account, mails, "monster.com","Jobs")
|
|
|
|
move_if_from_contains(account, mails, "naukri.com","Jobs")
|
|
|
|
|
2021-01-21 17:49:11 +01:00
|
|
|
move_if_to_contains(account, mails, "gitlab@gitlab.freedesktop.org", "FreedesktopGitlab")
|
|
|
|
move_if_from_contains(account, mails, "gitlab@gitlab.freedesktop.org", "FreedesktopGitlab")
|
2016-03-07 17:31:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function move_if_subject_contains(account, mails, subject, mailbox)
|
|
|
|
filtered = mails:contain_subject(subject)
|
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_if_to_contains(account, mails, to, mailbox)
|
|
|
|
filtered = mails:contain_to(to)
|
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_if_from_contains(account, mails, from, mailbox)
|
|
|
|
filtered = mails:contain_from(from)
|
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_if_cc_contains(account, mails, cc, mailbox)
|
|
|
|
filtered = mails:contain_cc(cc)
|
|
|
|
filtered:move_messages(account[mailbox]);
|
|
|
|
end
|
|
|
|
|
|
|
|
function move_to_gmail_trash(account, mails, mailbox)
|
|
|
|
filtered = mails:select_all()
|
|
|
|
filtered:move_messages(account[mailbox])
|
|
|
|
end
|
|
|
|
|
|
|
|
function delete_mail_from(account, mails, from)
|
|
|
|
filtered = mails:contain_from(from)
|
|
|
|
filtered:delete_messages()
|
|
|
|
end
|
|
|
|
|
|
|
|
function delete_mail_if_subject_contains(account, mails, subject)
|
|
|
|
filtered = mails:contain_subject(subject)
|
|
|
|
filtered:delete_messages()
|
|
|
|
end
|
|
|
|
|
|
|
|
function delete_from_trash(account, mails)
|
|
|
|
filtered = mails:select_all()
|
|
|
|
filtered:delete_messages()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Utility function to get IMAP password from file
|
|
|
|
function get_imap_password(file)
|
|
|
|
local home = os.getenv("HOME")
|
|
|
|
local file = home .. "/" .. file
|
|
|
|
local str = io.open(file):read()
|
|
|
|
return str;
|
|
|
|
end
|
|
|
|
|
2021-02-11 09:46:19 +01:00
|
|
|
function get_pwd_fastmail()
|
|
|
|
local cmd = "gpg2 --use-agent --quiet --batch --decrypt ~/.fastmail.gpg"
|
2016-03-07 17:31:28 +01:00
|
|
|
local fd = io.popen(cmd, 'r')
|
|
|
|
pass = fd:read("*a")
|
|
|
|
fd:close()
|
|
|
|
return pass;
|
|
|
|
end
|
|
|
|
|
2021-02-11 09:46:19 +01:00
|
|
|
function get_pwd_sanchayan()
|
|
|
|
local cmd = "gpg2 --use-agent --quiet --batch --decrypt ~/.sanchayan.gpg"
|
2020-01-06 06:25:00 +01:00
|
|
|
local fd = io.popen(cmd, 'r')
|
|
|
|
pass = fd:read("*a")
|
|
|
|
fd:close()
|
|
|
|
return pass;
|
|
|
|
end
|
|
|
|
|
2016-03-07 17:31:28 +01:00
|
|
|
main() -- Call the main function
|