move configuration of imap servers supporting push to mail site config and stadard imap server

This commit is contained in:
Ralf Becker 2020-07-23 14:17:16 +02:00
parent a2e5dc6981
commit cf06054fd7
5 changed files with 116 additions and 83 deletions

View File

@ -15,6 +15,7 @@ namespace EGroupware\Api\Mail;
use EGroupware\Api;
use EGroupware\SwoolePush\Tokens;
use Horde_Imap_Client;
use Horde_Imap_Client_Socket;
use Horde_Imap_Client_Cache_Backend_Cache;
@ -56,7 +57,7 @@ use Horde_Imap_Client_Mailbox_List;
* @property-read array $params parameters passed to constructor (all above as array)
* @property-read boolean|int|string $isAdminConnection admin connection if true or account_id or imap username
*/
class Imap extends Horde_Imap_Client_Socket implements Imap\Iface
class Imap extends Horde_Imap_Client_Socket implements Imap\PushIface
{
/**
* Default parameters for Horde_Imap_Client constructor
@ -1393,12 +1394,104 @@ class Imap extends Horde_Imap_Client_Socket implements Imap\Iface
return array();
}
/**
* @var array IMAP servers supporting push
*/
protected static $hosts_with_push = [];
/**
* Init static variables
*/
public static function init_static()
{
self::$supports_keywords =& Api\Cache::getSession (__CLASS__, 'supports_keywords');
// hosts from header.inc.php
self::$hosts_with_push = $GLOBALS['egw_info']['server']['imap_hosts_with_push'] ?? [];
// plus hosts from mail site config
$config = Api\Config::read('mail');
foreach(!empty($config['imap_hosts_with_push']) ? preg_split('/[, ]+/', $config['imap_hosts_with_push']) : [] as $host)
{
self::$hosts_with_push[] = $host;
}
}
/**
* Metadata name to enable push notifications in Dovecot
*/
const METADATA_NAME = '/private/vendor/vendor.dovecot/http-notify';
const METADATA_MAILBOX = '';
const METADATA_PREFIX = 'user=';
const METADATA_SEPARATOR = ';;';
/**
* Generate token / user-information for push to be stored by Dovecot
*
* The user informations has the form "$account_id::$acc_id;$token@$host"
*
* @param null $account_id
* @param string $token =null default push token of instance ($account_id=='0') or user
* @return string
* @throws Api\Exception\AssertionFailed
*/
protected function pushToken($account_id=null, $token=null)
{
if (!isset($token)) $token = ((string)$account_id === '0' ? Tokens::instance() : Tokens::user($account_id));
return self::METADATA_PREFIX.$GLOBALS['egw_info']['user']['account_id'].'::'.$this->acc_id.';'.
$token . '@' . Api\Header\Http::host();
}
/**
* Enable push notifictions for current connection and given account_id
*
* @param int $account_id =null 0=everyone on the instance
* @return bool true on success, false on failure
*/
function enablePush($account_id=null)
{
if (!class_exists(Tokens::class))
{
return false;
}
try {
$metadata = explode(self::METADATA_SEPARATOR, $this->getMetadata(self::METADATA_MAILBOX, [self::METADATA_NAME])) ?: [];
$my_token = $this->pushToken($account_id);
$my_token_preg = '/^'.$this->pushToken($account_id, '[^@]+').'$/';
foreach($metadata as $key => $token)
{
// token already registered --> we're done
if ($token === $my_token) return true;
// check old/expired token registered --> remove it
if (preg_match($my_token_preg, $token))
{
unset($metadata[$key]);
break;
}
}
// add my token and send it to Dovecot
$metadata[] = $my_token;
$this->setMetadata(self::METADATA_MAILBOX, [
self::METADATA_NAME => implode(self::METADATA_SEPARATOR, $metadata),
]);
}
catch (Horde_Imap_Client_Exception $e) {
_egw_log_exception($e);
return false;
}
return true;
}
/**
* Check if push is available / configured for given server
*
* @return bool
*/
function pushAvailable()
{
return self::$hosts_with_push && (in_array($this->acc_imap_host, self::$hosts_with_push) ||
in_array($this->acc_imap_host.':'.$this->acc_imap_port, self::$hosts_with_push));
}
}
Imap::init_static();

View File

@ -14,7 +14,6 @@ namespace EGroupware\Api\Mail\Imap;
use EGroupware\Api;
use EGroupware\Api\Mail;
use EGroupware\SwoolePush\Tokens;
/**
* Manages connection to Dovecot IMAP server
@ -25,7 +24,7 @@ use EGroupware\SwoolePush\Tokens;
* --> require by webserver writable user_home to be configured, otherwise deleting get ignored like with defaultimap
* - quota can be read, but not set
*/
class Dovecot extends Mail\Imap implements Mail\Imap\PushIface
class Dovecot extends Mail\Imap
{
/**
* Label shown in EMailAdmin
@ -283,82 +282,4 @@ class Dovecot extends Mail\Imap implements Mail\Imap\PushIface
return true;
}
/**
* Metadata name to enable push notifications
*/
const METADATA_NAME = '/private/vendor/vendor.dovecot/http-notify';
const METADATA_MAILBOX = '';
const METADATA_PREFIX = 'user=';
const METADATA_SEPARATOR = ';;';
/**
* Generate token / user-information for push to be stored by Dovecot
*
* The user informations has the form "$account_id::$acc_id;$token@$host"
*
* @param null $account_id
* @param string $token =null default push token of instance ($account_id=='0') or user
* @return string
* @throws Api\Exception\AssertionFailed
*/
protected function pushToken($account_id=null, $token=null)
{
if (!isset($token)) $token = ((string)$account_id === '0' ? Tokens::instance() : Tokens::user($account_id));
return self::METADATA_PREFIX.$GLOBALS['egw_info']['user']['account_id'].'::'.$this->acc_id.';'.
$token . '@' . Api\Header\Http::host();
}
/**
* Enable push notifictions for current connection and given account_id
*
* @param int $account_id =null 0=everyone on the instance
* @return bool true on success, false on failure
*/
function enablePush($account_id=null)
{
if (!class_exists(Tokens::class))
{
return false;
}
try {
$metadata = explode(self::METADATA_SEPARATOR, $this->getMetadata(self::METADATA_MAILBOX, [self::METADATA_NAME])) ?: [];
$my_token = $this->pushToken($account_id);
$my_token_preg = '/^'.$this->pushToken($account_id, '[^@]+').'$/';
foreach($metadata as $key => $token)
{
// token already registered --> we're done
if ($token === $my_token) return true;
// check old/expired token registered --> remove it
if (preg_match($my_token_preg, $token))
{
unset($metadata[$key]);
break;
}
}
// add my token and send it to Dovecot
$metadata[] = $my_token;
$this->setMetadata(self::METADATA_MAILBOX, [
self::METADATA_NAME => implode(self::METADATA_SEPARATOR, $metadata),
]);
}
catch (Horde_Imap_Client_Exception $e) {
_egw_log_exception($e);
return false;
}
return true;
}
/**
* Check if push is available / configured for given server
*
* @todo add a switch to enable push in the profile or
* @return bool
*/
function pushAvailable()
{
return in_array($this->acc_imap_host, ['imap.egroupware.org', 'mail.egroupware.org']) ||
$this->acc_imap_host === 'mail' && $this->acc_imap_port == 10143;
}
}

View File

@ -360,8 +360,10 @@ move to trash mail de in den Papierkorb verschieben
moved %1 message(s) from %2 to %3 mail de %1 Nachrichten wurden von %2 nach %3 verschoben
moving folders from one mailaccount to another is not supported mail de Verschieben von Ordnern von einem Mailkonto zu einem anderen wird nicht unterstützt
name of account mail de Konten-Bezeichnung
name of imap servers (space separated host or host:port) mail de Name der IMAP Server (Leerzeichen getrennt Host oder Host:Port)
never display html emails mail de niemals anzeigen
never show mail de Nie anzeigen
new mail from %1 mail de Neue Mail von %1
new mail notification mail de Benachrichtigung über neue E-Mails in:
new message type mail de Neue E-Mails verfassen als
new subject mail de Neuer Betreff
@ -424,6 +426,7 @@ printing mail de Drucke
printview mail de Druckansicht
processing of file %1 failed. failed to meet basic restrictions. mail de Das Verarbeiten der Datei %1 ist fehlgeschlagen. Grundlegende Voraussetzungen wurden nicht erfüllt.
provide a default vacation text, (used on new vacation messages when there was no message set up previously) admin de Vorschlagstext für eine Abwesenheitsnotiz (wenn noch kein eigener Benachrichtigungstext vorhanden ist)
push notifications mail de Push Benachrichtigungen
quicksearch mail de Schnellsuche
quicksearch (with cc) mail de Schnellsuche (+ Kopie)
quota limit warning in megabyte (recommended value is 30 mb). mail de Quota-Limit-Warnung in MegaByte (empfohlener Wert ist 30 MB).
@ -598,13 +601,14 @@ the %1 's acl, including its subfolders, removed from the %2 mail de Die Zugriff
the entered passphrase is not correct! please try again. mail de Das eingegebene Passwort ist nicht korrekt. Bitte versuchen Sie es erneut.
the folder %1 's acls saved mail de Die Zugriffskontrollrechte des Ordners %1 wurden gespeichert
the folder <b>%1</b> will be used, if there is nothing set here, and no valid predefine given. mail de Der Ordner <b>%1</b> wird verwendet, wenn hier nichts gesetzt ist und kein gültiger Vorgabewert eingetragen ist.
the imap server need to meet certain requirements and be configured for it: mail de Der IMAP Server muss verschiedene Vorraussetzungen erfüllen UND dafür konfiguriert sein:
the message sender has requested a response to indicate that you have read this message. would you like to send a receipt? mail de Der Absender hat eine Empfangsbestätigung angefordert, um sicherzustellen, dass Sie diese E-Mail gelesen haben. Möchten Sie eine Empfangsbestätigung senden?
the mimeparser can not parse this message. mail de Der MIME Parser versteht diese Nachricht nicht.
the rule with priority %1 successfully saved! mail de Die Regel mit Priorität %1 wurde erfolgreich gespeichert!
then mail de dann
this mail contains external images served via insecure http protocol. be aware showing or allowing them can compromise your security! mail de Diese Mail enthält externe Bilder die über das unsichere HTTP protocol ausgeliefert werden. Bitte seinen Sie sich bewußt, dass Anzeigen oder Erlauben Ihre Sicherheit beeinträchtigen kann!
there is no imap server configured. mail de Es ist kein IMAP-Server Konfiguriert
there is no space left to store sieve script, please check sieve_maxscriptsize option on your mailserver's config. mail de Es ist kein Platz mehr vorhanden, um das Sieve Skript zu speichern, bitte Sie Ihren Administrator die Option sieve_maxscriptsize in der Konfiguration Ihres Mailservers zu prüfen.
this mail contains external images served via insecure http protocol. be aware showing or allowing them can compromise your security! mail de Diese Mail enthält externe Bilder die über das unsichere HTTP protocol ausgeliefert werden. Bitte seinen Sie sich bewußt, dass Anzeigen oder Erlauben Ihre Sicherheit beeinträchtigen kann!
this message is smime encrypted and password protected. mail de Diese Nachricht ist S/MIME-Verschlüsselt und mit Passwort geschützt.
timeout on connections to your imap server mail de Stellen Sie hier das Verbindungstimeout für IMAP Verbindungen ein.
to do mail de zu erledigen

View File

@ -360,8 +360,10 @@ move to trash mail en move to trash
moved %1 message(s) from %2 to %3 mail en moved %1 message(s) from %2 to %3
moving folders from one mailaccount to another is not supported mail en Moving Folders from one mail account to another is not supported
name of account mail en Name of account
name of imap servers (space separated host or host:port) mail en Name of IMAP servers (space separated host or host:port)
never display html emails mail en never display HTML emails
never show mail en never show
new mail from %1 mail en New mail from %1
new mail notification mail en New mail notification
new message type mail en New message type
new subject mail en New subject
@ -424,6 +426,7 @@ printing mail en printing
printview mail en printview
processing of file %1 failed. failed to meet basic restrictions. mail en Processing of file %1 failed. Failed to meet basic restrictions.
provide a default vacation text, (used on new vacation messages when there was no message set up previously) admin en provide a default vacation text, (used on new vacation messages when there was no message set up previously)
push notifications mail en Push notifications
quicksearch mail en quicksearch
quicksearch (with cc) mail en quicksearch (incl.CC)
quota limit warning in megabyte (recommended value is 30 mb). mail en Quota limit warning in MegaByte (recommended value is 30 MB).
@ -598,13 +601,14 @@ the %1 's acl, including its subfolders, removed from the %2 mail en The %1 's a
the entered passphrase is not correct! please try again. mail en The entered passphrase is not correct! Please try again.
the folder %1 's acls saved mail en The Folder %1 's ACLs saved
the folder <b>%1</b> will be used, if there is nothing set here, and no valid predefine given. mail en The folder <b>%1</b> will be used, if there is nothing set here, and no valid predefine given.
the imap server need to meet certain requirements and be configured for it: mail en The IMAP server need to meet certain requirements AND be configured for it:
the message sender has requested a response to indicate that you have read this message. would you like to send a receipt? mail en The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?
the mimeparser can not parse this message. mail en The mimeparser can not parse this message.
the rule with priority %1 successfully saved! mail en The rule with priority %1 successfully saved!
then mail en THEN
this mail contains external images served via insecure http protocol. be aware showing or allowing them can compromise your security! mail en This mail contains external images served via insecure HTTP protocol. Be aware showing or allowing them can compromise your security!
there is no imap server configured. mail en There is no IMAP Server configured.
there is no space left to store sieve script, please check sieve_maxscriptsize option on your mailserver's config. mail en There is no space left to store sieve script, please check sieve_maxscriptsize option on your mailserver's config.
this mail contains external images served via insecure http protocol. be aware showing or allowing them can compromise your security! mail en This mail contains external images served via insecure HTTP protocol. Be aware showing or allowing them can compromise your security!
this message is smime encrypted and password protected. mail en This message is S/MIME encrypted and password protected.
timeout on connections to your imap server mail en Timeout on connections to your IMAP Server
to do mail en to do

View File

@ -51,6 +51,17 @@
</vbox>
<select-account id="newsettings[deny_aclmanagement]" account_type="groups" multiple="true" tags="true" width="100%"/>
</row>
<row height="25px" valign="bottom">
<description value="Push notifications" span="all" class="subHeader"/>
</row>
<row>
<url label="The IMAP server need to meet certain requirements AND be configured for it:" span="all"
value="https://github.com/EGroupware/egroupware/wiki/IMAP-Push-Notifications" readonly="true"/>
</row>
<row>
<description value="Name of IMAP servers (space separated host or host:port)" for="newsettings[imap_hosts_with_push]"/>
<textbox id="newsettings[imap_hosts_with_push]" class="et2_fullWidth"/>
</row>
<row>
<description value="Sieve" span="all" class="subHeader"/>
</row>