diff options
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 35 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 1 |
2 files changed, 34 insertions, 2 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 5c2e07c..16887b1 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <KIMAP2/ExpungeJob> | 31 | #include <KIMAP2/ExpungeJob> |
32 | #include <KIMAP2/CapabilitiesJob> | 32 | #include <KIMAP2/CapabilitiesJob> |
33 | #include <KIMAP2/SearchJob> | 33 | #include <KIMAP2/SearchJob> |
34 | #include <KIMAP2/GetMetaDataJob> | ||
34 | 35 | ||
35 | #include <KCoreAddons/KJob> | 36 | #include <KCoreAddons/KJob> |
36 | 37 | ||
@@ -479,14 +480,33 @@ static void reportFolder(const Folder &f, QSharedPointer<QSet<QString>> reported | |||
479 | } | 480 | } |
480 | } | 481 | } |
481 | 482 | ||
483 | KAsync::Job<void> ImapServerProxy::getMetaData(std::function<void(const QHash<QString, QMap<QByteArray, QByteArray> > &metadata)> callback) | ||
484 | { | ||
485 | if (!mCapabilities.contains("METADATA")) { | ||
486 | return KAsync::null(); | ||
487 | } | ||
488 | KIMAP2::GetMetaDataJob *meta = new KIMAP2::GetMetaDataJob(mSession); | ||
489 | meta->setMailBox(QLatin1String("*")); | ||
490 | meta->setServerCapability( KIMAP2::MetaDataJobBase::Metadata ); | ||
491 | meta->setDepth(KIMAP2::GetMetaDataJob::AllLevels); | ||
492 | meta->addRequestedEntry("/shared/vendor/kolab/folder-type"); | ||
493 | meta->addRequestedEntry("/private/vendor/kolab/folder-type"); | ||
494 | return runJob(meta).then<void>([callback, meta] () { | ||
495 | callback(meta->allMetaDataForMailboxes()); | ||
496 | }); | ||
497 | } | ||
498 | |||
482 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) | 499 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) |
483 | { | 500 | { |
484 | SinkTrace() << "Fetching folders"; | 501 | SinkTrace() << "Fetching folders"; |
485 | auto subscribedList = QSharedPointer<QSet<QString>>::create() ; | 502 | auto subscribedList = QSharedPointer<QSet<QString>>::create() ; |
486 | auto reportedList = QSharedPointer<QSet<QString>>::create() ; | 503 | auto reportedList = QSharedPointer<QSet<QString>>::create() ; |
487 | return list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){ | 504 | auto metaData = QSharedPointer<QHash<QString, QMap<QByteArray, QByteArray>>>::create() ; |
505 | return getMetaData([=] (const QHash<QString, QMap<QByteArray, QByteArray>> &m) { | ||
506 | *metaData = m; | ||
507 | }).then(list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){ | ||
488 | *subscribedList << mailbox.name; | 508 | *subscribedList << mailbox.name; |
489 | }).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) { | 509 | })).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) { |
490 | bool noselect = caseInsensitiveContains(FolderFlags::Noselect, flags); | 510 | bool noselect = caseInsensitiveContains(FolderFlags::Noselect, flags); |
491 | bool subscribed = subscribedList->contains(mailbox.name); | 511 | bool subscribed = subscribedList->contains(mailbox.name); |
492 | if (isGmail()) { | 512 | if (isGmail()) { |
@@ -502,6 +522,17 @@ KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder | |||
502 | } | 522 | } |
503 | } | 523 | } |
504 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; | 524 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; |
525 | //Ignore all non-mail folders | ||
526 | if (metaData->contains(mailbox.name)) { | ||
527 | auto m = metaData->value(mailbox.name); | ||
528 | auto sharedType = m.value("/shared/vendor/kolab/folder-type"); | ||
529 | auto privateType = m.value("/private/vendor/kolab/folder-type"); | ||
530 | auto type = !privateType.isEmpty() ? privateType : sharedType; | ||
531 | if (!type.isEmpty() && !type.contains("mail")) { | ||
532 | SinkLog() << "Skipping due to folder type: " << type; | ||
533 | return; | ||
534 | } | ||
535 | } | ||
505 | auto ns = getNamespace(mailbox.name); | 536 | auto ns = getNamespace(mailbox.name); |
506 | auto folder = Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}; | 537 | auto folder = Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}; |
507 | 538 | ||
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index f9b854b..86e3378 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -294,6 +294,7 @@ public: | |||
294 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); | 294 | KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); |
295 | 295 | ||
296 | private: | 296 | private: |
297 | KAsync::Job<void> getMetaData(std::function<void(const QHash<QString, QMap<QByteArray, QByteArray> > &metadata)> callback); | ||
297 | bool isGmail() const; | 298 | bool isGmail() const; |
298 | 299 | ||
299 | QString getNamespace(const QString &name); | 300 | QString getNamespace(const QString &name); |