Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
syncinternalmanager.php
1
<?php
2
3
namespace
Bitrix\Mail\ImapCommands
;
4
5
use
Bitrix\Mail\Helper\Mailbox
;
6
use
Bitrix\Mail\Internals\MailboxDirectoryTable
;
7
use
Bitrix\Main
;
8
use
Bitrix\Main\Localization\Loc
;
9
10
Loc::loadMessages
(__FILE__);
11
16
class
SyncInternalManager
17
{
18
const
FLAG_UNSEEN
=
'unseen'
;
19
const
FLAG_SEEN
=
'seen'
;
20
21
protected
$userId
;
22
protected
$mailbox
;
23
protected
$mailboxId
;
24
protected
$mailboxUserId
;
25
protected
$messagesIds
;
26
protected
$messages
;
27
private
$isInit;
29
protected
$repository
;
31
protected
$mailboxHelper
;
32
33
public
function
__construct
(
$mailboxId
,
$messagesIds
,
$userId
=
null
)
34
{
35
$this->mailboxId =
$mailboxId
;
36
if
(!is_array(
$messagesIds
))
37
{
38
$messagesIds
= [
$messagesIds
];
39
}
40
$this->messagesIds =
$messagesIds
;
41
$this->userId =
$userId
;
42
$this->repository = $this->
getRepository
();
43
$this->mailboxHelper = $this->
getMailClientHelper
();
44
}
45
46
public
function
setUserId
(
$userId
)
47
{
48
$this->userId =
$userId
;
49
}
50
51
protected
function
getRepository
()
52
{
53
return
new
Repository
($this->mailboxId, $this->messagesIds);
54
}
55
56
protected
function
getMailClientHelper
($throwExceptions =
true
)
57
{
58
return
Mailbox::createInstance
($this->mailboxId, $throwExceptions);
59
}
60
61
protected
function
initData
($folderType =
null
)
62
{
63
if
($this->isInit)
64
{
65
return
new
Main\Result
();
66
}
67
$this->isInit =
true
;
68
$result =
new
Main\Result
();
69
70
$this->mailbox = $this->repository->getMailbox($this->mailboxUserId);
71
if
(!$this->mailbox)
72
{
73
return
$result->addError(
new
Main\
Error
(
Loc::getMessage
(
'MAIL_CLIENT_MAILBOX_NOT_FOUND'
),
74
'MAIL_CLIENT_MAILBOX_NOT_FOUND'
));
75
}
76
77
if
($folderType)
78
{
79
$folder = $this->
getDirPathByType
($folderType);
80
if
(!$folder)
81
{
82
$errorCode =
'MAIL_CLIENT_'
. ($folderType == MailboxDirectoryTable::TYPE_TRASH ?
'TRASH'
:
'SPAM'
) .
'_FOLDER_NOT_SELECTED_ERROR'
;
83
return
$result->addError(
new
Main\
Error
(
84
Loc::getMessage
($errorCode),
85
$errorCode));
86
}
87
}
88
if
(is_null($this->messages))
89
{
90
$this->messages = $this->repository->getMessages();
91
}
92
93
if
(empty($this->messages))
94
{
95
return
$result->addError(
new
Main\
Error
(
Loc::getMessage
(
'MAIL_CLIENT_MESSAGES_NOT_FOUND'
),
96
'MAIL_CLIENT_MESSAGES_NOT_FOUND'
));
97
}
98
$this->
fillMessagesEmails
();
99
100
$folders = [];
101
foreach
($this->messages as $index => $message)
102
{
103
if
(in_array($message[
'ID'
], $this->messagesIds,
true
))
104
{
105
$folders[$message[
'DIR_MD5'
]] = $message[
'DIR_MD5'
];
106
}
107
}
108
if
(count($folders) > 1)
109
{
110
return
$result->addError(
new
Main\
Error
(
Loc::getMessage
(
'MAIL_CLIENT_MESSAGES_MULTIPLE_FOLDERS'
),
111
'MAIL_CLIENT_MESSAGES_MULTIPLE_FOLDERS'
));
112
}
113
return
$result;
114
}
115
116
protected
function
getDirPathByType
($dirType)
117
{
118
return
$this->mailboxHelper->getDirsHelper()->getDirPathByType($dirType);
119
}
120
121
protected
function
getDirByPath
($path)
122
{
123
return
$this->mailboxHelper->getDirsHelper()->getDirByPath($path);
124
}
125
126
protected
function
fillMessagesEmails
()
127
{
128
foreach
($this->messages as $index => $message)
129
{
130
$address =
new
Main\Mail\Address
($message[
'FIELD_FROM'
]);
131
$this->messages[$index][
'EMAIL'
] = $address->getEmail();
132
}
133
}
134
}
Bitrix\Mail\Helper\Mailbox\createInstance
static createInstance($id, $throw=true)
Definition
mailbox.php:101
Bitrix\Mail\ImapCommands\Repository
Definition
repository.php:10
Bitrix\Mail\ImapCommands\SyncInternalManager
Definition
syncinternalmanager.php:17
Bitrix\Mail\ImapCommands\SyncInternalManager\FLAG_UNSEEN
const FLAG_UNSEEN
Definition
syncinternalmanager.php:18
Bitrix\Mail\ImapCommands\SyncInternalManager\$mailbox
$mailbox
Definition
syncinternalmanager.php:22
Bitrix\Mail\ImapCommands\SyncInternalManager\$repository
$repository
Definition
syncinternalmanager.php:29
Bitrix\Mail\ImapCommands\SyncInternalManager\initData
initData($folderType=null)
Definition
syncinternalmanager.php:61
Bitrix\Mail\ImapCommands\SyncInternalManager\getRepository
getRepository()
Definition
syncinternalmanager.php:51
Bitrix\Mail\ImapCommands\SyncInternalManager\$messages
$messages
Definition
syncinternalmanager.php:26
Bitrix\Mail\ImapCommands\SyncInternalManager\FLAG_SEEN
const FLAG_SEEN
Definition
syncinternalmanager.php:19
Bitrix\Mail\ImapCommands\SyncInternalManager\fillMessagesEmails
fillMessagesEmails()
Definition
syncinternalmanager.php:126
Bitrix\Mail\ImapCommands\SyncInternalManager\$mailboxId
$mailboxId
Definition
syncinternalmanager.php:23
Bitrix\Mail\ImapCommands\SyncInternalManager\$mailboxHelper
$mailboxHelper
Definition
syncinternalmanager.php:31
Bitrix\Mail\ImapCommands\SyncInternalManager\__construct
__construct($mailboxId, $messagesIds, $userId=null)
Definition
syncinternalmanager.php:33
Bitrix\Mail\ImapCommands\SyncInternalManager\$userId
$userId
Definition
syncinternalmanager.php:21
Bitrix\Mail\ImapCommands\SyncInternalManager\$mailboxUserId
$mailboxUserId
Definition
syncinternalmanager.php:24
Bitrix\Mail\ImapCommands\SyncInternalManager\getDirByPath
getDirByPath($path)
Definition
syncinternalmanager.php:121
Bitrix\Mail\ImapCommands\SyncInternalManager\setUserId
setUserId($userId)
Definition
syncinternalmanager.php:46
Bitrix\Mail\ImapCommands\SyncInternalManager\getMailClientHelper
getMailClientHelper($throwExceptions=true)
Definition
syncinternalmanager.php:56
Bitrix\Mail\ImapCommands\SyncInternalManager\getDirPathByType
getDirPathByType($dirType)
Definition
syncinternalmanager.php:116
Bitrix\Mail\ImapCommands\SyncInternalManager\$messagesIds
$messagesIds
Definition
syncinternalmanager.php:25
Bitrix\Mail\Internals\MailboxDirectoryTable
Definition
mailboxdirectory.php:25
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Mail\Address
Definition
address.php:16
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Mail\Helper\Mailbox
Definition
imap.php:3
Bitrix\Mail\ImapCommands
Definition
mailsflagsmanager.php:3
Bitrix\Main
modules
mail
lib
imapcommands
syncinternalmanager.php
Создано системой
1.10.0