Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
mailboxconnecting.php
1
<?php
2
3
namespace
Bitrix\Mail\Controller
;
4
5
use
Bitrix\Mail\Helper\Mailbox
;
6
use
Bitrix\Mail\Helper\Mailbox\MailboxConnector
;
7
use
Bitrix\Mail\MailServicesTable
;
8
use
Bitrix\Main\Engine\Controller
;
9
use
Bitrix\Main\Engine\UrlManager
;
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Main\Loader
;
12
use
Bitrix\Mail\Helper\OAuth
;
13
use
Bitrix\Main\Localization\Loc
;
14
use
Bitrix\Main\Web\Uri
;
15
22
class
MailboxConnecting
extends
Controller
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
}
Bitrix\Mail\Controller\MailboxConnecting
Definition
mailboxconnecting.php:23
Bitrix\Mail\Controller\MailboxConnecting\getUrlOauthAction
getUrlOauthAction(string $serviceName, string $type=OAuth::WEB_TYPE)
Definition
mailboxconnecting.php:30
Bitrix\Mail\Controller\MailboxConnecting\getConnectionUrlAction
getConnectionUrlAction()
Definition
mailboxconnecting.php:78
Bitrix\Mail\Controller\MailboxConnecting\connectMailboxAction
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='')
Definition
mailboxconnecting.php:84
Bitrix\Mail\Controller\MailboxConnecting\getServicesAction
getServicesAction()
Definition
mailboxconnecting.php:53
Bitrix\Mail\Helper\Mailbox\MailboxConnector
Definition
mailboxconnector.php:15
Bitrix\Mail\Helper\Mailbox\getServices
static getServices()
Definition
mailbox.php:51
Bitrix\Mail\Helper\OAuth
Definition
oauth.php:12
Bitrix\Mail\Helper\OAuth\WEB_TYPE
const WEB_TYPE
Definition
oauth.php:21
Bitrix\Mail\Helper\OAuth\getInstance
static getInstance($service=null)
Definition
oauth.php:54
Bitrix\Mail\MailServicesTable
Definition
mailservices.php:28
Bitrix\Mail\MailServicesTable\getOAuthHelper
static getOAuthHelper($data)
Definition
mailservices.php:216
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Engine\UrlManager
Definition
urlmanager.php:11
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Mail\Controller
Definition
addressbook.php:3
Bitrix\Mail\Helper\Mailbox
Definition
imap.php:3
Bitrix\Mail\Helper\OAuth
Definition
google.php:3
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
mail
lib
controller
mailboxconnecting.php
Создано системой
1.10.0