summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/imapresource/imapresource.cpp28
-rw-r--r--examples/imapresource/imapserverproxy.cpp22
-rw-r--r--examples/imapresource/imapserverproxy.h4
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp4
4 files changed, 25 insertions, 33 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index c26dc39..63ae07b 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -298,15 +298,15 @@ public:
298 .then<QVector<Folder>>([this, imap]() { 298 .then<QVector<Folder>>([this, imap]() {
299 auto folderList = QSharedPointer<QVector<Folder>>::create(); 299 auto folderList = QSharedPointer<QVector<Folder>>::create();
300 SinkLog() << "Login was successful"; 300 SinkLog() << "Login was successful";
301 return imap->fetchFolders([this, &imap, folderList](const QVector<Folder> &folders) { 301 return imap->fetchFolders([folderList](const Folder &folder) {
302 synchronizeFolders(folders); 302 *folderList << folder;
303 commit();
304 *folderList << folders;
305 }) 303 })
306 .onError([](const KAsync::Error &error) { 304 .onError([](const KAsync::Error &error) {
307 SinkWarning() << "Folder list sync failed."; 305 SinkWarning() << "Folder list sync failed.";
308 }) 306 })
309 .syncThen<QVector<Folder>>([folderList]() { 307 .syncThen<QVector<Folder>>([this, folderList]() {
308 synchronizeFolders(*folderList);
309 commit();
310 return *folderList; 310 return *folderList;
311 }); 311 });
312 }) 312 })
@@ -440,12 +440,10 @@ public:
440 } else { //We try to merge special purpose folders first 440 } else { //We try to merge special purpose folders first
441 auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); 441 auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create();
442 auto mergeJob = imap->login(mUser, mPassword) 442 auto mergeJob = imap->login(mUser, mPassword)
443 .then<void>(imap->fetchFolders([=](const QVector<Imap::Folder> &folders) { 443 .then<void>(imap->fetchFolders([=](const Imap::Folder &folder) {
444 for (const auto &f : folders) { 444 if (SpecialPurpose::isSpecialPurposeFolderName(folder.pathParts.last())) {
445 if (SpecialPurpose::isSpecialPurposeFolderName(f.pathParts.last())) { 445 specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.pathParts.last()), folder.path);
446 specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(f.pathParts.last()), f.path); 446 };
447 };
448 }
449 })) 447 }))
450 .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { 448 .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> {
451 for (const auto &purpose : folder.getSpecialPurpose()) { 449 for (const auto &purpose : folder.getSpecialPurpose()) {
@@ -661,11 +659,9 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
661 659
662 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); 660 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort);
663 auto inspectionJob = imap->login(mUser, mPassword) 661 auto inspectionJob = imap->login(mUser, mPassword)
664 .then<void>(imap->fetchFolders([=](const QVector<Imap::Folder> &folders) { 662 .then<void>(imap->fetchFolders([=](const Imap::Folder &f) {
665 for (const auto &f : folders) { 663 *folderByPath << f.normalizedPath();
666 *folderByPath << f.normalizedPath(); 664 *folderByName << f.pathParts.last();
667 *folderByName << f.pathParts.last();
668 }
669 })) 665 }))
670 .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() { 666 .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() {
671 if (!folderByName->contains(folder.getName())) { 667 if (!folderByName->contains(folder.getName())) {
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index b14ebd2..a75825e 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -295,6 +295,8 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox,
295 //Fetch headers of all messages 295 //Fetch headers of all messages
296 return fetch(KIMAP2::ImapSet(minUid, 0), scope, 296 return fetch(KIMAP2::ImapSet(minUid, 0), scope,
297 [list](const KIMAP2::FetchJob::Result &result) { 297 [list](const KIMAP2::FetchJob::Result &result) {
298 // SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
299 // SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
298 300
299 //TODO based on the data available here, figure out which messages to actually fetch 301 //TODO based on the data available here, figure out which messages to actually fetch
300 //(we only fetched headers and structure so far) 302 //(we only fetched headers and structure so far)
@@ -312,12 +314,12 @@ KAsync::Job<QVector<qint64>> ImapServerProxy::fetchUids(const QString &mailbox)
312 return select(mailbox).then<QVector<qint64>>(search(KIMAP2::ImapSet(1, 0))); 314 return select(mailbox).then<QVector<qint64>>(search(KIMAP2::ImapSet(1, 0)));
313} 315}
314 316
315KAsync::Job<void> ImapServerProxy::list(KIMAP2::ListJob::Option option, const std::function<void(const QList<KIMAP2::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback) 317KAsync::Job<void> ImapServerProxy::list(KIMAP2::ListJob::Option option, const std::function<void(const KIMAP2::MailBoxDescriptor &mailboxes, const QList<QByteArray> &flags)> &callback)
316{ 318{
317 auto listJob = new KIMAP2::ListJob(mSession); 319 auto listJob = new KIMAP2::ListJob(mSession);
318 listJob->setOption(option); 320 listJob->setOption(option);
319 // listJob->setQueriedNamespaces(serverNamespaces()); 321 // listJob->setQueriedNamespaces(serverNamespaces());
320 QObject::connect(listJob, &KIMAP2::ListJob::mailBoxesReceived, 322 QObject::connect(listJob, &KIMAP2::ListJob::resultReceived,
321 listJob, callback); 323 listJob, callback);
322 return runJob(listJob); 324 return runJob(listJob);
323} 325}
@@ -372,19 +374,13 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
372 }); 374 });
373} 375}
374 376
375KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) 377KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback)
376{ 378{
377 SinkTrace() << "Fetching folders"; 379 SinkTrace() << "Fetching folders";
378 return list(KIMAP2::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP2::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ 380 return list(KIMAP2::ListJob::IncludeUnsubscribed, [callback](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags){
379 QVector<Folder> list; 381 bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect));
380 for (int i = 0; i < mailboxes.size(); i++) { 382 SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect;
381 const auto mailbox = mailboxes[i]; 383 callback(Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect});
382 const auto mailboxFlags = flags[i];
383 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect));
384 SinkLog() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect;
385 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect};
386 }
387 callback(list);
388 }); 384 });
389} 385}
390 386
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h
index e0e87d4..452b479 100644
--- a/examples/imapresource/imapserverproxy.h
+++ b/examples/imapresource/imapserverproxy.h
@@ -115,7 +115,7 @@ public:
115 115
116 KAsync::Job<void> fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, FetchCallback callback); 116 KAsync::Job<void> fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, FetchCallback callback);
117 KAsync::Job<void> fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback); 117 KAsync::Job<void> fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback);
118 KAsync::Job<void> list(KIMAP2::ListJob::Option option, const std::function<void(const QList<KIMAP2::MailBoxDescriptor> &mailboxes,const QList<QList<QByteArray> > &flags)> &callback); 118 KAsync::Job<void> list(KIMAP2::ListJob::Option option, const std::function<void(const KIMAP2::MailBoxDescriptor &mailboxes,const QList<QByteArray> &flags)> &callback);
119 119
120 QStringList getCapabilities() const; 120 QStringList getCapabilities() const;
121 121
@@ -130,7 +130,7 @@ public:
130 130
131 QString mailboxFromFolder(const Folder &) const; 131 QString mailboxFromFolder(const Folder &) const;
132 132
133 KAsync::Job<void> fetchFolders(std::function<void(const QVector<Folder> &)> callback); 133 KAsync::Job<void> fetchFolders(std::function<void(const Folder &)> callback);
134 KAsync::Job<void> fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); 134 KAsync::Job<void> fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>());
135 KAsync::Job<void> fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>()); 135 KAsync::Job<void> fetchMessages(const Folder &folder, qint64 uidNext, std::function<void(const QVector<Message> &)> callback, std::function<void(int, int)> progress = std::function<void(int, int)>());
136 KAsync::Job<SelectResult> fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const QVector<Message> &)> callback); 136 KAsync::Job<SelectResult> fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const QVector<Message> &)> callback);
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index 1bd5982..27d73ea 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -59,13 +59,13 @@ private slots:
59 { 59 {
60 ImapServerProxy imap("localhost", 993); 60 ImapServerProxy imap("localhost", 993);
61 VERIFYEXEC(imap.login("doe", "doe")); 61 VERIFYEXEC(imap.login("doe", "doe"));
62 VERIFYEXEC(imap.fetchFolders([](const QVector<Folder> &){})); 62 VERIFYEXEC(imap.fetchFolders([](const Folder &){}));
63 } 63 }
64 64
65 void testFetchFoldersFailure() 65 void testFetchFoldersFailure()
66 { 66 {
67 ImapServerProxy imap("foobar", 993); 67 ImapServerProxy imap("foobar", 993);
68 VERIFYEXEC_FAIL(imap.fetchFolders([](const QVector<Folder> &){})); 68 VERIFYEXEC_FAIL(imap.fetchFolders([](const Folder &){}));
69 } 69 }
70 70
71 void testFetchMail() 71 void testFetchMail()