grommunio /
grommunio-web
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * NewMailNotifier |
||
| 4 | * |
||
| 5 | * Generates notifications for hierarchy folder updates (content unread). |
||
| 6 | */ |
||
| 7 | class NewMailNotifier extends Notifier |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @return Number the event which this module handles. |
||
| 11 | */ |
||
| 12 | public function getEvents() |
||
| 13 | { |
||
| 14 | return HIERARCHY_UPDATE; |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * If an event elsewhere has occurred, it enters in this method. This method |
||
| 19 | * executes one ore more actions, depends on the event. |
||
| 20 | * @param int $event Event. |
||
| 21 | * @param string $entryid Entryid. |
||
| 22 | * @param array $data array of data. |
||
| 23 | */ |
||
| 24 | public function update($event, $entryid, $props) |
||
| 25 | { |
||
| 26 | switch ($event) { |
||
| 27 | case HIERARCHY_UPDATE: |
||
| 28 | $this->updateFolderHierachy($props[0], $props[1]); |
||
| 29 | break; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Fetch the folder hierarchy from the IPM.Subtree with the properties required for the newmail notification |
||
| 35 | * for grommunio Web client. |
||
| 36 | * |
||
| 37 | * The returned hierarchy is cached in the session state and compared when the function is called, when |
||
| 38 | * the data differs newmail notifications for the changed folder(s) are created and send to the client. |
||
| 39 | * @param string $username The user for whom the store is checked for mail updates. If not set, it will be |
||
| 40 | * current user's own store. |
||
| 41 | * @param string $folderType the type of shared folder (all, inbox or calendar) |
||
| 42 | */ |
||
| 43 | private function updateFolderHierachy($username='', $folderType='') { |
||
| 44 | $counterState = new State('counters_sessiondata'); |
||
| 45 | $counterState->open(); |
||
| 46 | $cacheKey = 'sessionData'; |
||
| 47 | if ($username) { |
||
| 48 | $cacheKey = $username; |
||
| 49 | } |
||
| 50 | |||
| 51 | $sessionData = $counterState->read($cacheKey); |
||
| 52 | if (!is_array($sessionData)) { |
||
| 53 | $sessionData = array(); |
||
| 54 | } |
||
| 55 | |||
| 56 | $folderStatCache = updateHierarchyCounters($username, $folderType); |
||
| 57 | |||
| 58 | if ($folderStatCache !== $sessionData) { |
||
| 59 | $data = array("item" => array()); |
||
| 60 | |||
| 61 | foreach($folderStatCache as $display_name => $props) { |
||
| 62 | if (isset($sessionData[$display_name]) && |
||
| 63 | $sessionData[$display_name]['commit_time'] !== $props['commit_time']) { |
||
| 64 | if ($username) { |
||
| 65 | $name = $GLOBALS["mapisession"]->getDisplayNameofUser($username); |
||
| 66 | } else { |
||
| 67 | $name = null; |
||
| 68 | } |
||
| 69 | $data['item'][] = array( |
||
| 70 | 'entryid' => $props['entryid'], |
||
| 71 | 'store_entryid' => $props['store_entryid'], |
||
| 72 | 'content_count' => $props['content_count'], |
||
| 73 | 'content_unread' => $props['content_unread'], |
||
| 74 | 'display_name' => $display_name, |
||
| 75 | 'user_display_name' => $name, |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->addNotificationActionData("newmail", $data); |
||
| 81 | $GLOBALS["bus"]->addData($this->createNotificationResponseData()); |
||
| 82 | |||
| 83 | $counterState->write($cacheKey, $folderStatCache); |
||
| 84 | } |
||
| 85 | |||
| 86 | $counterState->close(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | ?> |
||
|
0 ignored issues
–
show
|
|||
| 90 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.