summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapserverproxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r--examples/imapresource/imapserverproxy.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 08a0081..d3ad2d4 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -457,10 +457,23 @@ bool Imap::flagsContain(const QByteArray &f, const QByteArrayList &flags)
457 return caseInsensitiveContains(f, flags); 457 return caseInsensitiveContains(f, flags);
458} 458}
459 459
460static void reportFolder(const Folder &f, QSharedPointer<QSet<QString>> reportedList, std::function<void(const Folder &)> callback) {
461 if (!reportedList->contains(f.path())) {
462 reportedList->insert(f.path());
463 auto c = f;
464 c.noselect = true;
465 callback(c);
466 if (!f.parentPath().isEmpty()){
467 reportFolder(f.parentFolder(), reportedList, callback);
468 }
469 }
470}
471
460KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) 472KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback)
461{ 473{
462 SinkTrace() << "Fetching folders"; 474 SinkTrace() << "Fetching folders";
463 auto subscribedList = QSharedPointer<QSet<QString>>::create() ; 475 auto subscribedList = QSharedPointer<QSet<QString>>::create() ;
476 auto reportedList = QSharedPointer<QSet<QString>>::create() ;
464 return list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){ 477 return list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){
465 *subscribedList << mailbox.name; 478 *subscribedList << mailbox.name;
466 }).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) { 479 }).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) {
@@ -471,17 +484,24 @@ KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder
471 bool sent = caseInsensitiveContains(FolderFlags::Sent, flags); 484 bool sent = caseInsensitiveContains(FolderFlags::Sent, flags);
472 bool drafts = caseInsensitiveContains(FolderFlags::Drafts, flags); 485 bool drafts = caseInsensitiveContains(FolderFlags::Drafts, flags);
473 bool trash = caseInsensitiveContains(FolderFlags::Trash, flags); 486 bool trash = caseInsensitiveContains(FolderFlags::Trash, flags);
474 bool isgmailParent = mailbox.name.toLower() == "[gmail]" || mailbox.name.toLower() == "[Google Mail]";
475 /** 487 /**
476 * Because gmail duplicates messages all over the place we only support a few selected folders for now that should be mostly exclusive. 488 * Because gmail duplicates messages all over the place we only support a few selected folders for now that should be mostly exclusive.
477 */ 489 */
478 if (!(inbox || sent || drafts || trash || isgmailParent)) { 490 if (!(inbox || sent || drafts || trash)) {
479 return; 491 return;
480 } 492 }
481 } 493 }
482 SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; 494 SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed;
483 auto ns = getNamespace(mailbox.name); 495 auto ns = getNamespace(mailbox.name);
484 callback(Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}); 496 auto folder = Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags};
497
498 //call callback for parents if that didn't already happen.
499 //This is necessary because we can have missing bits in the hierarchy in IMAP, but this will not work in sink because we'd end up with an incomplete tree.
500 if (!folder.parentPath().isEmpty() && !reportedList->contains(folder.parentPath())) {
501 reportFolder(folder.parentFolder(), reportedList, callback);
502 }
503 reportedList->insert(folder.path());
504 callback(folder);
485 })); 505 }));
486} 506}
487 507