setHandled(); } return $excluded; } /** * @param array $entryids hex entryids * @param string $entryid hex entryid to look for * * @return bool true when $entryid is one of $entryids */ public static function containsEntryid($entryids, $entryid) { foreach ($entryids as $candidate) { if ($GLOBALS["entryid"]->compareEntryIds($candidate, $entryid)) { return true; } } return false; } /** * Fetch sender and subject of the newest unread message in a folder, used * to enrich the notification when exactly one new message arrived. * * @param mixed $store store containing the folder * @param string $entryid hex folder entryid * * @return null|array sender_name and subject, or null when unavailable */ public static function newestUnreadMessage($store, $entryid) { try { $folder = mapi_msgstore_openentry($store, hex2bin($entryid)); $table = mapi_folder_getcontentstable($folder, MAPI_DEFERRED_ERRORS); mapi_table_restrict($table, [RES_BITMASK, [ ULTYPE => BMR_EQZ, ULPROPTAG => PR_MESSAGE_FLAGS, ULMASK => MSGFLAG_READ, ], ], TBL_BATCH); mapi_table_sort($table, [PR_MESSAGE_DELIVERY_TIME => TABLE_SORT_DESCEND], TBL_BATCH); $rows = mapi_table_queryrows($table, [PR_SENT_REPRESENTING_NAME, PR_SENDER_NAME, PR_SENT_REPRESENTING_SMTP_ADDRESS, PR_SUBJECT], 0, 1); if (empty($rows)) { return null; } $row = $rows[0]; $sender = $row[PR_SENT_REPRESENTING_NAME] ?? $row[PR_SENDER_NAME] ?? $row[PR_SENT_REPRESENTING_SMTP_ADDRESS] ?? ''; $subject = $row[PR_SUBJECT] ?? ''; if ($sender === '' && $subject === '') { return null; } return [ 'sender_name' => $sender, 'subject' => $subject, ]; } catch (MAPIException $e) { $e->setHandled(); return null; } } }