diff options
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 53 | ||||
-rw-r--r-- | examples/mailtransportresource/tests/mailtransporttest.cpp | 4 |
2 files changed, 5 insertions, 52 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 51e4976..1e93bdf 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -39,60 +39,13 @@ | |||
39 | #include <log.h> | 39 | #include <log.h> |
40 | #include <resourceconfig.h> | 40 | #include <resourceconfig.h> |
41 | #include <pipeline.h> | 41 | #include <pipeline.h> |
42 | #include <mailpreprocessor.h> | ||
43 | #include <indexupdater.h> | ||
42 | 44 | ||
43 | #define ENTITY_TYPE_MAIL "mail" | 45 | #define ENTITY_TYPE_MAIL "mail" |
44 | 46 | ||
45 | using namespace Sink; | 47 | using namespace Sink; |
46 | 48 | ||
47 | class MimeMessageMover : public Sink::EntityPreprocessor<ApplicationDomain::Mail> | ||
48 | { | ||
49 | public: | ||
50 | MimeMessageMover(const QByteArray &resourceInstanceIdentifier) : Sink::EntityPreprocessor<ApplicationDomain::Mail>(), mResourceInstanceIdentifier(resourceInstanceIdentifier) {} | ||
51 | |||
52 | QString moveMessage(const QString &oldPath, const Sink::ApplicationDomain::Mail &mail) | ||
53 | { | ||
54 | const auto directory = Sink::resourceStorageLocation(mResourceInstanceIdentifier); | ||
55 | const auto filePath = directory + "/" + mail.identifier(); | ||
56 | if (oldPath != filePath) { | ||
57 | if (!QDir().mkpath(directory)) { | ||
58 | Warning() << "Failed to create the directory: " << directory; | ||
59 | } | ||
60 | QFile::remove(filePath); | ||
61 | QFile origFile(oldPath); | ||
62 | if (!origFile.open(QIODevice::ReadWrite)) { | ||
63 | Warning() << "Failed to open the original file with write rights: " << origFile.errorString(); | ||
64 | } | ||
65 | if (!origFile.rename(filePath)) { | ||
66 | Warning() << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); | ||
67 | } | ||
68 | origFile.close(); | ||
69 | return filePath; | ||
70 | } | ||
71 | return oldPath; | ||
72 | } | ||
73 | |||
74 | void newEntity(Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
75 | { | ||
76 | if (!mail.getMimeMessagePath().isEmpty()) { | ||
77 | mail.setMimeMessagePath(moveMessage(mail.getMimeMessagePath(), mail)); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | void modifiedEntity(const Sink::ApplicationDomain::Mail &oldMail, Sink::ApplicationDomain::Mail &newMail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
82 | { | ||
83 | if (!newMail.getMimeMessagePath().isEmpty()) { | ||
84 | newMail.setMimeMessagePath(moveMessage(newMail.getMimeMessagePath(), newMail)); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | void deletedEntity(const Sink::ApplicationDomain::Mail &mail, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
89 | { | ||
90 | QFile::remove(mail.getMimeMessagePath()); | ||
91 | } | ||
92 | QByteArray mResourceInstanceIdentifier; | ||
93 | }; | ||
94 | |||
95 | |||
96 | //TODO fold into synchronizer | 49 | //TODO fold into synchronizer |
97 | class MailtransportWriteback : public Sink::SourceWriteBack | 50 | class MailtransportWriteback : public Sink::SourceWriteBack |
98 | { | 51 | { |
@@ -210,7 +163,7 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie | |||
210 | changereplay->mSettings = mSettings; | 163 | changereplay->mSettings = mSettings; |
211 | setupChangereplay(changereplay); | 164 | setupChangereplay(changereplay); |
212 | 165 | ||
213 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover(mResourceInstanceIdentifier)); | 166 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover << new MailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); |
214 | } | 167 | } |
215 | 168 | ||
216 | void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) | 169 | void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) |
diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index f1190a7..3ce5f82 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp | |||
@@ -65,9 +65,9 @@ private slots: | |||
65 | VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier))); | 65 | VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier))); |
66 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); | 66 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); |
67 | 67 | ||
68 | auto sentMail = Store::readOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail).request<Mail::Sent>()); | 68 | auto sentMail = Store::readOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail).request<Mail::Sent>().request<Mail::Subject>()); |
69 | QVERIFY(sentMail.getSent()); | 69 | QVERIFY(sentMail.getSent()); |
70 | 70 | QVERIFY(!sentMail.getSubject().isEmpty()); | |
71 | } | 71 | } |
72 | 72 | ||
73 | //TODO test mail that fails to be sent. add a special header to the mail and have the resource fail sending. Ensure we can modify the mail to fix sending of the message. | 73 | //TODO test mail that fails to be sent. add a special header to the mail and have the resource fail sending. Ensure we can modify the mail to fix sending of the message. |