mail_check.lua (1221B)
1 #!/bin/lua 2 3 local mbsync = require 'tms.mbsync' 4 local acc = mbsync.accounts() 5 6 local function notify(title, body) 7 local h = io.popen(string.format( 8 'dunstify --action=\'open,Open\' --appname=\'neomutt\' \'%s\' \'%s\' &', 9 title, body)) 10 for a in h:lines() do 11 if a == 'open' then 12 os.execute('alacritty -e neomutt &') 13 end 14 end 15 end 16 17 local function on_change() os.execute('bar-update mail') end 18 19 local function check(dirs) 20 local cmd = string.format('inotifywait -m -r %s %s -q', 21 table.concat({'-e create', '-e move', '-e delete'}, ' '), 22 table.concat(dirs, ' ')) 23 local handler = io.popen(cmd) 24 for output in handler:lines() do 25 local _, _, _ = output:match('(.*) (.*) (.*)') 26 for _, _ in pairs(acc) do 27 -- if path:find(string.format("INBOX/new", a)) and action == "MOVED_TO" then 28 -- print('moved to now') 29 -- notify(string.format("MAIL:%s", a), "subject on the way") 30 -- end 31 32 print('change') 33 on_change() 34 end 35 36 end 37 end 38 39 local dirs = {} 40 for _, a in pairs(acc) do 41 table.insert(dirs, string.format('%s/.mail/%s/INBOX', os.getenv('HOME'), a)) 42 end 43 check(dirs)