Commit c64be582 authored by flypig's avatar flypig

Merge branch 'jb50162' into 'master'

Apply folder sync policy

See merge request !43
parents 2c7fc208 75956287
From 63e8766f65da2d5ff98333b61b8a433583dc967f Mon Sep 17 00:00:00 2001
From: David Llewellyn-Jones <david.llewellyn-jones@jolla.com>
Date: Tue, 14 Jul 2020 14:58:40 +0000
Subject: [PATCH] Apply folder policy to always on connection
Changes the configuration so that the push folders are generated from
the the policy and folder flags, rather than a separate configuration
setting.
---
src/libraries/qmfclient/qmailaccount.cpp | 51 +++++++++++++++++++
src/libraries/qmfclient/qmailaccount.h | 2 +
.../imap/imapconfiguration.cpp | 18 ++++++-
3 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/src/libraries/qmfclient/qmailaccount.cpp b/src/libraries/qmfclient/qmailaccount.cpp
index 5163e370..12445ff4 100644
--- a/src/libraries/qmfclient/qmailaccount.cpp
+++ b/src/libraries/qmfclient/qmailaccount.cpp
@@ -790,3 +790,54 @@ void QMailAccount::setFolderSyncPolicy(QMailAccount::FolderSyncPolicy policy)
{
d->_folderSyncPolicy = policy;
}
+
+const QList<QMailFolderId> QMailAccount::foldersToSync() const
+{
+ QList<QMailFolderId> folders;
+ QMailFolderKey filterKey(QMailFolderKey::parentAccountId(d->_id));
+ QMailFolderId inbox;
+ if ((d->_folderSyncPolicy == QMailAccount::SyncInboxOnly)
+ || (d->_folderSyncPolicy == QMailAccount::SyncInboxAndSubfolders)) {
+ // Find the inbox if we're going to need it
+ inbox = standardFolder(QMailFolder::InboxFolder);
+ }
+
+ switch (d->_folderSyncPolicy) {
+ default:
+ case QMailAccount::SyncInboxOnly:
+ folders << inbox;
+ break;
+ case QMailAccount::SyncInboxAndSubfolders: {
+ // Add only folders with the inbox in their ancestry
+ QMailFolderIdList folderIds = QMailStore::instance()->queryFolders(filterKey, QMailFolderSortKey::id(Qt::AscendingOrder));
+ for (QMailFolderId folderId : folderIds) {
+ bool result = false;
+ QMailFolderId checkId = folderId;
+ while (!result && checkId.isValid()) {
+ if (checkId == inbox) {
+ folders << folderId;
+ result = true;
+ }
+ else {
+ checkId = QMailFolder(checkId).parentFolderId();
+ }
+ }
+ }
+ }
+ break;
+ case QMailAccount::SyncSelectedFolders:
+ filterKey &= QMailFolderKey(QMailFolderKey::status(QMailFolder::SynchronizationEnabled));
+ // Fallthrough
+ case QMailAccount::SyncEverything:
+ QMailFolderIdList folderIds = QMailStore::instance()->queryFolders(filterKey, QMailFolderSortKey::id(Qt::AscendingOrder));
+ for (QMailFolderId folderId : folderIds) {
+ if (folderId.isValid()) {
+ folders << folderId;
+ }
+ }
+ break;
+ }
+
+ return folders;
+}
+
diff --git a/src/libraries/qmfclient/qmailaccount.h b/src/libraries/qmfclient/qmailaccount.h
index 933cfa0c..9ee1a6ce 100644
--- a/src/libraries/qmfclient/qmailaccount.h
+++ b/src/libraries/qmfclient/qmailaccount.h
@@ -145,6 +145,8 @@ public:
const QMap<QString, QString> &customFields() const;
+ const QList<QMailFolderId> foldersToSync() const;
+
private:
friend class QMailAccountPrivate;
friend class QMailStore;
diff --git a/src/plugins/messageservices/imap/imapconfiguration.cpp b/src/plugins/messageservices/imap/imapconfiguration.cpp
index 07289a1c..28c4a491 100644
--- a/src/plugins/messageservices/imap/imapconfiguration.cpp
+++ b/src/plugins/messageservices/imap/imapconfiguration.cpp
@@ -31,6 +31,8 @@
**
****************************************************************************/
+#include "qmailaccount.h"
+
#include "imapconfiguration.h"
#include <QStringList>
@@ -112,7 +114,21 @@ QString ImapConfiguration::baseFolder() const
QStringList ImapConfiguration::pushFolders() const
{
- return value("pushFolders").split(QChar('\x0A'), QString::SkipEmptyParts);
+ QStringList result;
+ const QMailAccountId id = this->id();
+
+ if (!id.isValid()) {
+ return value("pushFolders").split(QChar('\x0A'), QString::SkipEmptyParts);
+ }
+
+ const QList<QMailFolderId> folders = QMailAccount(id).foldersToSync();
+
+ // Convert to folder paths
+ for (QMailFolderId folderId : folders) {
+ result << QMailFolder(folderId).path();
+ }
+
+ return result;
}
int ImapConfiguration::checkInterval() const
--
2.26.2
......@@ -52,6 +52,8 @@ Patch19: 0019-Use-EightBit-encoding-instead-of-Base64-for-text-typ.patch
Patch20: 0020-Follow-the-synchronizationEnabled-flag-when-folders.patch
Patch21: 0021-Set-new-IMAP-folders-to-inherit-SynchronizationEnab.patch
Patch22: 0022-Set-qmf-accountscheck-to-be-run-by-the-booster.patch
Patch23: 0023-Retrieve-message-lists-based-on-the-folder-sync-poli.patch
Patch24: 0024-Apply-folder-policy-to-always-on-connection.patch
%description
The Qt Messaging Framework, QMF, consists of a C++ library and daemon server
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment