Push: Describe deployment on Cyrus IMAP

dev/push
Aleksander Machniak 5 years ago
parent 77b6e2606a
commit 05db0f5d87

@ -40,6 +40,22 @@ INSTALLATION
to Roundcube location.
INSTALLATION - CYRUS IMAP
-------------------------
0. Make sure the server has PHP with Curl extension installed.
1. Make sure notify service is enabled in cyrus.conf.
2. Update imapd.conf with:
```
notify_external: /usr/share/roundcubemail/plugins/push/helpers/notify-cyrus.sh
event_notifier: external
event_groups: message mailbox flags subscription
event_extra_params: diskUsed messages vnd.cmu.unseenMessages flagNames
```
3. Configure $URL and $TOKEN in notify-cyrus.sh script.
4. Restart cyrus-imapd.
NOTES
-----

@ -0,0 +1,52 @@
#!/usr/bin/env php
<?php
/**
* Push plugin helper for Cyrus IMAP
*
* @author Aleksander Machniak <alec@alec.pl>
*
* Copyright (C) 2010-2019 The Roundcube Dev Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
///////////////////// CONFIGURATION /////////////////////
$URL = "http://127.0.0.1:9501";
$TOKEN = "xyz";
/////////////////////////////////////////////////////////
if (php_sapi_name() != 'cli') {
die('Not on the "shell" (php-cli).');
}
$input = file_get_contents('php://stdin');
// Debug
file_put_contents('/tmp/notify.log', "$input\n", FILE_APPEND);
$curl = curl_init($URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $input);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($input),
'X-Token: ' . $TOKEN
));
curl_exec($curl);
curl_close($curl);

@ -39,7 +39,7 @@ class push_parser_notify
}
// Get event name (remove non-standard prefixes)
$event = str_replace('vnd.cmu.', '', $data['event']);
$event = str_replace('vnd.cmu.', '', $data['event']);
$data['event'] = $event;
// Parse data
@ -61,9 +61,10 @@ class push_parser_notify
$uri = $this->parseURI($data['uri']);
$result = array(
'event' => $data['event'],
'service' => $data['service'],
'uidset' => $data['uidset'],
'exists' => $data['messages'],
'exists' => isset($data['messages']) ? intval($data['messages']) : null,
'folder_user' => $uri['user'] ?: $data['user'],
'folder_name' => $uri['folder'],
);

@ -67,7 +67,7 @@ class push_service extends rcube
$port = $this->config->get('push_service_post') ?: 9501;
$cache_size = $this->config->get('push_cache_size') ?: 1024;
$this->debug = $this->config->get('push_debug', true);
$this->debug = $this->config->get('push_debug', false);
$this->token = $this->config->get('push_token');
$this->clients = new push_cache($cache_size);
$this->parser = new push_parser_notify;
@ -193,6 +193,7 @@ class push_service extends rcube
if (!empty($event) && $event['folder_user']) {
$user = $this->clients->get($event['folder_user']);
if ($user) {
$this->broadcast($user, $event);
}
@ -207,6 +208,9 @@ class push_service extends rcube
*/
protected function broadcast($client, $event)
{
// remove null items
$event = array_filter($event, function($v) { return !is_null($v); });
foreach ((array) $client['sockets'] as $fd) {
if ($json = json_encode($event)) {
$this->log_debug("[$fd] Sending message to " . $client['username'], $json);

Loading…
Cancel
Save