mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
fix token was only updated on account-change, not new login or daily token rotation, also support now multiple tokens/instances registring tokens for same account
This commit is contained in:
parent
32043f7a41
commit
0f8a2668fb
@ -289,6 +289,25 @@ class Dovecot extends Mail\Imap implements Mail\Imap\PushIface
|
|||||||
const METADATA_NAME = '/private/vendor/vendor.dovecot/http-notify';
|
const METADATA_NAME = '/private/vendor/vendor.dovecot/http-notify';
|
||||||
const METADATA_MAILBOX = '';
|
const METADATA_MAILBOX = '';
|
||||||
const METADATA_PREFIX = 'user=';
|
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 . '@' . 'office.egroupware.org'; //Api\Header\Http::host();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable push notifictions for current connection and given account_id
|
* Enable push notifictions for current connection and given account_id
|
||||||
@ -303,11 +322,25 @@ class Dovecot extends Mail\Imap implements Mail\Imap\PushIface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
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, [
|
$this->setMetadata(self::METADATA_MAILBOX, [
|
||||||
self::METADATA_NAME => self::METADATA_PREFIX.$GLOBALS['egw_info']['user']['account_id'].'::'.$this->acc_id.';'.
|
self::METADATA_NAME => implode(self::METADATA_SEPARATOR, $metadata),
|
||||||
$this->getMailBoxUserName($GLOBALS['egw_info']['user']['account_lid']) . ';' .
|
|
||||||
((string)$account_id === '0' ? Tokens::instance() : Tokens::user($account_id)) . '@' .
|
|
||||||
Api\Header\Http::host(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
catch (Horde_Imap_Client_Exception $e) {
|
catch (Horde_Imap_Client_Exception $e) {
|
||||||
@ -318,8 +351,9 @@ class Dovecot extends Mail\Imap implements Mail\Imap\PushIface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if push is available / konfigured for given server
|
* Check if push is available / configured for given server
|
||||||
*
|
*
|
||||||
|
* @todo add a switch to enable push in the profile or
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function pushAvailable()
|
function pushAvailable()
|
||||||
|
@ -251,12 +251,6 @@ class mail_ui
|
|||||||
if ($oldicServerID != self::$icServerID)
|
if ($oldicServerID != self::$icServerID)
|
||||||
{
|
{
|
||||||
$this->mail_bo->openConnection(self::$icServerID);
|
$this->mail_bo->openConnection(self::$icServerID);
|
||||||
// enable push notifications, if supported (and konfigured) by the server
|
|
||||||
if ($this->mail_bo->icServer instanceof Api\Mail\Imap\PushIface &&
|
|
||||||
$this->mail_bo->icServer->pushAvailable())
|
|
||||||
{
|
|
||||||
$this->mail_bo->icServer->enablePush();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (true) $oldicServerID = self::$icServerID;
|
if (true) $oldicServerID = self::$icServerID;
|
||||||
if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true ))
|
if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true ))
|
||||||
@ -1556,6 +1550,12 @@ class mail_ui
|
|||||||
}
|
}
|
||||||
if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX';
|
if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX';
|
||||||
}
|
}
|
||||||
|
// enable push notifications, if supported (and konfigured) by the server
|
||||||
|
if ($mail_ui->mail_bo->icServer instanceof Api\Mail\Imap\PushIface &&
|
||||||
|
$mail_ui->mail_bo->icServer->pushAvailable())
|
||||||
|
{
|
||||||
|
$mail_ui->mail_bo->icServer->enablePush();
|
||||||
|
}
|
||||||
//error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort']));
|
//error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort']));
|
||||||
//Mail::$debugTimes=true;
|
//Mail::$debugTimes=true;
|
||||||
if (Mail::$debugTimes) $starttime = microtime(true);
|
if (Mail::$debugTimes) $starttime = microtime(true);
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
app.classes.mail = AppJS.extend(
|
app.classes.mail = AppJS.extend(
|
||||||
{
|
{
|
||||||
appname: 'mail',
|
appname: 'mail',
|
||||||
|
/**
|
||||||
|
* modified attribute in mail app to test new entries get added on top of list
|
||||||
|
*/
|
||||||
|
modification_field_name: 'date',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* et2 widget container
|
* et2 widget container
|
||||||
|
Loading…
Reference in New Issue
Block a user