Initial upload to Gitea

This commit is contained in:
antonn committed 2026-11-30 16:32:37 +00:00
1 parent 78193254ad
commit 8478998cae
1485 files changed
+461025 -42348

No files matched your search

@@ -0,0 +1,41 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* AddressBookNotifier.
*
* Generates notifications update AddressBook contents.
*/
class AddressBookNotifier extends Notifier {
/**
* @return Number the event which this module handles
*/
#[Override]
public function getEvents() {
return OBJECT_SAVE;
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case OBJECT_SAVE:
$this->addNotificationActionData("addressbook", true);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
break;
}
}
}
@@ -0,0 +1,106 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/class.listnotifier.php';
/**
* AppointmentListNotifier.
*
* Generates notifications for changes to the
* Appointment Folder contents.
*/
class AppointmentListNotifier extends ListNotifier {
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
#[Override]
protected function getPropertiesList() {
return $GLOBALS["properties"]->getAppointmentListProperties();
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case TABLE_SAVE:
$data = [];
if (isset($props[PR_STORE_ENTRYID])) {
$store = $GLOBALS["mapisession"]->openMessageStore($props[PR_STORE_ENTRYID]);
$properties = $this->getPropertiesList();
$message = null;
if (isset($props[PR_ENTRYID])) {
$message = $GLOBALS["operations"]->openMessage($store, $props[PR_ENTRYID]);
$messageProps = mapi_getprops($message, $properties);
}
else {
$messageProps = [];
}
if (!isset($props[PR_ENTRYID]) || (isset($messageProps[$properties['recurring']]) && $messageProps[$properties['recurring']])) {
// An object was created inside this folder for which we don't know the entryid
// this can happen when we copy or move a message. Just tell the javascript that
// this folder has a new object.
// Alternatively the recurrence could have been changed, this means that we should send a notification to the client
// to inform the possibility that a different number of occurrences might be inside his view now.
$folder = mapi_msgstore_openentry($store, $props[PR_PARENT_ENTRYID]);
$folderProps = mapi_getprops($folder, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID, PR_CONTENT_COUNT, PR_CONTENT_UNREAD, PR_DISPLAY_NAME]);
$data = [
"item" => [
[
"content_count" => $folderProps[PR_CONTENT_COUNT],
"content_unread" => $folderProps[PR_CONTENT_UNREAD],
// Add store_entryid,entryid of folder and display_name of folder
// to JSON data in order to refresh the list.
"store_entryid" => bin2hex((string) $folderProps[PR_STORE_ENTRYID]),
"parent_entryid" => bin2hex((string) $folderProps[PR_PARENT_ENTRYID]),
"entryid" => bin2hex((string) $folderProps[PR_ENTRYID]),
"display_name" => $folderProps[PR_DISPLAY_NAME],
],
],
];
$this->addNotificationActionData("newobject", $data);
}
else {
$data = $GLOBALS["operations"]->getMessageProps($store, $message, $properties);
/*
* We dose't need these properties in AppointmentListNotifier,
* because if we send this properties in AppointmentListNotifier
* webapp use this properties and try to re-draw appointment in calendar
* which look annoying when user drag and drop same appointment frequently
* in calendar (related to WA-8897).
*/
unset($data['props']['startdate'], $data['props']['duedate'], $data['props']['commonstart'], $data['props']['commonend']);
$this->addNotificationActionData("update", ["item" => [$data]]);
}
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
}
break;
case TABLE_DELETE:
parent::update($event, $entryid, $props);
break;
}
}
}
@@ -0,0 +1,29 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/class.listnotifier.php';
/**
* ContactListNotifier.
*
* Generates notifications for changes to the
* Contact Folder contents.
*/
class ContactListNotifier extends ListNotifier {
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
#[Override]
protected function getPropertiesList() {
return $GLOBALS["properties"]->getContactListProperties();
}
}
@@ -0,0 +1,213 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* Hierarchy Notifier.
*
* Generates notifications which might be created
* inside the hierarchy.
*/
class HierarchyNotifier extends Notifier {
/**
* Flag to indicate that we need to reopen store object to get updated message size.
*/
private $reopenStore;
/**
* previous store size of the default store of user, this is updated whenever
* notification is sent to client to update quota details.
*/
private $storeSize;
public function __construct() {
/*
* Initialize hierarchy store's size, so in future on change events of
* folder object or message item we can check store's previous size,
* and if it is changed then send notification to server.
*/
$this->storeSize = -1;
parent::__construct();
}
/**
* @return Number Return the bitmask of events which are handled
* by this notifier. The bitmask can consist of the
* OBJECT_SAVE, OBJECT_DELETE, TABLE_SAVE, TABLE_DELETE, REQUEST_START and REQUEST_END flags
*/
#[Override]
public function getEvents() {
return OBJECT_SAVE | OBJECT_DELETE | TABLE_SAVE | TABLE_DELETE | REQUEST_START | REQUEST_END;
}
#[Override]
public function reset() {
parent::reset();
$this->reopenStore = false;
}
#[Override]
public function usePersistentStateLock($event = null) {
return $event === REQUEST_END;
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case REQUEST_START:
$this->reopenStore = false;
break;
case OBJECT_SAVE:
case TABLE_SAVE:
case TABLE_DELETE:
$data = [];
// If no PR_ENTRYID is given, we will settle with PR_PARENT_ENTRYID
$folderEntryid = false;
if (isset($props[PR_PARENT_ENTRYID])) {
$folderEntryid = $props[PR_PARENT_ENTRYID];
}
elseif (isset($props[PR_ENTRYID])) {
$folderEntryid = $props[PR_ENTRYID];
}
// We won't send notifiers for changes to the todolist folder, since there is nothing to
// be updated by the client.
$entryIdUtil = new EntryId();
$todoListEntryId = TodoList::getEntryId();
if ($folderEntryid !== false && $todoListEntryId !== false && $entryIdUtil->compareEntryIds(bin2hex($folderEntryid), bin2hex($todoListEntryId))) {
return;
}
if (!isset($props[PR_STORE_ENTRYID]) && !$folderEntryid) {
break;
}
$store = $GLOBALS["mapisession"]->openMessageStore($props[PR_STORE_ENTRYID]);
if (!$store) {
break;
}
try {
$folder = mapi_msgstore_openentry($store, $folderEntryid);
}
catch (MAPIException $e) {
$e->setHandled();
break;
}
if ($folder) {
$properties = $GLOBALS["properties"]->getFolderListProperties();
$folderProps = mapi_getprops($folder, $properties);
// If this folder belongs to Favorites folder,then change PARENT_ENTRYID manually.
if ($GLOBALS["entryid"]->isFavoriteFolder($folderProps[PR_ENTRYID])) {
$storeProps = mapi_getprops($store, [PR_IPM_FAVORITES_ENTRYID]);
if (isset($storeProps[PR_IPM_FAVORITES_ENTRYID])) {
$favFolder = mapi_msgstore_openentry($store, $storeProps[PR_IPM_FAVORITES_ENTRYID]);
$favHierarchyTable = mapi_folder_gethierarchytable($favFolder, MAPI_DEFERRED_ERRORS);
$folders = mapi_table_queryallrows(
$favHierarchyTable,
[PR_DISPLAY_NAME, PR_STORE_ENTRYID],
[RES_PROPERTY,
[
RELOP => RELOP_EQ,
ULPROPTAG => PR_ENTRYID,
VALUE => [
PR_ENTRYID => $folderProps[PR_ENTRYID],
],
],
]
);
if (!empty($folders)) {
// Update folderProps to properties of folder which is under 'FAVORITES'
$folderProps[PR_DISPLAY_NAME] = $folders[0][PR_DISPLAY_NAME];
$folderProps[PR_PARENT_ENTRYID] = $storeProps[PR_IPM_FAVORITES_ENTRYID];
}
}
}
$data[] = $GLOBALS["operations"]->setFolder($folderProps);
}
$this->addNotificationActionData("folders", ["item" => $data]);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
// data is changed in store so message size will be updated so reopen store to get correct data
$this->reopenStore = true;
break;
case OBJECT_DELETE:
if (isset($props[PR_ENTRYID], $props[PR_PARENT_ENTRYID])) {
$data = [];
$data["folderdelete"] = 1;
$data["entryid"] = bin2hex($props[PR_ENTRYID]);
$data["parent_entryid"] = bin2hex($props[PR_PARENT_ENTRYID]);
$data["store_entryid"] = bin2hex((string) $props[PR_STORE_ENTRYID]);
$this->addNotificationActionData("folders", ["item" => $data]);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
// data is changed in store so message size will be updated so reopen store to get correct data
$this->reopenStore = true;
}
break;
case REQUEST_END:
if ($this->reopenStore) {
// @FIXME this actually very heavy operation for performance point of view
// we need to remove this in future
$store = $GLOBALS["mapisession"]->getDefaultMessageStore(true);
}
else {
$store = $GLOBALS["mapisession"]->getDefaultMessageStore();
}
// reset flag for further use
$this->reopenStore = false;
// Send notification for any changes in store's properties
if ($store) {
$storeProps = mapi_getprops($store, [PR_ENTRYID, PR_STORE_ENTRYID, PR_MDB_PROVIDER, PR_OBJECT_TYPE, PR_PROHIBIT_SEND_QUOTA, PR_QUOTA_WARNING_THRESHOLD, PR_PROHIBIT_RECEIVE_QUOTA, PR_MESSAGE_SIZE_EXTENDED]);
$storeSize = round($storeProps[PR_MESSAGE_SIZE_EXTENDED] / 1024);
// Check whether size of the store is changed, if it is changed then
// send latest store size and quota information to client-side.
if ($this->storeSize != $storeSize) {
$data = [];
$data["props"] = [];
$data["store_entryid"] = bin2hex((string) $storeProps[PR_STORE_ENTRYID]);
$data["props"]["object_type"] = $storeProps[PR_OBJECT_TYPE];
$data["props"]["store_size"] = $storeSize;
$data["props"]["quota_warning"] = $storeProps[PR_QUOTA_WARNING_THRESHOLD] ?? 0;
$data["props"]["quota_soft"] = $storeProps[PR_PROHIBIT_SEND_QUOTA] ?? 0;
$data["props"]["quota_hard"] = $storeProps[PR_PROHIBIT_RECEIVE_QUOTA] ?? 0;
$this->addNotificationActionData("stores", ["item" => [$data]]);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
// assign size for next checking
$this->storeSize = $storeSize;
}
}
break;
}
}
}
@@ -0,0 +1,111 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* ListNotifier.
*
* Generates notifications for changes to the
* folder contents.
*/
class ListNotifier extends Notifier {
/**
* @return Number Return the bitmask of events which are handled
* by this notifier. The bitmask can consist of the
* OBJECT_SAVE, OBJECT_DELETE, TABLE_SAVE, TABLE_DELETE, REQUEST_START and REQUEST_END flags
*/
#[Override]
public function getEvents() {
return OBJECT_SAVE | TABLE_SAVE | TABLE_DELETE;
}
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
protected function getPropertiesList() {
return [];
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case TABLE_SAVE:
$data = [];
if (isset($props[PR_STORE_ENTRYID])) {
$store = $GLOBALS["mapisession"]->openMessageStore($props[PR_STORE_ENTRYID]);
if (isset($props[PR_ENTRYID])) {
$properties = $this->getPropertiesList();
$data = $GLOBALS["operations"]->getMessageProps($store, $GLOBALS["operations"]->openMessage($store, $props[PR_ENTRYID]), $properties);
$this->addNotificationActionData("update", ["item" => [$data]]);
}
elseif (isset($props[PR_PARENT_ENTRYID])) {
// An object was created inside this folder for which we don't know the entryid
// this can happen when we copy or move a message. Just tell the javascript that
// this folder has a new object.
$folder = mapi_msgstore_openentry($store, $props[PR_PARENT_ENTRYID]);
$folderProps = mapi_getprops($folder, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID, PR_CONTENT_COUNT, PR_CONTENT_UNREAD, PR_DISPLAY_NAME]);
$data = [
"item" => [
[
"content_count" => $folderProps[PR_CONTENT_COUNT],
"content_unread" => $folderProps[PR_CONTENT_UNREAD],
// Add store_entryid,entryid of folder and display_name of folder
// to JSON data in order to refresh the list.
"store_entryid" => bin2hex((string) $folderProps[PR_STORE_ENTRYID]),
"parent_entryid" => bin2hex((string) $folderProps[PR_PARENT_ENTRYID]),
"entryid" => bin2hex((string) $folderProps[PR_ENTRYID]),
"display_name" => $folderProps[PR_DISPLAY_NAME],
],
],
];
$this->addNotificationActionData("newobject", $data);
}
}
break;
case TABLE_DELETE:
$folderEntryID = $props[PR_PARENT_ENTRYID] ?? false;
if (isset($props[PR_ENTRYID]) && $folderEntryID) {
$data = [];
$data["parent_entryid"] = bin2hex((string) $folderEntryID);
if (is_array($props[PR_ENTRYID])) {
$data["entryid"] = [];
foreach ($props[PR_ENTRYID] as $deletedEntryId) {
array_push($data["entryid"], bin2hex((string) $deletedEntryId));
}
}
else {
$data["entryid"] = bin2hex((string) $props[PR_ENTRYID]);
}
$this->addNotificationActionData("delete", ["item" => [$data]]);
}
break;
}
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
}
}
@@ -0,0 +1,29 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/class.listnotifier.php';
/**
* MailListNotifier.
*
* Generates notifications for changes to the
* Mail Folder contents.
*/
class MailListNotifier extends ListNotifier {
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
#[Override]
protected function getPropertiesList() {
return $GLOBALS["properties"]->getMailListProperties();
}
}
@@ -0,0 +1,341 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once BASE_PATH . 'server/includes/core/class.newmailfolderquery.php';
/**
* NewMailNotifier.
*
* Generates notifications for hierarchy folder updates (content unread).
* Also piggybacks shared-store checks onto regular requests so that
* shared mailbox changes appear without waiting for the full polling
* interval.
*/
class NewMailNotifier extends Notifier {
/**
* Epoch timestamp of the last shared-store check, used for
* throttling so we don't query shared hierarchies on every
* single request.
*/
private $lastSharedCheck = 0;
/**
* Minimum number of seconds between shared-store hierarchy
* checks piggybacked onto regular requests.
*/
private const SHARED_CHECK_INTERVAL = 60;
/**
* Hex entryids of the folders the client never notifies about, keyed by
* the hex entryid of the store they belong to.
*/
private $excludedFolders = [];
/**
* @return Number the event which this module handles
*/
#[Override]
public function getEvents() {
return HIERARCHY_UPDATE | REQUEST_END;
}
#[Override]
public function usePersistentStateLock($event = null) {
return false;
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case HIERARCHY_UPDATE:
$this->updateFolderHierachy($props[0], $props[1]);
break;
case REQUEST_END:
$this->checkSharedStores();
break;
}
}
/**
* Check shared and public stores for hierarchy changes, throttled to avoid
* querying on every single request.
*/
private function checkSharedStores() {
$now = time();
if (($now - $this->lastSharedCheck) < self::SHARED_CHECK_INTERVAL) {
return;
}
$requestStateId = $GLOBALS['request_state_id'] ?? null;
if (is_string($requestStateId) && $requestStateId !== '') {
$checkState = new State('newmail-check-lease-' . hash('sha256', $requestStateId));
if ($checkState->open()) {
try {
$lastSharedCheck = max((int) $checkState->read('lastSharedCheck'), $this->lastSharedCheck);
if (($now - $lastSharedCheck) < self::SHARED_CHECK_INTERVAL) {
$this->lastSharedCheck = $lastSharedCheck;
return;
}
$checkState->write('lastSharedCheck', $now);
}
finally {
$checkState->close();
}
}
}
$this->lastSharedCheck = $now;
$this->updateOpenedStoreHierachies();
if (ENABLE_PUBLIC_FOLDERS) {
$this->updatePublicFolderHierachy();
}
}
/**
* Update unread counters for all opened non-public stores.
*/
private function updateOpenedStoreHierachies() {
$stores = $GLOBALS["mapisession"]->getOtherUserStore();
$defaultStoreEntryId = $GLOBALS["mapisession"]->getDefaultMessageStoreEntryId();
foreach ($stores as $store) {
try {
$storeProps = mapi_getprops($store, [PR_ENTRYID, PR_MDB_PROVIDER, PR_DISPLAY_NAME, PR_MAILBOX_OWNER_NAME]);
}
catch (MAPIException $e) {
$e->setHandled();
continue;
}
if (($storeProps[PR_MDB_PROVIDER] ?? null) == ZARAFA_STORE_PUBLIC_GUID) {
continue;
}
$storeEntryId = bin2hex((string) $storeProps[PR_ENTRYID]);
$isDefaultStore = $GLOBALS["entryid"]->compareEntryIds($storeEntryId, $defaultStoreEntryId);
$cacheKey = $isDefaultStore ? 'sessionData' : 'store_' . $storeEntryId;
$displayName = $isDefaultStore ? null : str_replace('Inbox - ', '', $storeProps[PR_MAILBOX_OWNER_NAME] ?? $storeProps[PR_DISPLAY_NAME] ?? '');
$folderType = $this->getOpenedStoreFolderType($storeProps[PR_ENTRYID]);
$this->updateFolderHierachy('', $folderType, $store, $cacheKey, $displayName, $isDefaultStore);
}
}
/**
* Returns the configured folder type for a manually opened shared store.
* Automatically opened stores do not have a setting and use the full subtree.
*
* @param string $storeEntryId binary store entryid
*
* @return string folder type for counter updates
*/
private function getOpenedStoreFolderType($storeEntryId) {
$username = $GLOBALS["mapisession"]->getUserNameOfStore($storeEntryId);
if (!$username) {
return '';
}
$otherUsers = $GLOBALS["mapisession"]->retrieveOtherUsersFromSettings();
if (!isset($otherUsers[$username])) {
return '';
}
$folderType = array_key_first($otherUsers[$username]);
$supportedTypes = ['inbox' => 1, 'all' => 1];
return isset($supportedTypes[$folderType]) ? $folderType : '';
}
/**
* Update unread counters for the public store hierarchy.
*/
private function updatePublicFolderHierachy() {
$store = $GLOBALS["mapisession"]->getPublicMessageStore();
if (!$store) {
return;
}
$this->updateFolderHierachy('', '', $store, 'publicStore');
}
/**
* Fetch the folder hierarchy from the IPM.Subtree with the properties required for the newmail notification
* for grommunio Web client.
*
* The returned hierarchy is cached in the session state and compared when the function is called, when
* the data differs newmail notifications for the changed folder(s) are created and send to the client.
*
* @param string $username The user for whom the store is checked for mail updates. If not set, it will be
* current user's own store.
* @param string $folderType the type of shared folder (all, inbox or calendar)
* @param mixed $store optional already opened store
* @param string $cacheKey optional key for the counter state cache
* @param string $displayName optional store display name for shared-store notifications
* @param bool $logErrors whether to log root folder open failures
*/
private function updateFolderHierachy($username = '', $folderType = '', $store = null, $cacheKey = null, $displayName = null, $logErrors = true) {
if (!$store) {
if ($username) {
$userEntryid = $GLOBALS["mapisession"]->getStoreEntryIdOfUser($username);
$store = $userEntryid ? $GLOBALS["mapisession"]->openMessageStore($userEntryid) : false;
}
else {
$store = $GLOBALS["mapisession"]->getDefaultMessageStore();
}
if (!$store) {
return;
}
}
$cacheKey ??= 'sessionData';
if ($username) {
$cacheKey = $username;
}
$counterLock = new State('counter-lock-' . hash('sha256', $cacheKey));
if (!$counterLock->open()) {
return;
}
try {
$this->updateFolderHierachyLocked($username, $folderType, $store, $cacheKey, $displayName, $logErrors);
}
finally {
$counterLock->close();
}
}
/**
* Update one counter cache while its computation lock is held.
*
* @param mixed $username
* @param mixed $folderType
* @param mixed $store
* @param mixed $cacheKey
* @param mixed $displayName
* @param mixed $logErrors
*/
private function updateFolderHierachyLocked($username, $folderType, $store, $cacheKey, $displayName, $logErrors) {
$counterState = new State('counters_sessiondata');
if (!$counterState->open()) {
return;
}
try {
$sessionData = $counterState->read($cacheKey);
}
finally {
$counterState->close();
}
if (!is_array($sessionData)) {
$sessionData = [];
}
$folderStatCache = updateHierarchyCounters($username, $folderType, $store, $logErrors);
// Keep the previous counter state when the hierarchy could not be read.
if (empty($folderStatCache)) {
return;
}
if ($folderStatCache !== $sessionData) {
$data = ["item" => []];
$name = null;
foreach ($folderStatCache as $entryid => $props) {
if (isset($sessionData[$entryid]) &&
$sessionData[$entryid]['commit_time'] !== $props['commit_time']) {
$name ??= $username ? $GLOBALS["mapisession"]->getDisplayNameofUser($username) : $displayName;
$item = [
'entryid' => $props['entryid'],
'store_entryid' => $props['store_entryid'],
'content_count' => $props['content_count'],
'content_unread' => $props['content_unread'],
'display_name' => $props['display_name'],
'user_display_name' => $name,
];
$prevUnread = $sessionData[$entryid]['content_unread'] ?? -1;
if ($prevUnread >= 0 && $props['content_unread'] >= 0) {
$delta = $props['content_unread'] - $prevUnread;
$item['content_unread_delta'] = $delta;
$isMailFolder = strcasecmp($props['container_class'] ?? '', 'IPF.Note') === 0;
if ($delta === 1 && $isMailFolder && !$this->isExcludedFolder($store, $props['store_entryid'], $entryid)) {
$newMessage = NewMailFolderQuery::newestUnreadMessage($store, $entryid);
if ($newMessage !== null) {
$item['new_message'] = $newMessage;
}
}
}
$data['item'][] = $item;
}
}
$this->addNotificationActionData("newmail", $data);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
$counterState = new State('counters_sessiondata');
if (!$counterState->open()) {
return;
}
try {
$counterState->write($cacheKey, $folderStatCache);
}
finally {
$counterState->close();
}
}
}
/**
* Check whether the client suppresses new mail notifications for a folder,
* so no message details have to be looked up for it. The same exclusion
* list as in Grommunio.hierarchy.data.HierarchyStore#onNotifyNewmail is used.
*
* @param mixed $store the store containing the folder
* @param string $storeEntryid hex entryid of that store
* @param string $entryid hex entryid of the folder
*
* @return bool true when the folder never shows a notification
*/
private function isExcludedFolder($store, $storeEntryid, $entryid) {
return NewMailFolderQuery::containsEntryid($this->getExcludedFolders($store, $storeEntryid), $entryid);
}
/**
* Collect the default folders for which the client never shows a new mail
* notification. The result is cached per store as it only changes when the
* mailbox layout itself changes.
*
* @param mixed $store the store to inspect
* @param string $storeEntryid hex entryid of that store, used as cache key
*
* @return array hex entryids of the excluded folders
*/
private function getExcludedFolders($store, $storeEntryid) {
return $this->excludedFolders[$storeEntryid] ??= NewMailFolderQuery::excludedFolders($store);
}
}
@@ -0,0 +1,47 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* NewTodoTaskNotifier.
*
* Generates notifications update To-Do list folder.
*/
class NewTodoTaskNotifier extends Notifier {
/**
* @return Number the event which this module handles
*/
#[Override]
public function getEvents() {
return OBJECT_SAVE;
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* @param int $event event
* @param string $entryid entryid
* @param mixed $props
*/
#[Override]
public function update($event, $entryid, $props) {
switch ($event) {
case OBJECT_SAVE:
$data = [
'item' => [[
'entryid' => $entryid,
'store_entryid' => bin2hex((string) $props[PR_STORE_ENTRYID]),
]],
];
$this->addNotificationActionData("newtodotask", $data);
$GLOBALS["bus"]->addData($this->createNotificationResponseData());
break;
}
}
}
@@ -0,0 +1,136 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* Notifier.
*
* Superclass for every notifier.
*/
class Notifier {
/**
* @var array list of the notifications, which is send to the client
*/
private $responseNotificationData;
/**
* @var int notification counter of the class
*/
private $notifyCount;
public function __construct() {
$this->notifyCount = 0;
$this->responseNotificationData = [];
}
/**
* @return Number Return the bitmask of events which are handled
* by this notifier. The bitmask can consist of the
* OBJECT_SAVE, OBJECT_DELETE, TABLE_SAVE, TABLE_DELETE, REQUEST_START and REQUEST_END flags
*/
public function getEvents() {
return 0;
}
/**
* Function which resets the data and the response data class variable.
*/
public function reset() {
$this->notifyCount = 0;
$this->responseNotificationData = [];
}
/**
* Whether updates need serialized persistent notifier state.
*
* Specialized notifiers may make this decision based on the event.
*
* @param null|mixed $event
*/
public function usePersistentStateLock(/* @scrutinizer ignore-unused */ $event = null) {
static $statefulClasses = [];
$className = get_class($this);
if (isset($statefulClasses[$className])) {
return $statefulClasses[$className];
}
$reflection = new ReflectionObject($this);
while ($reflection !== false && $reflection->getName() !== self::class) {
foreach ($reflection->getProperties() as $property) {
if ($property->getDeclaringClass()->getName() === $reflection->getName() && !$property->isStatic()) {
return $statefulClasses[$className] = true;
}
}
$reflection = $reflection->getParentClass();
}
return $statefulClasses[$className] = false;
}
/**
* Function which returns name of the notifier class.
*
* @return string notifier name
*/
public function getNotifierName() {
return strtolower(static::class);
}
/**
* Function which adds notification data to module, so later it can be retrieved to send.
*
* @param string $actionType type of action that response data corresponds
* @param mixed $data
*/
protected function addNotificationActionData($actionType, $data) {
if (!isset($this->responseNotificationData[$actionType])) {
$this->responseNotificationData[$actionType] = $data;
}
}
/**
* Function which returns notification data that will be sent to client. If there isn't any data added
* to response data then it will return a blank array.
*
* @return array response data
*/
protected function createNotificationResponseData() {
if (!empty($this->responseNotificationData)) {
$moduleName = $this->getNotifierName();
$idName = $moduleName . (++$this->notifyCount);
$response = [
$moduleName => [
$idName => $this->responseNotificationData,
],
];
// Clear notification data, the response which is being returned
// should be sent to the client.
$this->responseNotificationData = [];
return $response;
}
return [];
}
/**
* If an event elsewhere has occurred, it enters in this method. This method
* executes one or more actions, depends on the event.
*
* Implementations receive all three values; the default hook is intentionally empty.
*
* @param int $event event
* @param string $entryid entryid
* @param array $data array of data
*/
public function update(/* @scrutinizer ignore-unused */ $event, /* @scrutinizer ignore-unused */ $entryid, /* @scrutinizer ignore-unused */ $data) {
// you must implement this function for each notifier
}
}
@@ -0,0 +1,29 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/class.listnotifier.php';
/**
* StickyNoteListNotifier.
*
* Generates notifications for changes to the
* StickyNote Folder contents.
*/
class StickyNoteListNotifier extends ListNotifier {
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
#[Override]
protected function getPropertiesList() {
return $GLOBALS["properties"]->getStickyNoteListProperties();
}
}
@@ -0,0 +1,29 @@
<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/class.listnotifier.php';
/**
* TaskListNotifier.
*
* Generates notifications for changes to the
* Task Folder contents.
*/
class TaskListNotifier extends ListNotifier {
/**
* Obtain the list of Message Properties which should be returned
* to the client when a Message was changed.
*
* @return array The properties mapping
*/
#[Override]
protected function getPropertiesList() {
return $GLOBALS["properties"]->getTaskGridProperties();
}
}