diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-22 18:35:52 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-22 18:35:52 +0100 |
commit | b05edd5644738e7608d13a8b5b679f43d70f4dd4 (patch) | |
tree | 9ac59a67057da63564d59ecc3f896b21bcacd322 | |
parent | e513ee41adb6061aa72de8bfe49d117f47c1545b (diff) | |
download | sink-b05edd5644738e7608d13a8b5b679f43d70f4dd4.tar.gz sink-b05edd5644738e7608d13a8b5b679f43d70f4dd4.zip |
Don't treat the IMAP namespace as subfolder.
INBOX.INBOX means that the INBOX folder is in the INBOX. namespace.
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 43 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 17 | ||||
-rw-r--r-- | examples/imapresource/tests/imapserverproxytest.cpp | 14 |
3 files changed, 57 insertions, 17 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index a98483b..d5c212d 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -370,16 +370,16 @@ KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailb | |||
370 | { | 370 | { |
371 | return KAsync::start<QString>([this, parentMailbox, folderName]() { | 371 | return KAsync::start<QString>([this, parentMailbox, folderName]() { |
372 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 372 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
373 | auto folder = QSharedPointer<QString>::create(); | 373 | QString folder; |
374 | if (parentMailbox.isEmpty()) { | 374 | if (parentMailbox.isEmpty()) { |
375 | *folder = mPersonalNamespaces.toList().first() + folderName; | 375 | folder = mPersonalNamespaces.isEmpty() ? "" : mPersonalNamespaces.toList().first() + folderName; |
376 | } else { | 376 | } else { |
377 | *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; | 377 | folder = parentMailbox + mPersonalNamespaceSeparator + folderName; |
378 | } | 378 | } |
379 | SinkTrace() << "Creating subfolder: " << *folder; | 379 | SinkTrace() << "Creating subfolder: " << folder; |
380 | return create(*folder) | 380 | return create(folder) |
381 | .then([=]() { | 381 | .then([=]() { |
382 | return *folder; | 382 | return folder; |
383 | }); | 383 | }); |
384 | }); | 384 | }); |
385 | } | 385 | } |
@@ -390,15 +390,35 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox, | |||
390 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 390 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
391 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); | 391 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); |
392 | parts.removeLast(); | 392 | parts.removeLast(); |
393 | auto folder = QSharedPointer<QString>::create(parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName); | 393 | QString folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; |
394 | SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; | 394 | SinkTrace() << "Renaming subfolder: " << oldMailbox << folder; |
395 | return rename(oldMailbox, *folder) | 395 | return rename(oldMailbox, folder) |
396 | .then([=]() { | 396 | .then([=]() { |
397 | return *folder; | 397 | return folder; |
398 | }); | 398 | }); |
399 | }); | 399 | }); |
400 | } | 400 | } |
401 | 401 | ||
402 | QString ImapServerProxy::getNamespace(const QString &name) | ||
403 | { | ||
404 | for (const auto &ns : mPersonalNamespaces) { | ||
405 | if (name.startsWith(ns)) { | ||
406 | return ns; | ||
407 | } | ||
408 | } | ||
409 | for (const auto &ns : mSharedNamespaces) { | ||
410 | if (name.startsWith(ns)) { | ||
411 | return ns; | ||
412 | } | ||
413 | } | ||
414 | for (const auto &ns : mUserNamespaces) { | ||
415 | if (name.startsWith(ns)) { | ||
416 | return ns; | ||
417 | } | ||
418 | } | ||
419 | return QString{}; | ||
420 | } | ||
421 | |||
402 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) | 422 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) |
403 | { | 423 | { |
404 | SinkTrace() << "Fetching folders"; | 424 | SinkTrace() << "Fetching folders"; |
@@ -409,7 +429,8 @@ KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder | |||
409 | bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect)); | 429 | bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect)); |
410 | bool subscribed = subscribedList->contains(mailbox.name); | 430 | bool subscribed = subscribedList->contains(mailbox.name); |
411 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; | 431 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; |
412 | callback(Folder{mailbox.name, mailbox.separator, noselect, subscribed, flags}); | 432 | auto ns = getNamespace(mailbox.name); |
433 | callback(Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}); | ||
413 | })); | 434 | })); |
414 | } | 435 | } |
415 | 436 | ||
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 2175ca1..6785fc2 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -67,12 +67,12 @@ struct Message { | |||
67 | 67 | ||
68 | struct Folder { | 68 | struct Folder { |
69 | Folder() = default; | 69 | Folder() = default; |
70 | Folder(const QString &path, const QChar &separator, bool noselect_, bool subscribed_, const QByteArrayList &flags_) | 70 | Folder(const QString &path, const QString &ns, const QChar &separator, bool noselect_, bool subscribed_, const QByteArrayList &flags_) |
71 | : noselect(noselect_), | 71 | : noselect(noselect_), |
72 | subscribed(subscribed_), | 72 | subscribed(subscribed_), |
73 | flags(flags_), | 73 | flags(flags_), |
74 | mPath(path), | 74 | mPath(path), |
75 | pathParts(path.split(separator)), | 75 | mNamespace(ns), |
76 | mSeparator(separator) | 76 | mSeparator(separator) |
77 | { | 77 | { |
78 | } | 78 | } |
@@ -91,13 +91,19 @@ struct Folder { | |||
91 | QString parentPath() const | 91 | QString parentPath() const |
92 | { | 92 | { |
93 | Q_ASSERT(!mSeparator.isNull()); | 93 | Q_ASSERT(!mSeparator.isNull()); |
94 | auto parts = pathParts; | 94 | auto parts = mPath.split(mSeparator); |
95 | parts.removeLast(); | 95 | parts.removeLast(); |
96 | return parts.join(mSeparator); | 96 | auto parentPath = parts.join(mSeparator); |
97 | //Don't return the namespace for root folders as parent folder | ||
98 | if (mNamespace.startsWith(parentPath)) { | ||
99 | return QString{}; | ||
100 | } | ||
101 | return parentPath; | ||
97 | } | 102 | } |
98 | 103 | ||
99 | QString name() const | 104 | QString name() const |
100 | { | 105 | { |
106 | auto pathParts = mPath.split(mSeparator); | ||
101 | Q_ASSERT(!pathParts.isEmpty()); | 107 | Q_ASSERT(!pathParts.isEmpty()); |
102 | return pathParts.last(); | 108 | return pathParts.last(); |
103 | } | 109 | } |
@@ -108,7 +114,7 @@ struct Folder { | |||
108 | 114 | ||
109 | private: | 115 | private: |
110 | QString mPath; | 116 | QString mPath; |
111 | QList<QString> pathParts; | 117 | QString mNamespace; |
112 | QChar mSeparator; | 118 | QChar mSeparator; |
113 | }; | 119 | }; |
114 | 120 | ||
@@ -178,6 +184,7 @@ public: | |||
178 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); | 184 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); |
179 | 185 | ||
180 | private: | 186 | private: |
187 | QString getNamespace(const QString &name); | ||
181 | QObject mGuard; | 188 | QObject mGuard; |
182 | }; | 189 | }; |
183 | 190 | ||
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index 27d73ea..ec5df49 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp | |||
@@ -57,9 +57,21 @@ private slots: | |||
57 | 57 | ||
58 | void testFetchFolders() | 58 | void testFetchFolders() |
59 | { | 59 | { |
60 | QMap<QString, QString> expectedFolderAndParent; | ||
61 | expectedFolderAndParent.insert("INBOX", ""); | ||
62 | expectedFolderAndParent.insert("Drafts", ""); | ||
63 | expectedFolderAndParent.insert("Trash", ""); | ||
64 | expectedFolderAndParent.insert("test", ""); | ||
60 | ImapServerProxy imap("localhost", 993); | 65 | ImapServerProxy imap("localhost", 993); |
61 | VERIFYEXEC(imap.login("doe", "doe")); | 66 | VERIFYEXEC(imap.login("doe", "doe")); |
62 | VERIFYEXEC(imap.fetchFolders([](const Folder &){})); | 67 | QVector<Folder> list; |
68 | VERIFYEXEC(imap.fetchFolders([&](const Folder &f){ list << f;})); | ||
69 | for (const auto &f : list) { | ||
70 | QVERIFY(expectedFolderAndParent.contains(f.name())); | ||
71 | QCOMPARE(expectedFolderAndParent.value(f.name()), f.parentPath()); | ||
72 | expectedFolderAndParent.remove(f.name()); | ||
73 | } | ||
74 | QVERIFY(expectedFolderAndParent.isEmpty()); | ||
63 | } | 75 | } |
64 | 76 | ||
65 | void testFetchFoldersFailure() | 77 | void testFetchFoldersFailure() |