Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messagefolder.php
1<?php
2
3namespace Bitrix\Mail\Helper;
8
13{
14 const TRASH = 'trash';
15 const SPAM = 'spam';
16 const INCOME = 'income';
17 const OUTCOME = 'outcome';
18 const DRAFTS = 'drafts';
19
20 public static function increaseDirCounter($mailboxId, $dirForMoveMessages = false, $dirForMoveMessagesId, $idsUnseenCount)
21 {
22 if(!is_null($dirForMoveMessages) && $dirForMoveMessages === false || !$dirForMoveMessages->isInvisibleToCounters()){
24 '=MAILBOX_ID' => $mailboxId,
25 '=ENTITY_TYPE' => 'DIR',
26 '=ENTITY_ID' => $dirForMoveMessagesId
27 ])
28 )
29 {
31 [
32 'MAILBOX_ID' => $mailboxId,
33 'ENTITY_TYPE' => 'DIR',
34 'ENTITY_ID' => $dirForMoveMessagesId
35 ],
36 [
37 "VALUE" => new \Bitrix\Main\DB\SqlExpression("?# + $idsUnseenCount", "VALUE")
38 ]
39 );
40 }
41 else
42 {
44 'MAILBOX_ID' => $mailboxId,
45 'ENTITY_TYPE' => 'DIR',
46 'ENTITY_ID' => $dirForMoveMessagesId
47 ],
48 [
49 "VALUE" => $idsUnseenCount,
50 ]);
51 }
52 }
53 }
54
55 public static function decreaseDirCounter($mailboxId, $dirWithMessagesId, $idsUnseenCount)
56 {
57 if($dirWithMessagesId)
58 {
60 '=MAILBOX_ID' => $mailboxId,
61 '=ENTITY_TYPE' => 'DIR',
62 '=ENTITY_ID' => $dirWithMessagesId,
63 '>=VALUE' => $idsUnseenCount
64 ]))
65 {
67 [
68 'MAILBOX_ID' => $mailboxId,
69 'ENTITY_TYPE' => 'DIR',
70 'ENTITY_ID' => $dirWithMessagesId
71 ],
72 [
73 "VALUE" => new \Bitrix\Main\DB\SqlExpression("?# - $idsUnseenCount", "VALUE")
74 ]
75 );
76 }
77 }
78 }
79
80 public static function getDirIdForMessages($mailboxId, $messagesIds)
81 {
82 $dirWithMessagesId = MailboxDirectoryTable::getList([
83 'runtime' => array(
84 new Main\ORM\Fields\Relations\Reference(
85 'UID',
86 'Bitrix\Mail\MailMessageUidTable',
87 [
88 '=this.DIR_MD5' => 'ref.DIR_MD5',
89 '=this.MAILBOX_ID' => 'ref.MAILBOX_ID',
90 ],
91 [
92 'join_type' => 'INNER',
93 ]
94 ),
95 ),
96 'select' => [
97 'ID',
98 ],
99 'filter' => [
100 '@UID.ID' => $messagesIds,
101 '=MAILBOX_ID' => $mailboxId,
102 ],
103 'limit' => 1,
104 ])->fetchAll();
105
106 if(isset($dirWithMessagesId[0]['ID']))
107 {
108 return $dirWithMessagesId[0]['ID'];
109 }
110 return false;
111 }
112
118 public static function getFolderNameByHash($messageFolderHash, $mailboxOptions)
119 {
120 $folderName = '';
121 if (!empty($mailboxOptions['imap']['dirsMd5']))
122 {
123 $names = array_filter(
124 $mailboxOptions['imap']['dirsMd5'],
125 function ($hash) use ($messageFolderHash)
126 {
127 return $hash == $messageFolderHash;
128 }
129 );
130 if (count($names) == 1)
131 {
132 $folderName = array_keys($names)[0];
133 }
134 }
135 return $folderName;
136 }
137
138 public static function getFolderHashByType($folderType, $mailboxOptions)
139 {
140 $folderHash = '';
141 if (!empty($mailboxOptions['imap']['dirsMd5']))
142 {
143 $name = static::getFolderNameByType($folderType, $mailboxOptions);
144 $hashes = array_filter(
145 $mailboxOptions['imap']['dirsMd5'],
146 function ($_name) use ($name)
147 {
148 return $_name == $name;
149 },
150 ARRAY_FILTER_USE_KEY
151 );
152 if (count($hashes) == 1)
153 {
154 $folderHash = array_values($hashes)[0];
155 }
156 }
157
158 return $folderHash;
159 }
160
161 public static function getFolderNameByType($folderType, $mailboxOptions)
162 {
163 if (!empty($mailboxOptions['imap']) && is_array($mailboxOptions['imap']))
164 {
165 $imapOptions = $mailboxOptions['imap'];
166 if (!empty($imapOptions[$folderType]) && isset($imapOptions[$folderType][0]))
167 {
168 return $imapOptions[$folderType][0];
169 }
170 }
171 return null;
172 }
173
174 public static function getDisabledFolders($mailboxOptions)
175 {
176 $disabled = empty($mailboxOptions['imap']['disabled']) ? [] : $mailboxOptions['imap']['disabled'];
177 $ignore = empty($mailboxOptions['imap']['ignore']) ? [] : $mailboxOptions['imap']['ignore'];
178 return array_merge($disabled, $ignore);
179 }
180
181 public static function isDisabledFolder($folder, $mailboxOptions)
182 {
183 return in_array($folder, static::getDisabledFolders($mailboxOptions), true);
184 }
185
186 public static function getFormattedPath(array $path, $mailboxOptions)
187 {
188 $root = array_shift($path);
189
190 if (mb_strtolower($root) == 'inbox' && !static::isDisabledFolder($root, $mailboxOptions))
191 {
192 $root = Loc::getMessage('MAIL_CLIENT_INBOX_ALIAS');
193 }
194
195 array_unshift($path, $root);
196
197 return $path;
198 }
199
200 public static function getFormattedName(array $path, $mailboxOptions, $full = true)
201 {
202 $path = static::getFormattedPath($path, $mailboxOptions);
203
204 return $full ? join(' / ', $path) : end($path);
205 }
206
207}
static getFolderNameByType($folderType, $mailboxOptions)
static getFolderHashByType($folderType, $mailboxOptions)
static getFormattedPath(array $path, $mailboxOptions)
static getDisabledFolders($mailboxOptions)
static isDisabledFolder($folder, $mailboxOptions)
static decreaseDirCounter($mailboxId, $dirWithMessagesId, $idsUnseenCount)
static getFormattedName(array $path, $mailboxOptions, $full=true)
static getFolderNameByHash($messageFolderHash, $mailboxOptions)
static getDirIdForMessages($mailboxId, $messagesIds)
static increaseDirCounter($mailboxId, $dirForMoveMessages=false, $dirForMoveMessagesId, $idsUnseenCount)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getCount($filter=array(), array $cache=array())
static update($primary, array $data)