Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync only subscribed folders, if set in config. #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sync/config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
; This contains the default configuration used through the application.
; To extend any of these settings, edit the local.ini file in the same
; directory as this file.
; mandatory_sync_folders: for multiple folders use comma
; to separate them like "INBOX,Outbox"
; =====================================================================

[app]
Expand All @@ -13,6 +15,8 @@ db[sleep_minutes] = 1
sync[wait_seconds] = 10
sync[sleep_minutes] = 15
timezone = "America/New_York"
sync_only_subscribed_folders = false
mandatory_sync_folders = 'INBOX'

[log]

Expand Down
19 changes: 18 additions & 1 deletion sync/src/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use App\Exceptions\MessagesSync as MessagesSyncException;
use App\Traits\GarbageCollection as GarbageCollectionTrait;
use App\Exceptions\MissingIMAPConfig as MissingIMAPConfigException;
use Zend\Mail\Storage\Exception\InvalidArgumentException;

class Sync
{
Expand Down Expand Up @@ -574,7 +575,23 @@ private function syncFolders(AccountModel $account)
$this->emitter,
$this->interactive
);
$folderList = $this->mailbox->getFolders();
$mandatorySyncFolders = explode(",", $this->config['app']['mandatory_sync_folders']);
if (boolval($this->config['app']['sync_only_subscribed_folders'])) {
$folderList = new \AppendIterator();
$folderList->append($this->mailbox->getFolders(null, true));
if (count($mandatorySyncFolders) > 0) {
foreach ($mandatorySyncFolders as $folderName) {
try {
$folderList->append($this->mailbox->getFolders($folderName));
} catch (InvalidArgumentException $e) {
$this->log->notice('Mandatory folder '.$folderName.' from config does not exists'.
' in account '.$account->email);
}
}
}
} else {
$folderList = $this->mailbox->getFolders(null);
}
$savedFolders = (new FolderModel)->getByAccount($account->getId());
$folderSync->run($folderList, $savedFolders, $account);
} catch (PDOException $e) {
Expand Down