extend.lua (imapfilter-2.7.5) | : | extend.lua (imapfilter-2.7.6) | ||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
-- extension. This is implemented by the enter_idle() method, which waits for | -- extension. This is implemented by the enter_idle() method, which waits for | |||
-- a notification by the server when new messages arrive in the monitored | -- a notification by the server when new messages arrive in the monitored | |||
-- mailbox. | -- mailbox. | |||
while true do | while true do | |||
myaccount.mymailbox:enter_idle() | myaccount.mymailbox:enter_idle() | |||
results = myaccount.mymailbox:is_unread() | results = myaccount.mymailbox:is_unread() | |||
results:move_messages(myaccount.myothermailbox) | results:move_messages(myaccount.myothermailbox) | |||
end | end | |||
-- The previous example can be further improved to consider whether new | ||||
-- messages arrived while filtering took place, and also somewhat work on | ||||
-- servers that have no IDLE support. | ||||
function custom_idle(mbox) | ||||
if #mbox:is_unseen() == 0 then | ||||
if not mbox:enter_idle() then | ||||
sleep(300) | ||||
end | ||||
end | ||||
end | ||||
while true do | ||||
custom_idle(myaccount.mymailbox) | ||||
results = myaccount.mymailbox:is_unread() | ||||
results:move_messages(myaccount.myothermailbox) | ||||
end | ||||
-- IMAPFilter can take advantage of all those filtering utilities that | -- IMAPFilter can take advantage of all those filtering utilities that | |||
-- are available and use a wide range of heuristic tests, text analysis, | -- are available and use a wide range of heuristic tests, text analysis, | |||
-- internet-based realtime blacklists, advanced learning algorithms, | -- internet-based realtime blacklists, advanced learning algorithms, | |||
-- etc. to classify mail. IMAPFilter can pipe a message to a program | -- etc. to classify mail. IMAPFilter can pipe a message to a program | |||
-- and act on the message based on the program's exit status. | -- and act on the message based on the program's exit status. | |||
-- | -- | |||
-- The auxiliary function pipe_to() is supplied for conveniency. For | -- The auxiliary function pipe_to() is supplied for conveniency. For | |||
-- example if there was a utility named "bayesian-spam-filter", which | -- example if there was a utility named "bayesian-spam-filter", which | |||
-- returned 1 when it considered the message "spam" and 0 otherwise: | -- returned 1 when it considered the message "spam" and 0 otherwise: | |||
skipping to change at line 97 | skipping to change at line 115 | |||
for _, mesg in ipairs(all) do | for _, mesg in ipairs(all) do | |||
mbox, uid = table.unpack(mesg) | mbox, uid = table.unpack(mesg) | |||
header = mbox[uid]:fetch_header() | header = mbox[uid]:fetch_header() | |||
body = mbox[uid]:fetch_body() | body = mbox[uid]:fetch_body() | |||
message = header:gsub('[\r\n]+$', '\r\n') .. | message = header:gsub('[\r\n]+$', '\r\n') .. | |||
'My-Header: My-Content\r\n' .. '\r\n' .. body | 'My-Header: My-Content\r\n' .. '\r\n' .. body | |||
myaccount.myothermaibox:append_message(message) | myaccount.myothermaibox:append_message(message) | |||
end | end | |||
-- Passwords could be extracted during execution time from an encrypted | -- Passwords could be extracted during execution time from an encrypted | |||
-- password vault. Here's an example using pass. | ||||
status, output = pipe_from('openssl bf -d -in ~/passwords.enc') | ||||
_, _, password1, password2 = string.find(output, '([%w%p]+)\n([%w%p]+)') | ||||
status, password = pipe_from('pass Email/imap1.mail.server') | ||||
account1 = IMAP { | account1 = IMAP { | |||
server = 'imap1.mail.server', | server = 'imap1.mail.server', | |||
username = 'user1', | username = 'user1', | |||
password = password1 | password = password | |||
} | ||||
account2 = IMAP { | ||||
server = 'imap2.mail.server', | ||||
username = 'user2', | ||||
password = password2 | ||||
} | ||||
user = 'xoauth@gmail.com' | ||||
clientid = '364545978226.apps.googleusercontent.com' | ||||
clientsecret = 'zNrNsBzOOnQy8_O-8LkofeTR' | ||||
refreshtoken = '1/q4SaB2JMQB9I-an6F1rxJE9OkOMtfjaz1bPm1tfDpQM' | ||||
status, output = pipe_from('oauth2.py --client_id=' .. clientid .. | ||||
' --client_secret=' .. clientsecret .. | ||||
' --refresh_token=' .. refreshtoken) | ||||
_, _, accesstoken = string.find(output, 'Access Token: ([%w%p]+)\n') | ||||
status, output = pipe_from('oauth2.py --generate_oauth2_string' .. | ||||
' --access_token=' .. accesstoken .. | ||||
' --user=' .. user) | ||||
_, _, oauth2string = string.find(output, 'OAuth2 argument:\n([%w%p]+)\n') | ||||
account3 = IMAP { | ||||
server = 'imap.gmail.com', | ||||
ssl = 'tls1.2', | ||||
username = user, | ||||
oauth2 = oauth2string | ||||
} | } | |||
End of changes. 4 change blocks. | ||||
33 lines changed or deleted | 21 lines changed or added |