diff options
Diffstat (limited to 'examples/mailtransportresource/mailtransportresource.cpp')
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 75d9898..8e5b22e 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -43,6 +43,44 @@ SINK_DEBUG_AREA("mailtransportresource") | |||
43 | 43 | ||
44 | using namespace Sink; | 44 | using namespace Sink; |
45 | 45 | ||
46 | class MailtransportPreprocessor : public Sink::Preprocessor | ||
47 | { | ||
48 | public: | ||
49 | MailtransportPreprocessor() : Sink::Preprocessor() {} | ||
50 | |||
51 | QByteArray getTargetResource() | ||
52 | { | ||
53 | using namespace Sink::ApplicationDomain; | ||
54 | |||
55 | auto resource = Store::readOne<ApplicationDomain::SinkResource>(Query{}.filter(resourceInstanceIdentifier()).request<ApplicationDomain::SinkResource::Account>()); | ||
56 | if (resource.identifier().isEmpty()) { | ||
57 | SinkWarning() << "Failed to retrieve this resource: " << resourceInstanceIdentifier(); | ||
58 | } | ||
59 | Query query; | ||
60 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::sent); | ||
61 | query.filter<ApplicationDomain::SinkResource::Account>(resource.getAccount()); | ||
62 | auto targetResource = Store::readOne<ApplicationDomain::SinkResource>(query); | ||
63 | if (targetResource.identifier().isEmpty()) { | ||
64 | SinkWarning() << "Failed to find target resource: " << targetResource.identifier(); | ||
65 | } | ||
66 | return targetResource.identifier(); | ||
67 | } | ||
68 | |||
69 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE | ||
70 | { | ||
71 | using namespace Sink::ApplicationDomain; | ||
72 | auto mail = newEntity.cast<Mail>(); | ||
73 | if (mail.changedProperties().contains(Mail::Trash::name)) { | ||
74 | //Move back to regular resource | ||
75 | newEntity.setResource(getTargetResource()); | ||
76 | } else if (mail.changedProperties().contains(Mail::Draft::name)) { | ||
77 | //Move back to regular resource | ||
78 | newEntity.setResource(getTargetResource()); | ||
79 | } | ||
80 | //TODO this will only copy it back, but not yet move | ||
81 | } | ||
82 | }; | ||
83 | |||
46 | class MailtransportSynchronizer : public Sink::Synchronizer { | 84 | class MailtransportSynchronizer : public Sink::Synchronizer { |
47 | public: | 85 | public: |
48 | MailtransportSynchronizer(const Sink::ResourceContext &resourceContext) | 86 | MailtransportSynchronizer(const Sink::ResourceContext &resourceContext) |
@@ -65,7 +103,11 @@ public: | |||
65 | msg->setHead(KMime::CRLFtoLF(data)); | 103 | msg->setHead(KMime::CRLFtoLF(data)); |
66 | msg->parse(); | 104 | msg->parse(); |
67 | if (settings.testMode) { | 105 | if (settings.testMode) { |
68 | SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); | 106 | auto subject = msg->subject(true)->asUnicodeString(); |
107 | SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier() << subject; | ||
108 | if (!subject.contains("send")) { | ||
109 | return KAsync::error("Failed to send the message."); | ||
110 | } | ||
69 | auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; | 111 | auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; |
70 | SinkTrace() << path; | 112 | SinkTrace() << path; |
71 | QDir dir; | 113 | QDir dir; |
@@ -194,7 +236,7 @@ MailtransportResource::MailtransportResource(const Sink::ResourceContext &resour | |||
194 | setupSynchronizer(synchronizer); | 236 | setupSynchronizer(synchronizer); |
195 | setupInspector(QSharedPointer<MailtransportInspector>::create(resourceContext)); | 237 | setupInspector(QSharedPointer<MailtransportInspector>::create(resourceContext)); |
196 | 238 | ||
197 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MailPropertyExtractor); | 239 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MailPropertyExtractor << new MailtransportPreprocessor); |
198 | } | 240 | } |
199 | 241 | ||
200 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) | 242 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) |