]> git.madduck.net Git - etc/awesome.git/blob - widgets/maildir.lua.orig

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Delete asyncshell_BACKUP_32072.lua
[etc/awesome.git] / widgets / maildir.lua.orig
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013,      Luke Bonham                
6       * (c) 2010-2012, Peter Hofmann              
7                                                   
8 --]]
9
10 local newtimer        = require("lain.helpers").newtimer
11 <<<<<<< HEAD
12 =======
13 local read_pipe       = require("lain.helpers").read_pipe
14 >>>>>>> upstream/master
15
16 local wibox           = require("wibox")
17
18 local util            = require("lain.util")
19
20 local io              = { popen  = io.popen }
21 local os              = { getenv = os.getenv }
22 local pairs           = pairs
23 local string          = { len    = string.len,
24                           match  = string.match }
25 local table           = { sort   = table.sort }
26
27 local setmetatable    = setmetatable
28
29 -- Maildir check
30 -- lain.widgets.maildir
31 local maildir = {}
32
33 local function worker(args)
34     local args         = args or {}
35     local timeout      = args.timeout or 60
36     local mailpath     = args.mailpath or os.getenv("HOME") .. "/Mail"
37     local ignore_boxes = args.ignore_boxes or {}
38     local settings     = args.settings or function() end
39
40     maildir.widget = wibox.widget.textbox('')
41
42     function update()
43         -- Find pathes to mailboxes.
44         local p = io.popen("find " .. mailpath ..
45                            " -mindepth 1 -maxdepth 1 -type d" ..
46                            " -not -name .git")
47         local boxes = {}
48         repeat
49             line = p:read("*l")
50             if line ~= nil
51             then
52                 -- Find all files in the "new" subdirectory. For each
53                 -- file, print a single character (no newline). Don't
54                 -- match files that begin with a dot.
55                 -- Afterwards the length of this string is the number of
56                 -- new mails in that box.
57 <<<<<<< HEAD
58                 local np = io.popen("find " .. line ..
59                                     "/new -mindepth 1 -type f " ..
60                                     "-not -name '.*' -printf a")
61                 local mailstring = np:read("*a")
62 =======
63                 local mailstring = read_pipe("find " .. line ..
64                                     "/new -mindepth 1 -type f " ..
65                                     "-not -name '.*' -printf a")
66 >>>>>>> upstream/master
67
68                 -- Strip off leading mailpath.
69                 local box = string.match(line, mailpath .. "/*([^/]+)")
70                 local nummails = string.len(mailstring)
71                 if nummails > 0
72                 then
73                     boxes[box] = nummails
74                 end
75             end
76         until line == nil
77
78 <<<<<<< HEAD
79         table.sort(boxes)
80
81         newmail = "no mail"
82         --Count the total number of mails irrespective of where it was found
83 =======
84         p:close()
85         table.sort(boxes)
86
87         newmail = "no mail"
88         -- Count the total number of mails irrespective of where it was found
89 >>>>>>> upstream/master
90         total = 0
91
92         for box, number in pairs(boxes)
93         do
94             -- Add this box only if it's not to be ignored.
95             if not util.element_in_table(box, ignore_boxes)
96             then
97                 total = total + number
98                 if newmail == "no mail"
99                 then
100                     newmail = box .. "(" .. number .. ")"
101                 else
102                     newmail = newmail .. ", " ..
103                               box .. "(" .. number .. ")"
104                 end
105             end
106         end
107
108         widget = maildir.widget
109         settings()
110     end
111
112     newtimer(mailpath, timeout, update, true)
113     return maildir.widget
114 end
115
116 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })