Skip to content

Commit

Permalink
Merge branch 'folders' into 'master'
Browse files Browse the repository at this point in the history
[buteo-sync-plugins-email] Call for folder synchronization other than inbox according to policy.

See merge request mer-core/buteo-sync-plugins-email!3
  • Loading branch information
pvuorela committed Nov 26, 2019
2 parents 085831b + b979e82 commit 1af8837
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/syncemailclient.cpp
Expand Up @@ -57,6 +57,20 @@ SyncEmailClient::~SyncEmailClient()
{
}

static bool isAncestorFolder(const QMailFolder &folder, const QMailFolderId &ancestor)
{
if (folder.status() & QMailFolder::NonMail) {
return false;
}
QMailFolderId parentId = folder.parentFolderId();
if (!parentId.isValid()) {
return false;
} else {
return parentId == ancestor
|| isAncestorFolder(QMailFolder(parentId), ancestor);
}
}

bool SyncEmailClient::init()
{
m_accountId = QMailAccountId(profile().key(Buteo::KEY_ACCOUNT_ID).toInt());
Expand All @@ -65,6 +79,37 @@ bool SyncEmailClient::init()
return false;
}

Accounts::Manager accountManager;
Accounts::Account *account = accountManager.account(m_accountId.toULongLong());
if (account) {
account->selectService(accountManager.service(QStringLiteral("email")));
m_folderSyncPolicy = account->valueAsString(QStringLiteral("folderSyncPolicy"));
bool all = m_folderSyncPolicy.compare(QStringLiteral("all-folders"));
if (all || m_folderSyncPolicy.compare(QStringLiteral("inbox-and-subfolders"))) {
// Ensure that synchronization flag is set
// for inbox and subfolders or for all.
QMailAccount account(m_accountId);
QMailFolderId inboxId = account.standardFolder(QMailFolder::InboxFolder);
if (inboxId.isValid()) {
QMailFolderKey key = QMailFolderKey::parentAccountId(m_accountId);
QList<QMailFolderId> folders = QMailStore::instance()->queryFolders(key);
for (QList<QMailFolderId>::ConstIterator it = folders.constBegin();
it != folders.constEnd(); ++it) {
if (it->isValid()) {
QMailFolder folder(*it);
folder.setStatus(QMailFolder::SynchronizationEnabled,
all || *it == inboxId
|| isAncestorFolder(folder, inboxId));
}
}
} else {
qWarning() << Q_FUNC_INFO << "Email account has no inbox.";
// This will trigger inbox creation in email agent.
m_folderSyncPolicy = QStringLiteral("inbox");
}
}
}

// if messageserver is not running, EmailAgent will attempt to start it via systemd
m_emailAgent = new EmailAgent(this);
connect(m_emailAgent, SIGNAL(ipcConnectionEstablished()), this, SLOT(ipcConnected()));
Expand Down Expand Up @@ -143,7 +188,12 @@ void SyncEmailClient::triggerSync()

connect(m_emailAgent, SIGNAL(synchronizingChanged()), this, SLOT(syncStatusChanged()));
connect(m_emailAgent, SIGNAL(networkConnectionRequested()), this, SLOT(cancelSync()));
m_emailAgent->syncAccounts(QMailAccountIdList() << m_accountId);
if (m_folderSyncPolicy.isEmpty()
|| m_folderSyncPolicy.compare(QStringLiteral("inbox"))) {
m_emailAgent->synchronizeInbox(m_accountId.toULongLong());
} else {
m_emailAgent->synchronize(m_accountId.toULongLong());
}
}

void SyncEmailClient::updateResults(const Buteo::SyncResults &results)
Expand Down
1 change: 1 addition & 0 deletions src/syncemailclient.h
Expand Up @@ -74,6 +74,7 @@ private slots:
Buteo::SyncResults m_syncResults;
EmailAgent *m_emailAgent;
QMailAccountId m_accountId;
QString m_folderSyncPolicy;
QTimer m_ipcTimeout;

void updateResults(const Buteo::SyncResults &results);
Expand Down

0 comments on commit 1af8837

Please sign in to comment.