scripts

Utilitity scripts
git clone git://gtms.dev:scripts
Log | Files | Refs

mail_count.lua (616B)


      1 #!/bin/lua
      2 
      3 -- List accounts inside mbsyncrc
      4 local accounts = function()
      5   local acc = {}
      6   for a in io.popen('cat ~/.mbsyncrc | sed -n \'s/^Group //p\''):lines() do
      7     table.insert(acc, a)
      8   end
      9   return acc
     10 end
     11 
     12 local acc = accounts()
     13 
     14 local function count(a)
     15   local h = io.popen(string.format('fd . %s/.mail/%s/INBOX/new | wc -l', os.getenv('HOME'), a))
     16   return tonumber(h:read())
     17 end
     18 
     19 local format = {}
     20 for _, a in pairs(acc) do
     21   local c = count(a)
     22   if c > 0 then
     23     table.insert(format, string.format('%s:%s', a, c))
     24   end
     25 end
     26 
     27 if #format == 0 then
     28   print('')
     29 else
     30   print(table.concat(format, ' '))
     31 end