Skip to content

Instantly share code, notes, and snippets.

@sthalik
Last active October 18, 2015 10:23
Show Gist options
  • Save sthalik/344d3a0db54c4c9051e4 to your computer and use it in GitHub Desktop.
Save sthalik/344d3a0db54c4c9051e4 to your computer and use it in GitHub Desktop.
account:subscribe_mailbox('INBOX')
account:subscribe_mailbox('Junk')
E_JUNK = 'imapfilter-junk'
E_SEEN = 'imapfilter-seen'
E_SZ = 1024 * 512
update = false
repeat
new_sz = account.INBOX:is_smaller(E_SZ)
new_ = new_sz - account.INBOX:has_flag(E_SEEN)
new_unspam = account.INBOX:has_flag(E_JUNK) * new_sz
new = new_ - new_unspam
for _, mesg in ipairs(new_unspam) do
mbox, uid = unpack(mesg)
m = mbox[uid]
print('UNMARK ' .. m:fetch_field('From'))
pipe_to('bogofilter -nSl', m:fetch_message())
end
new_unspam:remove_flags({ E_JUNK })
spam_sz = account.Junk:is_smaller(E_SZ)
new_spam = spam_sz - account.Junk:has_flag(E_JUNK)
for _, mesg in ipairs(new_spam) do
mbox, uid = unpack(mesg)
m = mbox[uid]
print('MARK ' .. m:fetch_field('From'))
pipe_to('bogofilter -Nsl', m:fetch_message())
end
new_spam:add_flags({ E_JUNK })
for _, mesg in ipairs(new) do
mbox, uid = unpack(mesg)
m = mbox[uid]
print('NEW ' .. m:fetch_field('From'))
text = m:fetch_message()
if type(text) == 'string' then
flag = pipe_to('bogofilter -ul', m:fetch_message())
if flag == 0 then
s = Set {mesg}
s:mark_seen()
s:move_messages(account.Junk)
s:add_flags({ E_JUNK })
s:mark_seen()
end
end
end
new:add_flags({ E_SEEN })
update = account.INBOX:enter_idle()
until not update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment