From 425a709ab4a062aa38581a86ef4f8908707863a5 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 6 Aug 2020 20:33:48 +0200 Subject: [PATCH] Updated IMAP Push Notifications (markdown) --- IMAP-Push-Notifications.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/IMAP-Push-Notifications.md b/IMAP-Push-Notifications.md index 43c75ae..1446dc1 100644 --- a/IMAP-Push-Notifications.md +++ b/IMAP-Push-Notifications.md @@ -52,11 +52,11 @@ Then restart Dovecot: ```systemctl restart dovecot``` Install ```dovecot-lua``` plus required Lua modules: ``` -apt install dovecot-lua lua-socket luarocks -luarocks install json-lua -ln -s ln -s /usr/share/lua/5.1/JSON.lua /usr/share/lua/5.2/ +apt install dovecot-lua lua-socket lua-json 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 ``` # 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= user_from_metadata -- 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 ltn12 = require "ltn12" --- luarocks install json-lua -local json = require "JSON" +local json = require "json" function table_get(t, k, d) return t[k] or d @@ -232,8 +233,8 @@ function dovecot_lua_notify_event_flags_set(ctx, event) end if (event.name == "FlagsClear") then - msg["flags-old"] = event.flags_old - msg["keywords-old"] = event.keywords_old + msg.flags_old = event.flags_old + msg.keywords_old = event.keywords_old end table.insert(ctx.messages, msg) end @@ -247,7 +248,7 @@ function arrayEqual(t1, t2) then return true end - return json:encode(t1) == json:encode(t2) + return json.encode(t1) == json.encode(t2) end 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 local e = dovecot.event(ctx.event) e:set_name("lua_notify_mail_finished") - reqbody = json:encode(msg) + reqbody = json.encode(msg) e:log_debug(ctx.ep .. " - sending " .. reqbody) res, code = http.request({ method = "PUT",