13 private $mailboxId =
null;
14 private $storage =
null;
20 $this->mailboxId = $mailboxId;
27 return $this->storage->get(
'all', []);
32 $this->storage->set($dirs);
37 $this->storage->init();
47 $list = $this->storage->get(
'draft', []);
54 $list = $this->storage->get(
'income', []);
61 $list = $this->storage->get(
'outcome', []);
68 $list = $this->storage->get(
'spam', []);
75 $list = $this->storage->get(
'trash', []);
86 return $dir->getPath($emojiEncode);
98 return $dir->getPath($emojiEncode);
110 return $dir->getPath($emojiEncode);
122 return $dir->getPath($emojiEncode);
134 return $dir->getPath($emojiEncode);
142 $dir = $this->storage->getByHash($hash);
146 return $dir->getPath();
154 $dir = $this->storage->getByHash($hash);
168 case MailboxDirectoryTable::TYPE_INCOME:
171 case MailboxDirectoryTable::TYPE_OUTCOME:
174 case MailboxDirectoryTable::TYPE_SPAM:
177 case MailboxDirectoryTable::TYPE_TRASH:
192 $dir = $this->storage->getByPath($path);
204 return array_filter($this->
getDirs(),
function ($item)
206 return $item->isSync();
212 return array_filter($this->orderByTime($this->
getSyncDirs()),
function ($item) use ($excludeDirPath)
214 return $item->getPath() !== $excludeDirPath;
222 foreach ($this->
getDirs() as $item)
226 $list[] = $item->getPath($emojiEncode);
237 foreach ($this->
getDirs() as $item)
239 if ((
int)$item->getLevel() === 1)
241 $list[$item->getPath()] = $item;
248 private function orderByDefault($dirs)
250 usort($dirs,
function ($a, $b)
255 if ($aSort === $bSort)
260 return $aSort > $bSort ? 1 : -1;
268 return $dir->isIncome() ? 10 : ($dir->isOutcome() ? 2000 : ($dir->isTrash() ? 3000 : ($dir->isSpam() ? 4000 : ($dir->isDraft() ? 5000 : $dir->getLevel() * 100))));
271 private function orderByName($dirs)
273 usort($dirs,
function ($a, $b)
275 $aSort = $a->getName();
276 $bSort = $b->getName();
298 if ($aSort === $bSort)
303 return $aSort > $bSort ? 1 : -1;
309 private function orderByTime($dirs)
311 usort($dirs,
function ($a, $b)
313 $aSort = $a->getSyncTime() ?: ($a->isIncome() ? 100 : ($a->isOutcome() ? 200 : ($a->isTrash() ? 300 : ($a->isSpam() ? 400 : $a->getLevel() * 1000))));
314 $bSort = $b->getSyncTime() ?: ($b->isIncome() ? 100 : ($b->isOutcome() ? 200 : ($b->isTrash() ? 300 : ($b->isSpam() ? 400 : $b->getLevel() * 1000))));
316 if ($aSort === $bSort)
321 return $aSort > $bSort ? 1 : -1;
329 $list = $this->orderByDefault($this->
getSyncDirs());
330 $list = array_filter($list,
function ($item) use ($excludeDirPath)
332 return $item->getPath() !== $excludeDirPath;
347 $list = $this->orderByDefault($this->
getSyncDirs());
348 $list = array_filter($list,
function ($item) use ($excludeDirPath)
350 return $item->getPath() !== $excludeDirPath;
353 $getIndex =
function ($list, $path)
355 foreach ($list as $index => $item)
357 if ($item->getPath() === $path)
366 return $getIndex($list, $path);
373 foreach ($dirs as $item)
376 '=PATH' => $item->getPath(
true),
380 '%=PATH' => $item->getPath(
true) . $item->getDelimiter() .
'%',
384 if (!empty($removeRows))
386 $removeRows = array_merge([
'LOGIC' =>
'OR'], $removeRows);
388 $filter = array_merge([
390 '=MAILBOX_ID' => $this->mailboxId,
403 foreach ([$inboxDir, $sendDir] as $dir)
405 if ($dir !=
null && !$dir->isDisabled() && $dir->isSync())
411 foreach ($dirs as $dir)
413 if (!$dir->isDisabled() && $dir->isSync())
428 return $dir->getPath($emojiEncode);
440 foreach ($dirs as $dir)
442 $list[$dir->getId()] = $dir;
445 foreach ($list as $id => $dir)
447 if (!empty($list[$dir->getParentId()]))
449 $list[$dir->getParentId()]->addChild($dir);
453 $result[$dir->getId()] = $dir;
457 return $this->orderByDefault($result);
462 $pattern = sprintf(
'%s%s%%', $parent->getPath(), $parent->getDelimiter());
464 $dirs = $mailboxHelper->listDirs($pattern);
468 $this->errors = $mailboxHelper->getErrors();
476 'level' => $parent->getLevel() + 1,
477 'parent_id' => $parent->getId(),
478 'root_id' => $parent->getRootId() ?: $parent->getId(),
479 'is_sync' => MailboxDirectoryTable::INACTIVE,
482 $dirs = array_map(
function ($item) use ($params)
484 return array_merge($item, $params);
503 $parent->getLevel() + 1
511 $parent->getPath(
true) . $parent->getDelimiter() .
'%',
512 $parent->getLevel() + 1
518 $diffDirs = array_diff_key($dirs, $dbDirs);
520 $addRows = array_map(
523 if (!isset($dir[
'is_sync']))
525 $dir[
'is_sync'] = !preg_grep(
'/^ \x5c ( Drafts | Trash | Junk | Spam ) $/ix', $dir[
'flags']);
529 'MAILBOX_ID' => $this->mailboxId,
530 'NAME' => Emoji::encode($dir[
'name']),
531 'PATH' => Emoji::encode($dir[
'path']),
532 'LEVEL' => isset($dir[
'level']) ? $dir[
'level'] : 1,
533 'PARENT_ID' => isset($dir[
'parent_id']) ? $dir[
'parent_id'] :
null,
534 'ROOT_ID' => isset($dir[
'root_id']) ? $dir[
'root_id'] :
null,
536 'DELIMITER' => $dir[
'delim'],
537 'DIR_MD5' => md5(Emoji::encode($dir[
'path'])),
538 'IS_SYNC' => $dir[
'is_sync'],
539 'IS_INCOME' => mb_strtoupper($dir[
'name']) ===
'INBOX',
540 'IS_OUTCOME' => preg_grep(
'/^ \x5c Sent $/ix', $dir[
'flags']),
541 'IS_DRAFT' => preg_grep(
'/^ \x5c Drafts $/ix', $dir[
'flags']),
542 'IS_TRASH' => preg_grep(
'/^ \x5c Trash $/ix', $dir[
'flags']),
543 'IS_SPAM' => preg_grep(
'/^ \x5c ( Junk | Spam ) $/ix', $dir[
'flags']),
544 'IS_DISABLED' => preg_grep(
'/^ \x5c Noselect $/ix', $dir[
'flags']),
550 if (!empty($addRows))
558 $updateRows = array_udiff_assoc($dirs, $dbDirs,
function ($a, $b)
561 $flagsB = $b->getFlags();
563 $delimA = $a[
'delim'];
564 $delimB = $b->getDelimiter();
566 if ($flagsA !== $flagsB)
568 return $flagsA > $flagsB ? 1 : -1;
570 else if ($delimA !== $delimB)
572 return $delimA > $delimB ? 1 : -1;
578 foreach ($updateRows as $row)
580 $dbDir = $this->
getDirByPath(Emoji::encode($row[
'path']));
590 'DELIMITER' => $row[
'delim'],
599 $diffDirs = array_diff_key($dbDirs, $dirs);
601 if (!empty($diffDirs))
612 foreach ($dirs as $dir)
614 $hash = isset($dir[
'dirMd5']) ? $dir[
'dirMd5'] :
null;
615 $value = isset($dir[
'value']) ? intval($dir[
'value']) : 0;
617 if (!$hash || !in_array($value, [MailboxDirectoryTable::ACTIVE, MailboxDirectoryTable::INACTIVE]))
622 if ($value === MailboxDirectoryTable::ACTIVE)
624 $enableRows[] = $hash;
628 $disableRows[] = $hash;
632 if (!empty($enableRows))
637 if (!empty($disableRows))
643 $mailboxHelper->activateSync();
648 foreach ($dirs as $dir)
650 $type = !empty($dir[
'type']) ? $dir[
'type'] :
null;
651 $hash = !empty($dir[
'dirMd5']) ? $dir[
'dirMd5'] :
null;
667 $type => MailboxDirectoryTable::ACTIVE
693 MailboxDirectoryTable::TYPE_OUTCOME,
694 MailboxDirectoryTable::TYPE_TRASH,
695 MailboxDirectoryTable::TYPE_SPAM
709 return implode(
' ', $flags);
714 return (
int)\Bitrix\Main\Config\Option::get(
'mail',
'maxLevelDirs', 20);
719 \Bitrix\Main\Config\Option::set(
'mail',
'maxLevelDirs', $val);
724 return \Bitrix\Main\Config\Option::get(
'mail',
'currentSyncDir',
'');
729 \Bitrix\Main\Config\Option::set(
'mail',
'currentSyncDir', $path);
static getFlags(array $flags)
getOutcomePath($emojiEncode=false)
static getCurrentSyncDir()
updateSyncDirs($dirs, $dbDirs)
getDraftsPath($emojiEncode=false)
getLastSyncDirByDefault($excludeDirPath=null)
getSpamPath($emojiEncode=false)
getDefaultDirPath($emojiEncode=false)
removeDirsLikePath(array $dirs)
getIncomePath($emojiEncode=false)
removeSyncDirs($dirs, $dbDirs)
addSyncDirs($dirs, $dbDirs)
updateMessageCount($id, $count)
static isDirsTypes($name)
getSyncDirsOrderByTime($excludeDirPath=null)
getAllLevelByParentId($parent)
getDirByPath(?string $path)
static setMaxLevelDirs(int $val)
getTrashPath($emojiEncode=false)
getCurrentSyncDirByTime()
static setCurrentSyncDir(string $path)
getOneLevelByParentId($parent)
getCurrentSyncDirPositionByDefault(string $path, $excludeDirPath=null)
getSyncDirsPath($emojiEncode=false)
static createInstance($id, $throw=true)
static fetchAllLevelByParentId($mailboxId, $path, $level)
static deleteList(array $filter)
static resetDirsTypes($mailboxId, $type)
static updateMessageCount($id, $val)
static addMulti($rows, $ignoreEvents=false)
static fetchOneLevelByParentId($mailboxId, $id, $level)
static updateSyncDirs(array $values, $val, $mailboxId)
static update($id, $data)
static fetchOneByMailboxIdAndHash($mailboxId, $hash)
if(!function_exists(__NAMESPACE__.'\\___1034172934'))