summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/maildirresource/libmaildir/maildir.cpp13
-rw-r--r--examples/maildirresource/libmaildir/maildir.h5
-rw-r--r--examples/maildirresource/maildirresource.cpp5
-rw-r--r--tests/maildirresourcetest.cpp4
4 files changed, 24 insertions, 3 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp
index 59e7e5c..8d6de3e 100644
--- a/examples/maildirresource/libmaildir/maildir.cpp
+++ b/examples/maildirresource/libmaildir/maildir.cpp
@@ -22,6 +22,7 @@
22 22
23#include <QDateTime> 23#include <QDateTime>
24#include <QDir> 24#include <QDir>
25#include <QDirIterator>
25#include <QFileInfo> 26#include <QFileInfo>
26#include <QHostInfo> 27#include <QHostInfo>
27#include <QUuid> 28#include <QUuid>
@@ -566,6 +567,18 @@ QDateTime Maildir::lastModified(const QString& key) const
566 return info.lastModified(); 567 return info.lastModified();
567} 568}
568 569
570void Maildir::importNewMails()
571{
572 QDirIterator entryIterator(pathToNew(), QDir::Files);
573 while (entryIterator.hasNext()) {
574 const QString filePath = QDir::fromNativeSeparators(entryIterator.next());
575 QFile file(filePath);
576 if (!file.rename(pathToCurrent() +"/" + entryIterator.fileName())) {
577 qWarning() << "Failed to rename the file: " << file.errorString();
578 }
579 }
580}
581
569QString Maildir::getKeyFromFile(const QString& file) 582QString Maildir::getKeyFromFile(const QString& file)
570{ 583{
571 return Maildir::Private::stripFlags(file.split('/').last()); 584 return Maildir::Private::stripFlags(file.split('/').last());
diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h
index 6c68656..31778ac 100644
--- a/examples/maildirresource/libmaildir/maildir.h
+++ b/examples/maildirresource/libmaildir/maildir.h
@@ -163,6 +163,11 @@ public:
163 QDateTime lastModified( const QString &key ) const; 163 QDateTime lastModified( const QString &key ) const;
164 164
165 /** 165 /**
166 * Move all mails in new to cur
167 */
168 void importNewMails();
169
170 /**
166 * Return the contents of the file in the maildir with the given @p key. 171 * Return the contents of the file in the maildir with the given @p key.
167 */ 172 */
168 QByteArray readEntry( const QString& key ) const; 173 QByteArray readEntry( const QString& key ) const;
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 05fcbb6..839b427 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -145,6 +145,9 @@ void MaildirResource::synchronizeMails(Sink::Storage::Transaction &transaction,
145 return; 145 return;
146 } 146 }
147 147
148 Trace() << "Importing new mail.";
149 maildir.importNewMails();
150
148 auto listingPath = maildir.pathToCurrent(); 151 auto listingPath = maildir.pathToCurrent();
149 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files); 152 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files);
150 Trace() << "Looking into " << listingPath; 153 Trace() << "Looking into " << listingPath;
@@ -199,7 +202,7 @@ void MaildirResource::synchronizeMails(Sink::Storage::Transaction &transaction,
199 } 202 }
200 mSynchronizerQueue.commit(); 203 mSynchronizerQueue.commit();
201 const auto elapsed = time->elapsed(); 204 const auto elapsed = time->elapsed();
202 Trace() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 205 Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
203 206
204} 207}
205 208
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index 28a1d44..eefe1e9 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -205,7 +205,7 @@ private Q_SLOTS:
205 205
206 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 206 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
207 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 207 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
208 QCOMPARE(mailModel->rowCount(QModelIndex()), 2); 208 QCOMPARE(mailModel->rowCount(QModelIndex()), 3);
209 } 209 }
210 210
211 void testSyncMailRemoval() 211 void testSyncMailRemoval()
@@ -228,7 +228,7 @@ private Q_SLOTS:
228 228
229 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 229 auto mailModel = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
230 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 230 QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
231 QCOMPARE(mailModel->rowCount(QModelIndex()), 1); 231 QCOMPARE(mailModel->rowCount(QModelIndex()), 2);
232 } 232 }
233 233
234 void testCreateFolder() 234 void testCreateFolder()