23 $manager =
new static();
24 $manager->processOnMailMessageDeletedEvent($event);
28 private function processOnMailMessageDeletedEvent(
Event $event)
31 $filter = empty($params[
'DELETED_BY_FILTER']) ? [] : $params[
'DELETED_BY_FILTER'];
32 $fieldsData = empty($params[
'MAIL_FIELDS_DATA']) ? [] : $params[
'MAIL_FIELDS_DATA'];
33 $this->handleRemovedEvent($fieldsData, $filter);
44 $manager =
new static();
45 $manager->processOnMailMessageModified($event);
49 private function processOnMailMessageModified(
Event $event)
52 $updatedFieldValues = empty($params[
'UPDATED_FIELDS_VALUES']) ? [] : $params[
'UPDATED_FIELDS_VALUES'];
53 $fieldsData = empty($params[
'MAIL_FIELDS_DATA']) ? [] : $params[
'MAIL_FIELDS_DATA'];
54 $filter = empty($params[
'UPDATED_BY_FILTER']) ? [] : $params[
'UPDATED_BY_FILTER'];
56 if (!empty($updatedFieldValues) && isset($updatedFieldValues[
'IS_SEEN']))
58 $fieldsData = $this->getMailsFieldsData($fieldsData, [
'HEADER_MD5',
'MAILBOX_USER_ID',
'IS_SEEN'], $filter);
62 if (!empty($updatedFieldValues) && isset($updatedFieldValues[
'DIR_MD5']) && isset($filter[
'=MAILBOX_ID']))
64 $dirHash = empty($updatedFieldValues[
'DIR_MD5']) ? null : $updatedFieldValues[
'DIR_MD5'];
67 if (!empty($dirHash) && $dir !=
null)
69 if ($dir->isTrash() || $dir->isSpam() || $dir->isDisabled())
71 $this->handleRemovedEvent($fieldsData, $filter);
79 foreach ($fieldsData as $fields)
82 'mail',
'OnMessageModified',
84 'user' => $fields[
'MAILBOX_USER_ID'],
85 'hash' => $fields[
'HEADER_MD5'],
86 'seen' => $fields[
'IS_SEEN'] ===
'Y',
93 private function handleRemovedEvent($fieldsData, $filter)
100 foreach ($fieldsData as $fields)
103 'mail',
'OnMessageObsolete',
105 'user' => $fields[
'MAILBOX_USER_ID'],
106 'hash' => $fields[
'HEADER_MD5'],
113 private function getMailsFieldsData($eventData, $requiredKeys, $filter)
115 $fieldsData = $eventData;
116 $missingKeys = $requiredKeys;
117 $messagesCount = count($eventData);
120 foreach ($requiredKeys as $requiredKey)
122 if (count(array_column($eventData, $requiredKey)) === $messagesCount)
124 $missingKeys = array_diff($missingKeys, [$requiredKey]);
129 if (!empty($missingKeys) && !empty($filter))
134 foreach ($fieldsData as $index => $mailFieldsData)
136 $results[$mailFieldsData[
'HEADER_MD5']] = $mailFieldsData;
144 $dateLastMonth->add(
'-1 MONTH');
145 foreach ($selectingFields as $index => $selectingField)
147 if (strncmp(
'MAILBOX_', $selectingField, 8) === 0)
149 $selectingFields[$selectingField] =
'MAILBOX.'.mb_substr($selectingField, 8);
150 unset($selectingFields[$index]);
154 return MailMessageUidTable::getList([
155 'select' => $selectingFields,
156 'filter' => array_merge($filter, [
157 '>=INTERNALDATE' => $dateLastMonth,
158 '==DELETE_TIME' => 0,
172 $messageId = $data[
'msgid'];
175 $message = MailMessageTable::getList([
177 'OPTIONS',
'ID',
'READ_CONFIRMED',
180 '=MSG_ID' => $messageId,
181 'READ_CONFIRMED' =>
null,
187 $result = MailMessageTable::update($message[
'ID'], [
188 'READ_CONFIRMED' => $readTime,
190 if($result->isSuccess())
192 if(Loader::includeModule(
"pull"))
194 \CPullWatch::addToStack(static::getPullTagName($message[
'ID']), [
195 'module_id' =>
'mail',
196 'command' =>
'onMessageRead',
198 'messageId' => $message[
'ID'],
199 'readTime' => $readTime->getTimestamp(),
212 return 'MAILMESSAGEREADED'.$messageId;
217 if ($eventName === static::EVENT_DELETE_MESSAGES)
219 return array(
'HEADER_MD5',
'MESSAGE_ID',
'MAILBOX_USER_ID');