diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-13 14:39:57 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-13 14:39:57 +0200 |
commit | 82ca7ebb9c24fef6f1860eeca9577d998af03c7f (patch) | |
tree | b3e43325ccf1d315f351424e178cac1fbd7e9933 /examples/maildirresource/maildirresource.cpp | |
parent | 29cca3919ed373c486c3c9acec32481918baeb58 (diff) | |
download | sink-82ca7ebb9c24fef6f1860eeca9577d998af03c7f.tar.gz sink-82ca7ebb9c24fef6f1860eeca9577d998af03c7f.zip |
Implemented maildir mail moves and got it to pass tests again
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 9800f7f..05441b0 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -139,10 +139,30 @@ public: | |||
139 | const auto path = getPath(folder, transaction); | 139 | const auto path = getPath(folder, transaction); |
140 | KPIM::Maildir maildir(path, false); | 140 | KPIM::Maildir maildir(path, false); |
141 | if (!maildir.isValid(true)) { | 141 | if (!maildir.isValid(true)) { |
142 | qWarning() << "Maildir is not existing: " << path; | 142 | Warning() << "Maildir is not existing: " << path; |
143 | } | 143 | } |
144 | auto identifier = maildir.addEntryFromPath(oldPath); | 144 | auto identifier = maildir.addEntryFromPath(oldPath); |
145 | return path + "/" + identifier; | 145 | return path + "/" + identifier; |
146 | } else { | ||
147 | //Handle moves | ||
148 | const auto path = getPath(folder, transaction); | ||
149 | KPIM::Maildir maildir(path, false); | ||
150 | if (!maildir.isValid(true)) { | ||
151 | Warning() << "Maildir is not existing: " << path; | ||
152 | } | ||
153 | auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath); | ||
154 | auto pathParts = oldPath.split('/'); | ||
155 | pathParts.takeLast(); | ||
156 | auto oldDirectory = pathParts.join('/'); | ||
157 | if (oldDirectory == path) { | ||
158 | return oldPath; | ||
159 | } | ||
160 | KPIM::Maildir oldMaildir(oldDirectory, false); | ||
161 | if (!oldMaildir.isValid(false)) { | ||
162 | Warning() << "Maildir is not existing: " << path; | ||
163 | } | ||
164 | auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir); | ||
165 | return path + "/" + identifier; | ||
146 | } | 166 | } |
147 | return oldPath; | 167 | return oldPath; |
148 | } | 168 | } |
@@ -161,21 +181,29 @@ public: | |||
161 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 181 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, |
162 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 182 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
163 | { | 183 | { |
164 | //TODO deal with moves | 184 | if (newEntity.getProperty("draft").toBool()) { |
185 | newEntity.setProperty("folder", mDraftsFolder); | ||
186 | } | ||
165 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 187 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
166 | if (mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString()) { | 188 | const auto newFolder = newEntity.getProperty("folder"); |
167 | //Remove the olde mime message if there is a new one | 189 | const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); |
168 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 190 | const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); |
169 | QFile::remove(filePath); | 191 | if (mimeMessageChanged || folderChanged) { |
170 | 192 | Trace() << "Moving mime message: " << mimeMessageChanged << folderChanged; | |
171 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); | 193 | auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); |
172 | Trace() << "Modified message: " << filePath << oldEntity.getProperty("mimeMessage").toString(); | 194 | if (newPath != oldEntity.getProperty("mimeMessage").toString()) { |
195 | const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | ||
196 | newEntity.setProperty("mimeMessage", newPath); | ||
197 | //Remove the olde mime message if there is a new one | ||
198 | QFile::remove(oldPath); | ||
199 | } | ||
173 | } | 200 | } |
174 | 201 | ||
175 | auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); | 202 | auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); |
176 | const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray(), transaction); | 203 | const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray(), transaction); |
177 | KPIM::Maildir maildir(maildirPath, false); | 204 | KPIM::Maildir maildir(maildirPath, false); |
178 | QString identifier = KPIM::Maildir::getKeyFromFile(mimeMessagePath); | 205 | const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); |
206 | QString identifier = KPIM::Maildir::getKeyFromFile(file); | ||
179 | 207 | ||
180 | //get flags from | 208 | //get flags from |
181 | KPIM::Maildir::Flags flags; | 209 | KPIM::Maildir::Flags flags; |
@@ -247,14 +275,17 @@ public: | |||
247 | return list; | 275 | return list; |
248 | } | 276 | } |
249 | 277 | ||
250 | QByteArray createFolder(const QString &folderPath, const QByteArray &icon) | 278 | QByteArray createFolder(const QString &folderPath, const QByteArray &icon, const QByteArrayList &specialpurpose = QByteArrayList()) |
251 | { | 279 | { |
252 | auto remoteId = folderPath.toUtf8(); | 280 | auto remoteId = folderPath.toUtf8(); |
253 | auto bufferType = ENTITY_TYPE_FOLDER; | 281 | auto bufferType = ENTITY_TYPE_FOLDER; |
254 | KPIM::Maildir md(folderPath, folderPath == mMaildirPath); | 282 | KPIM::Maildir md(folderPath, folderPath == mMaildirPath); |
255 | Sink::ApplicationDomain::Folder folder; | 283 | Sink::ApplicationDomain::Folder folder; |
256 | folder.setProperty("name", md.name()); | 284 | folder.setName(md.name()); |
257 | folder.setProperty("icon", icon); | 285 | folder.setIcon(icon); |
286 | if (!specialpurpose.isEmpty()) { | ||
287 | folder.setSpecialPurpose(specialpurpose); | ||
288 | } | ||
258 | 289 | ||
259 | if (!md.isRoot()) { | 290 | if (!md.isRoot()) { |
260 | folder.setProperty("parent", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8())); | 291 | folder.setProperty("parent", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8())); |
@@ -478,10 +509,10 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh | |||
478 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << folderPreprocessor << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); | 509 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << folderPreprocessor << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); |
479 | 510 | ||
480 | KPIM::Maildir dir(mMaildirPath, true); | 511 | KPIM::Maildir dir(mMaildirPath, true); |
481 | mDraftsFolder = dir.addSubFolder("drafts"); | ||
482 | Trace() << "Started maildir resource for maildir: " << mMaildirPath; | 512 | Trace() << "Started maildir resource for maildir: " << mMaildirPath; |
513 | mDraftsFolder = dir.addSubFolder("Drafts"); | ||
483 | 514 | ||
484 | auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder"); | 515 | auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder", QByteArrayList() << "drafts"); |
485 | auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); | 516 | auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); |
486 | synchronizer->commit(); | 517 | synchronizer->commit(); |
487 | synchronizer->commitSync(); | 518 | synchronizer->commitSync(); |