summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/imapresource/imapresource.cpp15
-rw-r--r--examples/imapresource/imapserverproxy.cpp39
-rw-r--r--examples/imapresource/imapserverproxy.h13
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp24
4 files changed, 28 insertions, 63 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index 8422b49..c26dc39 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -220,10 +220,9 @@ public:
220 auto capabilities = imap->getCapabilities(); 220 auto capabilities = imap->getCapabilities();
221 bool canDoIncrementalRemovals = false; 221 bool canDoIncrementalRemovals = false;
222 return KAsync::start<void>([=]() { 222 return KAsync::start<void>([=]() {
223 auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong();
223 const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); 224 const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong();
224 // auto changedsince = QSharedPointer<qint64>::create(0); 225 return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const QVector<Message> &messages) {
225 //FIXME this should generate a compiletime error
226 return imap->fetchFlags(folder, changedsince, [this, folder](const QVector<Message> &messages) {
227 // synchronizeMails(folder.normalizedPath(), messages); 226 // synchronizeMails(folder.normalizedPath(), messages);
228 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8()); 227 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folder.normalizedPath().toUtf8());
229 for (const auto &message : messages) { 228 for (const auto &message : messages) {
@@ -266,11 +265,17 @@ public:
266 } 265 }
267 synchronizeMails(folder.normalizedPath(), messages); 266 synchronizeMails(folder.normalizedPath(), messages);
268 }, 267 },
269 [](int progress, int total) { 268 [this, maxUid, folder](int progress, int total) {
270 SinkTrace() << "Progress: " << progress << " out of " << total; 269 SinkLog() << "Progress: " << progress << " out of " << total;
270 //commit every 10 messages
271 if ((progress % 10) == 0) {
272 commit();
273 }
271 }) 274 })
272 .syncThen<void>([this, maxUid, folder]() { 275 .syncThen<void>([this, maxUid, folder]() {
273 syncStore().writeValue(folder.normalizedPath().toUtf8() + "uidnext", QByteArray::number(*maxUid)); 276 syncStore().writeValue(folder.normalizedPath().toUtf8() + "uidnext", QByteArray::number(*maxUid));
277 SinkLog() << "UIDMAX: " << *maxUid << folder.normalizedPath();
278 commit();
274 }); 279 });
275 }); 280 });
276 281
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 0f3524f..b14ebd2 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -257,13 +257,7 @@ KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::Fet
257 fetch->setSequenceSet(set); 257 fetch->setSequenceSet(set);
258 fetch->setUidBased(true); 258 fetch->setUidBased(true);
259 fetch->setScope(scope); 259 fetch->setScope(scope);
260 QObject::connect(fetch, static_cast<void(KIMAP2::FetchJob::*)(const QString &, 260 QObject::connect(fetch, &KIMAP2::FetchJob::resultReceived, callback);
261 const QMap<qint64,qint64> &,
262 const QMap<qint64,qint64> &,
263 const QMap<qint64,KIMAP2::MessageAttribute> &,
264 const QMap<qint64,KIMAP2::MessageFlags> &,
265 const QMap<qint64,KIMAP2::MessagePtr> &)>(&KIMAP2::FetchJob::headersReceived),
266 callback);
267 return runJob(fetch); 261 return runJob(fetch);
268} 262}
269 263
@@ -280,16 +274,9 @@ KAsync::Job<QVector<qint64>> ImapServerProxy::search(const KIMAP2::ImapSet &set)
280KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback) 274KAsync::Job<void> ImapServerProxy::fetch(const KIMAP2::ImapSet &set, KIMAP2::FetchJob::FetchScope scope, const std::function<void(const QVector<Message> &)> &callback)
281{ 275{
282 return fetch(set, scope, 276 return fetch(set, scope,
283 [callback](const QString &mailbox, 277 [callback](const KIMAP2::FetchJob::Result &result) {
284 const QMap<qint64,qint64> &uids,
285 const QMap<qint64,qint64> &sizes,
286 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
287 const QMap<qint64,KIMAP2::MessageFlags> &flags,
288 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
289 QVector<Message> list; 278 QVector<Message> list;
290 for (const auto &id : uids.keys()) { 279 list << Message{result.uid, result.size, result.attributes, result.flags, result.message};
291 list << Message{uids.value(id), sizes.value(id), attrs.value(id), flags.value(id), messages.value(id)};
292 }
293 callback(list); 280 callback(list);
294 }); 281 });
295} 282}
@@ -307,22 +294,13 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox,
307 294
308 //Fetch headers of all messages 295 //Fetch headers of all messages
309 return fetch(KIMAP2::ImapSet(minUid, 0), scope, 296 return fetch(KIMAP2::ImapSet(minUid, 0), scope,
310 [list](const QString &mailbox, 297 [list](const KIMAP2::FetchJob::Result &result) {
311 const QMap<qint64,qint64> &uids,
312 const QMap<qint64,qint64> &sizes,
313 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
314 const QMap<qint64,KIMAP2::MessageFlags> &flags,
315 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
316 SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
317 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
318 298
319 //TODO based on the data available here, figure out which messages to actually fetch 299 //TODO based on the data available here, figure out which messages to actually fetch
320 //(we only fetched headers and structure so far) 300 //(we only fetched headers and structure so far)
321 //We could i.e. build chunks to fetch based on the size 301 //We could i.e. build chunks to fetch based on the size
322 302
323 for (const auto &id : uids.keys()) { 303 list->append(result.uid);
324 list->append(uids.value(id));
325 }
326 }) 304 })
327 .syncThen<QList<qint64>>([list](){ 305 .syncThen<QList<qint64>>([list](){
328 return *list; 306 return *list;
@@ -416,7 +394,7 @@ QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const
416 return folder.pathParts.join(mPersonalNamespaceSeparator); 394 return folder.pathParts.join(mPersonalNamespaceSeparator);
417} 395}
418 396
419KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, qint64 changedsince, std::function<void(const QVector<Message> &)> callback) 397KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, const KIMAP2::ImapSet &set, qint64 changedsince, std::function<void(const QVector<Message> &)> callback)
420{ 398{
421 SinkTrace() << "Fetching flags " << folder.normalizedPath(); 399 SinkTrace() << "Fetching flags " << folder.normalizedPath();
422 return select(mailboxFromFolder(folder)).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> { 400 return select(mailboxFromFolder(folder)).then<SelectResult, SelectResult>([=](const SelectResult &selectResult) -> KAsync::Job<SelectResult> {
@@ -427,13 +405,13 @@ KAsync::Job<SelectResult> ImapServerProxy::fetchFlags(const Folder &folder, qint
427 return KAsync::value<SelectResult>(selectResult); 405 return KAsync::value<SelectResult>(selectResult);
428 } 406 }
429 407
430 SinkTrace() << "Fetching flags " << folder.normalizedPath() << selectResult.highestModSequence << changedsince; 408 SinkTrace() << "Fetching flags " << folder.normalizedPath() << set << selectResult.highestModSequence << changedsince;
431 409
432 KIMAP2::FetchJob::FetchScope scope; 410 KIMAP2::FetchJob::FetchScope scope;
433 scope.mode = KIMAP2::FetchJob::FetchScope::Flags; 411 scope.mode = KIMAP2::FetchJob::FetchScope::Flags;
434 scope.changedSince = changedsince; 412 scope.changedSince = changedsince;
435 413
436 return fetch(KIMAP2::ImapSet(1, 0), scope, callback).syncThen<SelectResult>([selectResult] { 414 return fetch(set, scope, callback).syncThen<SelectResult>([selectResult] {
437 return selectResult; 415 return selectResult;
438 }); 416 });
439 }); 417 });
@@ -451,6 +429,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui
451 return KAsync::null<void>(); 429 return KAsync::null<void>();
452 } 430 }
453 431
432 SinkTrace() << "Fetching messages from " << folder.normalizedPath() << selectResult.uidNext << uidNext;
454 return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress, folder](const QList<qint64> &uidsToFetch){ 433 return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress, folder](const QList<qint64> &uidsToFetch){
455 SinkTrace() << "Fetched headers" << folder.normalizedPath(); 434 SinkTrace() << "Fetched headers" << folder.normalizedPath();
456 SinkTrace() << " Total: " << uidsToFetch.size(); 435 SinkTrace() << " Total: " << uidsToFetch.size();
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h
index ff87d47..e0e87d4 100644
--- a/examples/imapresource/imapserverproxy.h
+++ b/examples/imapresource/imapserverproxy.h
@@ -51,8 +51,8 @@ namespace FolderFlags
51struct Message { 51struct Message {
52 qint64 uid; 52 qint64 uid;
53 qint64 size; 53 qint64 size;
54 QPair<QByteArray, QVariant> attributes; 54 KIMAP2::MessageAttributes attributes;
55 QList<QByteArray> flags; 55 KIMAP2::MessageFlags flags;
56 KMime::Message::Ptr msg; 56 KMime::Message::Ptr msg;
57}; 57};
58 58
@@ -111,12 +111,7 @@ public:
111 KAsync::Job<void> copy(const KIMAP2::ImapSet &set, const QString &newMailbox); 111 KAsync::Job<void> copy(const KIMAP2::ImapSet &set, const QString &newMailbox);
112 KAsync::Job<QVector<qint64>> search(const KIMAP2::ImapSet &set); 112 KAsync::Job<QVector<qint64>> search(const KIMAP2::ImapSet &set);
113 113
114 typedef std::function<void(const QString &, 114 typedef std::function<void(const KIMAP2::FetchJob::Result &)> FetchCallback;
115 const QMap<qint64,qint64> &,
116 const QMap<qint64,qint64> &,
117 const QMap<qint64,KIMAP2::MessageAttribute> &,
118 const QMap<qint64,KIMAP2::MessageFlags> &,
119 const QMap<qint64,KIMAP2::MessagePtr> &)> FetchCallback;
120 115
121 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);
122 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);
@@ -138,7 +133,7 @@ public:
138 KAsync::Job<void> fetchFolders(std::function<void(const QVector<Folder> &)> callback); 133 KAsync::Job<void> fetchFolders(std::function<void(const QVector<Folder> &)> callback);
139 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)>());
140 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)>());
141 KAsync::Job<SelectResult> fetchFlags(const Folder &folder, 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);
142 KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder); 137 KAsync::Job<QVector<qint64>> fetchUids(const Folder &folder);
143 138
144private: 139private:
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index 21c2248..1bd5982 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -12,7 +12,7 @@
12 12
13using namespace Imap; 13using namespace Imap;
14 14
15SINK_DEBUG_AREA("imapserverproxytest") 15// SINK_DEBUG_AREA("imapserverproxytest")
16 16
17/** 17/**
18 */ 18 */
@@ -77,15 +77,8 @@ private slots:
77 scope.mode = KIMAP2::FetchJob::FetchScope::Headers; 77 scope.mode = KIMAP2::FetchJob::FetchScope::Headers;
78 int count = 0; 78 int count = 0;
79 auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope, 79 auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope,
80 [&count](const QString &mailbox, 80 [&count](const KIMAP2::FetchJob::Result &) {
81 const QMap<qint64,qint64> &uids, 81 count++;
82 const QMap<qint64,qint64> &sizes,
83 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
84 const QMap<qint64,KIMAP2::MessageFlags> &flags,
85 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
86 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
87 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
88 count += uids.size();
89 })); 82 }));
90 83
91 VERIFYEXEC(job); 84 VERIFYEXEC(job);
@@ -102,15 +95,8 @@ private slots:
102 scope.mode = KIMAP2::FetchJob::FetchScope::Headers; 95 scope.mode = KIMAP2::FetchJob::FetchScope::Headers;
103 int count = 0; 96 int count = 0;
104 auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope, 97 auto job = imap.select("INBOX.test").then<void>(imap.fetch(KIMAP2::ImapSet::fromImapSequenceSet("1:*"), scope,
105 [&count](const QString &mailbox, 98 [&count](const KIMAP2::FetchJob::Result &) {
106 const QMap<qint64,qint64> &uids, 99 count++;
107 const QMap<qint64,qint64> &sizes,
108 const QMap<qint64,KIMAP2::MessageAttribute> &attrs,
109 const QMap<qint64,KIMAP2::MessageFlags> &flags,
110 const QMap<qint64,KIMAP2::MessagePtr> &messages) {
111 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
112 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
113 count += uids.size();
114 })); 100 }));
115 101
116 VERIFYEXEC(job); 102 VERIFYEXEC(job);