Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messagesearchcontentstepper.php
1<?php
2
3namespace Bitrix\Mail\Helper;
6
8{
9 private const LIMIT = 100;
10 protected static $moduleId = 'mail';
11
12 public function execute(array &$option): bool
13 {
14 if (empty($option))
15 {
16 $option['lastId'] = 0;
17 $maxId = Mail\MailMessageTable::getList([
18 'order' => ['ID' => 'DESC'],
19 'limit' => 1,
20 'select' => ['ID'],
21 ])->fetch();
22 $option['maxId'] = (int) $maxId['ID'];
23 }
24
25 if ($option['lastId'] >= $option['maxId'])
26 {
28 }
29
30 $result = Mail\MailMessageTable::getList([
31 'select' => [
32 'ID',
33 'SEARCH_CONTENT',
34 ],
35 'filter' => [
36 '><ID' => [max($option['lastId'], 0),$option['maxId']],
37 ],
38 'order' => ['ID' => 'ASC'],
39 'limit' => self::LIMIT,
40 ]);
41
42 while ($message = $result->fetch())
43 {
44 $message['SEARCH_CONTENT'] = self::isolateBase64Files(str_rot13($message['SEARCH_CONTENT']));
45 Mail\MailMessageTable::update($message['ID'], [
46 'SEARCH_CONTENT' => $message['SEARCH_CONTENT'],
47 ]);
48
49 $option['lastId'] = $message['ID'];
50 }
51
53 }
54
55
56 private function isolateBase64Files(string $text): string
57 {
58 $pattern = '/\[\s*data:(?!text\b)[^;]+;base64,\S+ \]/';
59 $clearText = preg_replace($pattern, '', $text);
60 return str_rot13($clearText);
61 }
62}