summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource
diff options
context:
space:
mode:
Diffstat (limited to 'examples/maildirresource')
-rw-r--r--examples/maildirresource/libmaildir/maildir.cpp34
-rw-r--r--examples/maildirresource/libmaildir/maildir.h1
-rw-r--r--examples/maildirresource/maildirresource.cpp2
3 files changed, 36 insertions, 1 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp
index 8d6de3e..670d4ca 100644
--- a/examples/maildirresource/libmaildir/maildir.cpp
+++ b/examples/maildirresource/libmaildir/maildir.cpp
@@ -706,6 +706,40 @@ QString Maildir::addEntry(const QByteArray& data)
706 return uniqueKey; 706 return uniqueKey;
707} 707}
708 708
709QString Maildir::addEntryFromPath(const QString& path)
710{
711 QString uniqueKey;
712 QString key;
713 QString finalKey;
714 QString curKey;
715
716 // QUuid doesn't return globally unique identifiers, therefor we query until we
717 // get one that doesn't exists yet
718 do {
719 uniqueKey = createUniqueFileName() + d->hostName;
720 key = d->path + QLatin1String("/tmp/") + uniqueKey;
721 finalKey = d->path + QLatin1String("/new/") + uniqueKey;
722 curKey = d->path + QLatin1String("/cur/") + uniqueKey;
723 } while (QFile::exists(key) || QFile::exists(finalKey) || QFile::exists(curKey));
724
725 QFile f(path);
726 if (!f.open(QIODevice::ReadWrite)) {
727 qWarning() << f.errorString();
728 qWarning() << "Cannot open mail file: " << key;
729 return QString();
730 }
731
732 if (!f.rename(finalKey)) {
733 qWarning() << "Maildir: Failed to add entry: " << finalKey << "! Error: " << f.errorString();
734 // d->lastError = i18n("Failed to create mail file %1. The error was: %2" , finalKey, f.errorString());
735 return QString();
736 }
737 // KeyCache *keyCache = KeyCache::self();
738 // keyCache->removeKey(d->path, key); //remove all keys, be it "cur" or "new" first
739 // keyCache->addNewKey(d->path, key); //and add a key for "new", as the mail was moved there
740 return uniqueKey;
741}
742
709bool Maildir::removeEntry(const QString& key) 743bool Maildir::removeEntry(const QString& key)
710{ 744{
711 QString realKey(d->findRealKey(key)); 745 QString realKey(d->findRealKey(key));
diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h
index 31778ac..8c622c7 100644
--- a/examples/maildirresource/libmaildir/maildir.h
+++ b/examples/maildirresource/libmaildir/maildir.h
@@ -207,6 +207,7 @@ public:
207 * Adds the given @p data to the maildir. Returns the key of the entry. 207 * Adds the given @p data to the maildir. Returns the key of the entry.
208 */ 208 */
209 QString addEntry( const QByteArray& data ); 209 QString addEntry( const QByteArray& data );
210 QString addEntryFromPath(const QString& path);
210 211
211 /** 212 /**
212 * Removes the entry with the given @p key. Returns success or failure. 213 * Removes the entry with the given @p key. Returns success or failure.
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index 839b427..2ad45cd 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -290,7 +290,7 @@ KAsync::Job<void> MaildirResource::replay(Sink::Storage &synchronizationStore, c
290 } 290 }
291 //FIXME move the mime message from the mimeMessage property to the proper place. 291 //FIXME move the mime message from the mimeMessage property to the proper place.
292 Trace() << "Creating a new mail."; 292 Trace() << "Creating a new mail.";
293 const auto remoteId = maildir.addEntry("foobar"); 293 const auto remoteId = maildir.addEntryFromPath(mail.getProperty("mimeMessage").toString());
294 if (remoteId.isEmpty()) { 294 if (remoteId.isEmpty()) {
295 Warning() << "Failed to create mail: " << remoteId; 295 Warning() << "Failed to create mail: " << remoteId;
296 return KAsync::error<void>(1, "Failed to create mail."); 296 return KAsync::error<void>(1, "Failed to create mail.");