]> git.madduck.net Git - etc/awesome.git/blob - widgets/imap.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:

1121f1a67399ca676a9bfa3ceb823b307d87321e
[etc/awesome.git] / widgets / imap.lua.orig
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6                                                   
7 --]]
8
9 local helpers      = require("lain.helpers")
10 local async        = require("lain.asyncshell")
11
12 local naughty      = require("naughty")
13 local wibox        = require("wibox")
14
15 <<<<<<< HEAD
16 =======
17 local mouse        = mouse
18 >>>>>>> upstream/master
19 local string       = { format = string.format,
20                        gsub   = string.gsub }
21 local tonumber     = tonumber
22
23 local setmetatable = setmetatable
24
25 -- Mail IMAP check
26 -- lain.widgets.imap
27
28 local function worker(args)
29 <<<<<<< HEAD
30     local imap     = {}
31     local args     = args or {}
32
33     local server   = args.server
34     local mail     = args.mail
35     local password = args.password
36
37     local port     = args.port or 993
38     local timeout  = args.timeout or 60
39     local is_plain = args.is_plain or false
40     local settings = args.settings or function() end
41 =======
42     local imap        = {}
43     local args        = args or {}
44
45     local server      = args.server
46     local mail        = args.mail
47     local password    = args.password
48
49     local port        = args.port or 993
50     local timeout     = args.timeout or 60
51     local is_plain    = args.is_plain or false
52     local followmouse = args.followmouse or false
53     local settings    = args.settings or function() end
54 >>>>>>> upstream/master
55
56     local head_command  = "curl --connect-timeout 3 -fsm 3"
57     local request = "-X 'SEARCH (UNSEEN)'"
58
59     helpers.set_map(mail, 0)
60
61     if not is_plain
62     then
63 <<<<<<< HEAD
64         local f = io.popen(password)
65         password = f:read("*a"):gsub("\n", "")
66         f:close()
67 =======
68         password = helpers.read_pipe(password):gsub("\n", "")
69 >>>>>>> upstream/master
70     end
71
72     imap.widget = wibox.widget.textbox('')
73
74     function update()
75         mail_notification_preset = {
76             icon     = helpers.icons_dir .. "mail.png",
77             position = "top_left"
78         }
79
80 <<<<<<< HEAD
81 =======
82         if followmouse then
83             mail_notification_preset.screen = mouse.screen
84         end
85
86 >>>>>>> upstream/master
87         curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
88                head_command, server, port, mail, password, request)
89
90         async.request(curl, function(f)
91 <<<<<<< HEAD
92             ws = f:read("*a")
93             f:close()
94
95             _, mailcount = string.gsub(ws, "%d+", "")
96 =======
97             _, mailcount = string.gsub(f, "%d+", "")
98 >>>>>>> upstream/master
99             _ = nil
100
101             widget = imap.widget
102             settings()
103
104             if mailcount >= 1 and mailcount > helpers.get_map(mail)
105             then
106                 if mailcount == 1 then
107                     nt = mail .. " has one new message"
108                 else
109                     nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
110                 end
111                 naughty.notify({
112                     preset = mail_notification_preset,
113 <<<<<<< HEAD
114                     text = nt,
115 =======
116                     text = nt
117 >>>>>>> upstream/master
118                 })
119             end
120
121             helpers.set_map(mail, mailcount)
122         end)
123
124     end
125
126     helpers.newtimer(mail, timeout, update, true)
127
128     return setmetatable(imap, { __index = imap.widget })
129 end
130
131 return setmetatable({}, { __call = function(_, ...) return worker(...) end })