- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/helper/mailbox/imap.php
- Класс: BitrixMailHelperMailboxImap
- Вызов: Imap::syncMailbox
public function syncMailbox()
{
if (!$this->client->authenticate($error))
{
return false;
}
$syncReport = [
'syncCount'=>0,
'reSyncCount' => 0,
'reSyncStatus' => false,
];
$this->cacheDirs();
$currentDir = null;
if (!empty($this->syncParams['currentDir']))
{
$currentDir = $this->syncParams['currentDir'];
}
$dirsSync = $this->getDirsHelper()->getSyncDirsOrderByTime($currentDir);
if (empty($dirsSync))
{
return $syncReport;
}
$lastDir = $this->getDirsHelper()->getLastSyncDirByDefault($currentDir);
foreach ($dirsSync as $item)
{
MailboxDirectoryHelper::setCurrentSyncDir($item->getPath());
$syncReport['syncCount'] += $this->syncDir($item->getPath());
if ($this->isTimeQuotaExceeded())
{
break;
}
MailboxDirectory::updateSyncTime($item->getId(), time());
if ($lastDir != null && $item->getPath() == $lastDir->getPath())
{
MailboxDirectoryHelper::setCurrentSyncDir('');
break;
}
}
$this->setLastSyncResult(['updatedMessages' => 0, 'deletedMessages' => 0]);
if (!$this->isTimeQuotaExceeded())
{
/* Mark emails from unsynchronized folders (unchecked) for deletion
It is impossible to check these filters for the legality of deleting messages,
since:
1) messages do not disappear from the original mailbox
2) messages that fall under filters are in different folders,
and the check goes through one folder.
*/
$result = $this->unregisterMessages([
'!@DIR_MD5' => array_map(
'md5',
$this->getDirsHelper()->getSyncDirsPath(true)
),
],
[
'info' => 'disabled directory synchronization in Bitrix',
],
true);
$countDeleted = $result ? $result->getCount() : 0;
$this->lastSyncResult['deletedMessages'] += $countDeleted;
$successfulReSyncCount = 0;
if (!empty($this->syncParams['full']))
{
foreach ($dirsSync as $item)
{
$reSyncReport = $this->resyncDir($item->getPath());
if($reSyncReport['complete'])
{
$syncReport['reSyncCount']++;
}
if ($this->isTimeQuotaExceeded())
{
break;
}
}
if($syncReport['reSyncCount'] === count($dirsSync))
{
$syncReport['reSyncStatus'] = true;
}
}
}
return $syncReport;
}