summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource
diff options
context:
space:
mode:
Diffstat (limited to 'examples/maildirresource')
-rw-r--r--examples/maildirresource/libmaildir/maildir.cpp74
1 files changed, 42 insertions, 32 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp
index 2b0148c..94363b8 100644
--- a/examples/maildirresource/libmaildir/maildir.cpp
+++ b/examples/maildirresource/libmaildir/maildir.cpp
@@ -18,7 +18,7 @@
18*/ 18*/
19 19
20#include "maildir.h" 20#include "maildir.h"
21#include "keycache.h" 21// #include "keycache.h"
22 22
23#include <QDateTime> 23#include <QDateTime>
24#include <QDir> 24#include <QDir>
@@ -98,7 +98,7 @@ public:
98 98
99 //Cache object is created the first time this runs. 99 //Cache object is created the first time this runs.
100 //It will live throughout the lifetime of the application 100 //It will live throughout the lifetime of the application
101 KeyCache::self()->addKeys(path); 101 // KeyCache::self()->addKeys(path);
102 } 102 }
103 103
104 Private(const Private& rhs) 104 Private(const Private& rhs)
@@ -140,8 +140,10 @@ public:
140 140
141 QString findRealKey(const QString& key) const 141 QString findRealKey(const QString& key) const
142 { 142 {
143 KeyCache* keyCache = KeyCache::self(); 143 // KeyCache* keyCache = KeyCache::self();
144 if (keyCache->isNewKey(path, key)) { 144 // if (keyCache->isNewKey(path, key)) {
145 qWarning() << path + QString::fromLatin1("/new/") + key;
146 if (QFile::exists(path + QString::fromLatin1("/new/") + key)) {
145#ifdef DEBUG_KEYCACHE_CONSITENCY 147#ifdef DEBUG_KEYCACHE_CONSITENCY
146 if (!QFile::exists(path + QString::fromLatin1("/new/") + key)) { 148 if (!QFile::exists(path + QString::fromLatin1("/new/") + key)) {
147 qDebug() << "WARNING: key is in cache, but the file is gone: " << path + QString::fromLatin1("/new/") + key; 149 qDebug() << "WARNING: key is in cache, but the file is gone: " << path + QString::fromLatin1("/new/") + key;
@@ -149,7 +151,8 @@ public:
149#endif 151#endif
150 return path + QString::fromLatin1("/new/") + key; 152 return path + QString::fromLatin1("/new/") + key;
151 } 153 }
152 if (keyCache->isCurKey(path, key)) { 154 // if (keyCache->isCurKey(path, key)) {
155 if (QFile::exists(path + QString::fromLatin1("/cur/") + key)) {
153#ifdef DEBUG_KEYCACHE_CONSITENCY 156#ifdef DEBUG_KEYCACHE_CONSITENCY
154 if (!QFile::exists(path + QString::fromLatin1("/cur/") + key)) { 157 if (!QFile::exists(path + QString::fromLatin1("/cur/") + key)) {
155 qDebug() << "WARNING: key is in cache, but the file is gone: " << path + QString::fromLatin1("/cur/") + key; 158 qDebug() << "WARNING: key is in cache, but the file is gone: " << path + QString::fromLatin1("/cur/") + key;
@@ -159,18 +162,18 @@ public:
159 } 162 }
160 QString realKey = path + QString::fromLatin1("/new/") + key; 163 QString realKey = path + QString::fromLatin1("/new/") + key;
161 164
162 QFile f(realKey); 165 // QFile f(realKey);
163 if (f.exists()) { 166 // if (f.exists()) {
164 keyCache->addNewKey(path, key); 167 // keyCache->addNewKey(path, key);
165 } else { //not in "new", search in "cur" 168 // } else { //not in "new", search in "cur"
166 realKey = path + QString::fromLatin1("/cur/") + key; 169 // realKey = path + QString::fromLatin1("/cur/") + key;
167 QFile f2(realKey); 170 // QFile f2(realKey);
168 if (f2.exists()) { 171 // if (f2.exists()) {
169 keyCache->addCurKey(path, key); 172 // keyCache->addCurKey(path, key);
170 } else { 173 // } else {
171 realKey.clear(); //not in "cur" either 174 // realKey.clear(); //not in "cur" either
172 } 175 // }
173 } 176 // }
174 177
175 return realKey; 178 return realKey;
176 } 179 }
@@ -660,9 +663,9 @@ QString Maildir::addEntry(const QByteArray& data)
660 // d->lastError = i18n("Failed to create mail file %1. The error was: %2" , finalKey, f.errorString()); 663 // d->lastError = i18n("Failed to create mail file %1. The error was: %2" , finalKey, f.errorString());
661 return QString(); 664 return QString();
662 } 665 }
663 KeyCache *keyCache = KeyCache::self(); 666 // KeyCache *keyCache = KeyCache::self();
664 keyCache->removeKey(d->path, key); //remove all keys, be it "cur" or "new" first 667 // keyCache->removeKey(d->path, key); //remove all keys, be it "cur" or "new" first
665 keyCache->addNewKey(d->path, key); //and add a key for "new", as the mail was moved there 668 // keyCache->addNewKey(d->path, key); //and add a key for "new", as the mail was moved there
666 return uniqueKey; 669 return uniqueKey;
667} 670}
668 671
@@ -673,9 +676,16 @@ bool Maildir::removeEntry(const QString& key)
673 qWarning() << "Maildir::removeEntry unable to find: " << key; 676 qWarning() << "Maildir::removeEntry unable to find: " << key;
674 return false; 677 return false;
675 } 678 }
676 KeyCache *keyCache = KeyCache::self(); 679 // KeyCache *keyCache = KeyCache::self();
677 keyCache->removeKey(d->path, key); 680 // keyCache->removeKey(d->path, key);
678 return QFile::remove(realKey); 681 qWarning() << "Real key";
682 QFile file(realKey);
683 if (!file.remove()) {
684 qWarning() << file.errorString() << file.error();
685 return false;
686 }
687 return true;
688 // return QFile::remove(realKey);
679} 689}
680 690
681// QString Maildir::changeEntryFlags(const QString& key, const Akonadi::Item::Flags& flags) 691// QString Maildir::changeEntryFlags(const QString& key, const Akonadi::Item::Flags& flags)
@@ -835,10 +845,10 @@ QString Maildir::moveEntryTo(const QString &key, const Maildir &destination)
835 return QString(); 845 return QString();
836 } 846 }
837 847
838 KeyCache* keyCache = KeyCache::self(); 848 // KeyCache* keyCache = KeyCache::self();
839 849 //
840 keyCache->addNewKey(destination.path(), key); 850 // keyCache->addNewKey(destination.path(), key);
841 keyCache->removeKey(d->path, key); 851 // keyCache->removeKey(d->path, key);
842 852
843 return key; 853 return key;
844} 854}
@@ -858,15 +868,15 @@ QString Maildir::subDirNameForFolderName(const QString &folderName)
858 868
859void Maildir::removeCachedKeys(const QStringList & keys) 869void Maildir::removeCachedKeys(const QStringList & keys)
860{ 870{
861 KeyCache *keyCache = KeyCache::self(); 871 // KeyCache *keyCache = KeyCache::self();
862 Q_FOREACH (const QString &key, keys) { 872 // Q_FOREACH (const QString &key, keys) {
863 keyCache->removeKey(d->path, key); 873 // keyCache->removeKey(d->path, key);
864 } 874 // }
865} 875}
866 876
867void Maildir::refreshKeyCache() 877void Maildir::refreshKeyCache()
868{ 878{
869 KeyCache::self()->refreshKeys(d->path); 879 // KeyCache::self()->refreshKeys(d->path);
870} 880}
871 881
872QString Maildir::lastError() const 882QString Maildir::lastError() const