mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-16 11:38:02 +02:00
Updated IMAP Push Notifications (markdown)
@ -52,11 +52,11 @@ Then restart Dovecot: ```systemctl restart dovecot```
|
|||||||
|
|
||||||
Install ```dovecot-lua``` plus required Lua modules:
|
Install ```dovecot-lua``` plus required Lua modules:
|
||||||
```
|
```
|
||||||
apt install dovecot-lua lua-socket luarocks
|
apt install dovecot-lua lua-socket lua-json
|
||||||
luarocks install json-lua
|
|
||||||
ln -s ln -s /usr/share/lua/5.1/JSON.lua /usr/share/lua/5.2/
|
|
||||||
curl https://raw.githubusercontent.com/EGroupware/swoolepush/master/doc/dovecot-push.lua > /etc/dovecot/dovecot-push.lua
|
curl https://raw.githubusercontent.com/EGroupware/swoolepush/master/doc/dovecot-push.lua > /etc/dovecot/dovecot-push.lua
|
||||||
```
|
```
|
||||||
|
(For CentOS/RHEL use ```yum``` instead of ```apt``` and you need to install ```epel-release``` package/repo first.)
|
||||||
|
|
||||||
Create the following file /etc/dovecot/conf.d/99-egroupware-push.conf
|
Create the following file /etc/dovecot/conf.d/99-egroupware-push.conf
|
||||||
```
|
```
|
||||||
# Store METADATA information in a file dovecot-metadata in user's home
|
# Store METADATA information in a file dovecot-metadata in user's home
|
||||||
@ -87,13 +87,14 @@ The above commands installed the following Lua script to /etc/dovecot/dovecot-pu
|
|||||||
--
|
--
|
||||||
-- server is sent a PUT message with JSON body like push_notification_driver = ox:url=<push_lua_url> user_from_metadata
|
-- server is sent a PUT message with JSON body like push_notification_driver = ox:url=<push_lua_url> user_from_metadata
|
||||||
-- plus additionally the events MessageAppend, MessageExpunge, FlagsSet and FlagsClear
|
-- plus additionally the events MessageAppend, MessageExpunge, FlagsSet and FlagsClear
|
||||||
-- MessageTrash and MessageRead are ignored, so are empty FlagSet/Clear or FlagSet NonJunk (TB)
|
-- MessageTrash and MessageRead are ignored, so are empty or NonJunk FlagSet/Clear from TB
|
||||||
|
--
|
||||||
|
-- Needs lua-socket and lua-json packages plus dovecot-lua!
|
||||||
--
|
--
|
||||||
|
|
||||||
local http = require "socket.http"
|
local http = require "socket.http"
|
||||||
local ltn12 = require "ltn12"
|
local ltn12 = require "ltn12"
|
||||||
-- luarocks install json-lua
|
local json = require "json"
|
||||||
local json = require "JSON"
|
|
||||||
|
|
||||||
function table_get(t, k, d)
|
function table_get(t, k, d)
|
||||||
return t[k] or d
|
return t[k] or d
|
||||||
@ -232,8 +233,8 @@ function dovecot_lua_notify_event_flags_set(ctx, event)
|
|||||||
end
|
end
|
||||||
if (event.name == "FlagsClear")
|
if (event.name == "FlagsClear")
|
||||||
then
|
then
|
||||||
msg["flags-old"] = event.flags_old
|
msg.flags_old = event.flags_old
|
||||||
msg["keywords-old"] = event.keywords_old
|
msg.keywords_old = event.keywords_old
|
||||||
end
|
end
|
||||||
table.insert(ctx.messages, msg)
|
table.insert(ctx.messages, msg)
|
||||||
end
|
end
|
||||||
@ -247,7 +248,7 @@ function arrayEqual(t1, t2)
|
|||||||
then
|
then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return json:encode(t1) == json:encode(t2)
|
return json.encode(t1) == json.encode(t2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function dovecot_lua_notify_event_flags_clear(ctx, event)
|
function dovecot_lua_notify_event_flags_clear(ctx, event)
|
||||||
@ -259,7 +260,7 @@ function dovecot_lua_notify_end_txn(ctx)
|
|||||||
for i,msg in ipairs(ctx.messages) do
|
for i,msg in ipairs(ctx.messages) do
|
||||||
local e = dovecot.event(ctx.event)
|
local e = dovecot.event(ctx.event)
|
||||||
e:set_name("lua_notify_mail_finished")
|
e:set_name("lua_notify_mail_finished")
|
||||||
reqbody = json:encode(msg)
|
reqbody = json.encode(msg)
|
||||||
e:log_debug(ctx.ep .. " - sending " .. reqbody)
|
e:log_debug(ctx.ep .. " - sending " .. reqbody)
|
||||||
res, code = http.request({
|
res, code = http.request({
|
||||||
method = "PUT",
|
method = "PUT",
|
||||||
|
Reference in New Issue
Block a user