diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-05 10:37:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-05 10:37:28 +0200 |
commit | ca354ec4e2b9bc35b7d97c41bec68cccf6a6c8c9 (patch) | |
tree | 416c7c3462cd0df4d8681fe0414cf543ef4c094e /examples | |
parent | c03743546aa97d697d99eaac854516b1aa1f072b (diff) | |
download | sink-ca354ec4e2b9bc35b7d97c41bec68cccf6a6c8c9.tar.gz sink-ca354ec4e2b9bc35b7d97c41bec68cccf6a6c8c9.zip |
Create actual messages in maildir
Diffstat (limited to 'examples')
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.cpp | 34 | ||||
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.h | 1 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 2 |
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 | ||
709 | QString 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 | |||
709 | bool Maildir::removeEntry(const QString& key) | 743 | bool 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."); |