Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
allowedsender.php
1<?
4
6{
12 public static function getList($forUserId = null)
13 {
14 $result = [];
15
16 $userMailboxes = \Bitrix\Main\Mail\Sender::prepareUserMailboxes($forUserId);
17 if (is_array($userMailboxes))
18 {
19 foreach ($userMailboxes as $mailbox)
20 {
21 $formatted = isset($mailbox['formatted']) ? $mailbox['formatted'] : $mailbox['formated'];
22 $result[] = [
23 'name' => $mailbox['name'],
24 'email' => $mailbox['email'],
25 'formatted' => preg_replace("/^<(.*)>$/i", "$1", $formatted),
26 ];
27 }
28 }
29
30 if (Loader::includeModule("sender")
31 && !\Bitrix\Sender\Integration\Bitrix24\Service::isCloud())
32 {
33 $addressFromList = \Bitrix\Sender\MailingChainTable::getEmailFromList();
34 $address = new \Bitrix\Main\Mail\Address();
35 foreach ($addressFromList as $email)
36 {
37 $address->set($email);
38 $formatted = $address->get();
39 if (!$formatted)
40 {
41 continue;
42 }
43
44 $result[] = [
45 'name' => $address->getName(),
46 'email' => $address->getEmail(),
47 'formatted' => preg_replace("/^<(.*)>$/i", "$1", $formatted),
48 ];
49 }
50 }
51
52 return $result;
53 }
54
61 public static function isAllowed($email, $userId = null)
62 {
63 if ($email == '')
64 {
65 return false;
66 }
67
68 $address = new Address();
69 $address->set($email);
70 $normalizedEmail = $address->getEmail();
71 if (!$normalizedEmail)
72 {
73 return false;
74 }
75 $normalizedEmail = mb_strtolower($normalizedEmail);
76 $allowedSenders = self::getList($userId);
77 if (empty(array_filter($allowedSenders, function ($item) use ($normalizedEmail)
78 {
79 return mb_strtolower($item['email']) === $normalizedEmail;
80 })))
81 {
82 return false;
83 }
84
85 return true;
86 }
87}