diff options
-rw-r--r-- | examples/imapresource/imapresource.cpp | 19 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 11 | ||||
-rw-r--r-- | examples/imapresource/imapserverproxy.h | 51 |
3 files changed, 57 insertions, 24 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 302d681..d3949ae 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -119,7 +119,7 @@ public: | |||
119 | [&folderList](const QByteArray &remoteId) -> bool { | 119 | [&folderList](const QByteArray &remoteId) -> bool { |
120 | // folderList.contains(remoteId) | 120 | // folderList.contains(remoteId) |
121 | for (const auto &folderPath : folderList) { | 121 | for (const auto &folderPath : folderList) { |
122 | if (folderPath.path == remoteId) { | 122 | if (folderPath.path() == remoteId) { |
123 | return true; | 123 | return true; |
124 | } | 124 | } |
125 | } | 125 | } |
@@ -128,7 +128,7 @@ public: | |||
128 | ); | 128 | ); |
129 | 129 | ||
130 | for (const auto &f : folderList) { | 130 | for (const auto &f : folderList) { |
131 | createFolder(f.pathParts.last(), f.path, f.parentPath(), "folder"); | 131 | createFolder(f.name(), f.path(), f.parentPath(), "folder"); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
@@ -190,12 +190,12 @@ public: | |||
190 | KAsync::Job<void> synchronizeFolder(QSharedPointer<ImapServerProxy> imap, const Imap::Folder &folder) | 190 | KAsync::Job<void> synchronizeFolder(QSharedPointer<ImapServerProxy> imap, const Imap::Folder &folder) |
191 | { | 191 | { |
192 | QSet<qint64> uids; | 192 | QSet<qint64> uids; |
193 | SinkLog() << "Synchronizing mails" << folder.normalizedPath(); | 193 | SinkLog() << "Synchronizing mails" << folder.path(); |
194 | auto capabilities = imap->getCapabilities(); | 194 | auto capabilities = imap->getCapabilities(); |
195 | bool canDoIncrementalRemovals = false; | 195 | bool canDoIncrementalRemovals = false; |
196 | return KAsync::start<void>([=]() { | 196 | return KAsync::start<void>([=]() { |
197 | //First we fetch flag changes for all messages. Since we don't know which messages are locally available we just get everything and only apply to what we have. | 197 | //First we fetch flag changes for all messages. Since we don't know which messages are locally available we just get everything and only apply to what we have. |
198 | SinkLog() << "About to update flags" << folder.normalizedPath(); | 198 | SinkLog() << "About to update flags" << folder.path(); |
199 | auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); | 199 | auto uidNext = syncStore().readValue(folder.normalizedPath().toUtf8() + "uidnext").toLongLong(); |
200 | const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); | 200 | const auto changedsince = syncStore().readValue(folder.normalizedPath().toUtf8() + "changedsince").toLongLong(); |
201 | return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const Message &message) { | 201 | return imap->fetchFlags(folder, KIMAP2::ImapSet(1, qMax(uidNext, qint64(1))), changedsince, [this, folder](const Message &message) { |
@@ -361,7 +361,10 @@ public: | |||
361 | if (folder.noselect) { | 361 | if (folder.noselect) { |
362 | return KAsync::null<void>(); | 362 | return KAsync::null<void>(); |
363 | } | 363 | } |
364 | return synchronizeFolder(imap, folder); | 364 | return synchronizeFolder(imap, folder) |
365 | .onError([folder](const KAsync::Error &error) { | ||
366 | SinkWarning() << "Failed to sync folder: ." << folder.normalizedPath(); | ||
367 | }); | ||
365 | }); | 368 | }); |
366 | 369 | ||
367 | return job; | 370 | return job; |
@@ -492,8 +495,8 @@ public: | |||
492 | auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); | 495 | auto specialPurposeFolders = QSharedPointer<QHash<QByteArray, QString>>::create(); |
493 | auto mergeJob = imap->login(mUser, mPassword) | 496 | auto mergeJob = imap->login(mUser, mPassword) |
494 | .then<void>(imap->fetchFolders([=](const Imap::Folder &folder) { | 497 | .then<void>(imap->fetchFolders([=](const Imap::Folder &folder) { |
495 | if (SpecialPurpose::isSpecialPurposeFolderName(folder.pathParts.last())) { | 498 | if (SpecialPurpose::isSpecialPurposeFolderName(folder.name())) { |
496 | specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.pathParts.last()), folder.path); | 499 | specialPurposeFolders->insert(SpecialPurpose::getSpecialPurposeType(folder.name()), folder.path()); |
497 | }; | 500 | }; |
498 | })) | 501 | })) |
499 | .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { | 502 | .then<void>([specialPurposeFolders, folder, imap, parentFolder, rid]() -> KAsync::Job<void> { |
@@ -707,7 +710,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in | |||
707 | auto inspectionJob = imap->login(mUser, mPassword) | 710 | auto inspectionJob = imap->login(mUser, mPassword) |
708 | .then<void>(imap->fetchFolders([=](const Imap::Folder &f) { | 711 | .then<void>(imap->fetchFolders([=](const Imap::Folder &f) { |
709 | *folderByPath << f.normalizedPath(); | 712 | *folderByPath << f.normalizedPath(); |
710 | *folderByName << f.pathParts.last(); | 713 | *folderByName << f.name(); |
711 | })) | 714 | })) |
712 | .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() { | 715 | .then<void>([this, folderByName, folderByPath, folder, remoteId, imap]() { |
713 | if (!folderByName->contains(folder.getName())) { | 716 | if (!folderByName->contains(folder.getName())) { |
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 56ddf89..d6f0c7f 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -157,6 +157,8 @@ KAsync::Job<SelectResult> ImapServerProxy::select(const QString &mailbox) | |||
157 | select->setCondstoreEnabled(mCapabilities.contains("CONDSTORE")); | 157 | select->setCondstoreEnabled(mCapabilities.contains("CONDSTORE")); |
158 | return runJob<SelectResult>(select, [select](KJob* job) -> SelectResult { | 158 | return runJob<SelectResult>(select, [select](KJob* job) -> SelectResult { |
159 | return {select->uidValidity(), select->nextUid(), select->highestModSequence()}; | 159 | return {select->uidValidity(), select->nextUid(), select->highestModSequence()}; |
160 | }).onError([=] (const KAsync::Error &error) { | ||
161 | SinkWarning() << "Select failed: " << mailbox; | ||
160 | }); | 162 | }); |
161 | } | 163 | } |
162 | 164 | ||
@@ -388,17 +390,16 @@ KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder | |||
388 | return list(KIMAP2::ListJob::IncludeUnsubscribed, [callback](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags){ | 390 | return list(KIMAP2::ListJob::IncludeUnsubscribed, [callback](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags){ |
389 | bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect)); | 391 | bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect)); |
390 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect; | 392 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect; |
391 | callback(Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect}); | 393 | callback(Folder{mailbox.name, mailbox.separator, noselect}); |
392 | }); | 394 | }); |
393 | } | 395 | } |
394 | 396 | ||
395 | QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const | 397 | QString ImapServerProxy::mailboxFromFolder(const Folder &folder) const |
396 | { | 398 | { |
397 | if (folder.path.isEmpty()) { | 399 | if (folder.path().isEmpty()) { |
398 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 400 | return folder.path(mPersonalNamespaceSeparator); |
399 | return folder.pathParts.join(mPersonalNamespaceSeparator); | ||
400 | } else { | 401 | } else { |
401 | return folder.path; | 402 | return folder.path(); |
402 | } | 403 | } |
403 | } | 404 | } |
404 | 405 | ||
diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index 6e6626e..22527c0 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h | |||
@@ -59,35 +59,64 @@ struct Message { | |||
59 | 59 | ||
60 | struct Folder { | 60 | struct Folder { |
61 | Folder() = default; | 61 | Folder() = default; |
62 | Folder(QList<QString> pathParts_, const QString &path_, const QChar &separator_, bool noselect_) | 62 | Folder(const QString &path, const QChar &separator, bool noselect_) |
63 | : pathParts(pathParts_), | 63 | : noselect(noselect_), |
64 | path(path_), | 64 | mPath(path), |
65 | separator(separator_), | 65 | pathParts(path.split(separator)), |
66 | noselect(noselect_) | 66 | mSeparator(separator) |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | Folder(const QString &path_) | 70 | Folder(const QString &path_) |
71 | : path(path_) | 71 | : mPath(path_) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | QString normalizedPath() const | 75 | QString normalizedPath() const |
76 | { | 76 | { |
77 | return pathParts.join('/'); | 77 | return path('/'); |
78 | } | ||
79 | |||
80 | QString path(const QChar &s) const | ||
81 | { | ||
82 | Q_ASSERT(!s.isNull()); | ||
83 | return pathParts.join(s); | ||
84 | } | ||
85 | |||
86 | QString path() const | ||
87 | { | ||
88 | Q_ASSERT(!mPath.isEmpty()); | ||
89 | return mPath; | ||
78 | } | 90 | } |
79 | 91 | ||
80 | QString parentPath() const | 92 | QString parentPath() const |
81 | { | 93 | { |
94 | Q_ASSERT(!mSeparator.isNull()); | ||
82 | auto parts = pathParts; | 95 | auto parts = pathParts; |
83 | parts.removeLast(); | 96 | parts.removeLast(); |
84 | return parts.join(separator); | 97 | return parts.join(mSeparator); |
98 | } | ||
99 | |||
100 | QString normalizedParentPath() const | ||
101 | { | ||
102 | Q_ASSERT(!pathParts.isEmpty()); | ||
103 | auto parts = pathParts; | ||
104 | parts.removeLast(); | ||
105 | return parts.join('/'); | ||
106 | } | ||
107 | |||
108 | QString name() const | ||
109 | { | ||
110 | Q_ASSERT(!pathParts.isEmpty()); | ||
111 | return pathParts.last(); | ||
85 | } | 112 | } |
86 | 113 | ||
87 | QList<QString> pathParts; | ||
88 | QString path; | ||
89 | QChar separator; | ||
90 | bool noselect = false; | 114 | bool noselect = false; |
115 | |||
116 | private: | ||
117 | QString mPath; | ||
118 | QList<QString> pathParts; | ||
119 | QChar mSeparator; | ||
91 | }; | 120 | }; |
92 | 121 | ||
93 | struct SelectResult { | 122 | struct SelectResult { |