Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailboxconnecting.php
1<?php
2
4
15
23{
30 public function getUrlOauthAction(string $serviceName, string $type = OAuth::WEB_TYPE): string
31 {
32 if (!Loader::includeModule('mail'))
33 {
34 $this->addError(new Error(Loc::getMessage('MAIL_MAILBOX_CONNECTING_ERROR_MAIL_MODULE_IS_NOT_INSTALLED')));
35 return '';
36 }
37
38 $oauthHelper = OAuth::getInstance($serviceName);
39
40 if (!$oauthHelper)
41 {
42 $this->addError(new Error(Loc::getMessage('MAIL_MAILBOX_CONNECTING_ERROR_MAIL_MODULE_OAUTH_SERVICE_IS_NOT_CONFIGURED')));
43 return false;
44 }
45
46 return $oauthHelper->getUrl($type);
47 }
48
53 public function getServicesAction(): array
54 {
55 if (!Loader::includeModule('mail'))
56 {
57 $this->addError(new Error(Loc::getMessage('MAIL_MAILBOX_CONNECTING_ERROR_MAIL_MODULE_IS_NOT_INSTALLED')));
58 return [];
59 }
60
61 $services = Mailbox::getServices();
62
63 foreach ($services as &$service)
64 {
65 if (MailServicesTable::getOAuthHelper(['NAME' => $service['name']]) instanceof OAuth)
66 {
67 $service['oauthMode'] = true;
68 }
69 else
70 {
71 $service['oauthMode'] = false;
72 }
73 }
74
75 return $services;
76 }
77
78 public function getConnectionUrlAction(): string
79 {
80 $uri = new Uri(UrlManager::getInstance()->getHostUrl().'/bitrix/tools/mobile_oauth.php');
81 return $uri->getLocator();
82 }
83
84 public function connectMailboxAction(
85 string $login = '',
86 string $password = '',
87 int $serviceId = 0,
88 string $server = '',
89 int $port = 993,
90 bool $ssl = true,
91 string $storageOauthUid = '',
92 bool $syncAfterConnection = true,
93 bool $useSmtp = true,
94 string $serverSmtp = '',
95 int $portSmtp = 587,
96 bool $sslSmtp = true,
97 string $loginSmtp = '',
98 string $passwordSMTP = ''
99 ): array
100 {
101 if (!Loader::includeModule('mail'))
102 {
103 $this->addError(new Error(Loc::getMessage('MAIL_MAILBOX_CONNECTING_ERROR_MAIL_MODULE_IS_NOT_INSTALLED')));
104 return [];
105 }
106
107 $mailboxConnector = new MailboxConnector();
108 $result = $mailboxConnector->connectMailbox($login, $password, $serviceId, $server, $port, $ssl, $storageOauthUid, $syncAfterConnection, $useSmtp, $serverSmtp, $portSmtp, $sslSmtp, $loginSmtp, $passwordSMTP);
109 $this->addErrors($mailboxConnector->getErrors());
110
111 return $result;
112 }
113}
getUrlOauthAction(string $serviceName, string $type=OAuth::WEB_TYPE)
connectMailboxAction(string $login='', string $password='', int $serviceId=0, string $server='', int $port=993, bool $ssl=true, string $storageOauthUid='', bool $syncAfterConnection=true, bool $useSmtp=true, string $serverSmtp='', int $portSmtp=587, bool $sslSmtp=true, string $loginSmtp='', string $passwordSMTP='')
static getInstance($service=null)
Definition oauth.php:54
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29