summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/domain/applicationdomaintype.h12
-rw-r--r--common/domain/mail.cpp6
-rw-r--r--common/domain/mail.fbs11
-rw-r--r--common/mailpreprocessor.cpp4
-rw-r--r--common/propertymapper.cpp33
-rw-r--r--common/propertymapper.h25
6 files changed, 82 insertions, 9 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 39ce2b9..b377db9 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -271,10 +271,17 @@ struct SINK_EXPORT Folder : public Entity {
271}; 271};
272 272
273struct SINK_EXPORT Mail : public Entity { 273struct SINK_EXPORT Mail : public Entity {
274 struct SINK_EXPORT Contact {
275 QString name;
276 QString emailAddress;
277 };
278
274 SINK_ENTITY(Mail); 279 SINK_ENTITY(Mail);
275 SINK_PROPERTY(QString, Uid, uid); 280 SINK_PROPERTY(QString, Uid, uid);
276 SINK_EXTRACTED_PROPERTY(QString, Sender, sender); 281 SINK_PROPERTY(Contact, Sender, sender);
277 SINK_EXTRACTED_PROPERTY(QString, SenderName, senderName); 282 SINK_PROPERTY(QList<Contact>, To, to);
283 SINK_PROPERTY(QList<Contact>, Cc, cc);
284 SINK_PROPERTY(QList<Contact>, Bcc, bcc);
278 SINK_EXTRACTED_PROPERTY(QString, Subject, subject); 285 SINK_EXTRACTED_PROPERTY(QString, Subject, subject);
279 SINK_EXTRACTED_PROPERTY(QDateTime, Date, date); 286 SINK_EXTRACTED_PROPERTY(QDateTime, Date, date);
280 SINK_PROPERTY(bool, Unread, unread); 287 SINK_PROPERTY(bool, Unread, unread);
@@ -417,5 +424,6 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount)
417Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr) 424Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr)
418Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity) 425Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity)
419Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr) 426Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr)
427Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact)
420Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) 428Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
421Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 429Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index ee58928..5a77681 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -38,7 +38,7 @@ void TypeImplementation<Mail>::configure(TypeIndex &index)
38{ 38{
39 index.addProperty<QByteArray>(Mail::Uid::name); 39 index.addProperty<QByteArray>(Mail::Uid::name);
40 index.addProperty<QByteArray>(Mail::Sender::name); 40 index.addProperty<QByteArray>(Mail::Sender::name);
41 index.addProperty<QByteArray>(Mail::SenderName::name); 41 /* index.addProperty<QByteArray>(Mail::SenderName::name); */
42 /* index->addProperty<QString>(Mail::Subject::name); */ 42 /* index->addProperty<QString>(Mail::Subject::name); */
43 /* index->addFulltextProperty<QString>(Mail::Subject::name); */ 43 /* index->addFulltextProperty<QString>(Mail::Subject::name); */
44 index.addProperty<QDateTime>(Mail::Date::name); 44 index.addProperty<QDateTime>(Mail::Date::name);
@@ -68,7 +68,7 @@ void TypeImplementation<Mail>::configure(ReadPropertyMapper<Buffer> &propertyMap
68{ 68{
69 propertyMapper.addMapping<Mail::Uid, Buffer>(&Buffer::uid); 69 propertyMapper.addMapping<Mail::Uid, Buffer>(&Buffer::uid);
70 propertyMapper.addMapping<Mail::Sender, Buffer>(&Buffer::sender); 70 propertyMapper.addMapping<Mail::Sender, Buffer>(&Buffer::sender);
71 propertyMapper.addMapping<Mail::SenderName, Buffer>(&Buffer::senderName); 71 /* propertyMapper.addMapping<Mail::Recepients, Buffer>(&Buffer::recepients); */
72 propertyMapper.addMapping<Mail::Subject, Buffer>(&Buffer::subject); 72 propertyMapper.addMapping<Mail::Subject, Buffer>(&Buffer::subject);
73 propertyMapper.addMapping<Mail::Date, Buffer>(&Buffer::date); 73 propertyMapper.addMapping<Mail::Date, Buffer>(&Buffer::date);
74 propertyMapper.addMapping<Mail::Unread, Buffer>(&Buffer::unread); 74 propertyMapper.addMapping<Mail::Unread, Buffer>(&Buffer::unread);
@@ -86,7 +86,7 @@ void TypeImplementation<Mail>::configure(WritePropertyMapper<BufferBuilder> &pro
86{ 86{
87 propertyMapper.addMapping<Mail::Uid>(&BufferBuilder::add_uid); 87 propertyMapper.addMapping<Mail::Uid>(&BufferBuilder::add_uid);
88 propertyMapper.addMapping<Mail::Sender>(&BufferBuilder::add_sender); 88 propertyMapper.addMapping<Mail::Sender>(&BufferBuilder::add_sender);
89 propertyMapper.addMapping<Mail::SenderName>(&BufferBuilder::add_senderName); 89 /* propertyMapper.addMapping<Mail::Recepients>(&BufferBuilder::add_senderName); */
90 propertyMapper.addMapping<Mail::Subject>(&BufferBuilder::add_subject); 90 propertyMapper.addMapping<Mail::Subject>(&BufferBuilder::add_subject);
91 propertyMapper.addMapping<Mail::Date>(&BufferBuilder::add_date); 91 propertyMapper.addMapping<Mail::Date>(&BufferBuilder::add_date);
92 propertyMapper.addMapping<Mail::Unread>(&BufferBuilder::add_unread); 92 propertyMapper.addMapping<Mail::Unread>(&BufferBuilder::add_unread);
diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs
index f14e9f1..737a671 100644
--- a/common/domain/mail.fbs
+++ b/common/domain/mail.fbs
@@ -1,10 +1,17 @@
1namespace Sink.ApplicationDomain.Buffer; 1namespace Sink.ApplicationDomain.Buffer;
2 2
3table MailContact {
4 name: string;
5 email: string;
6}
7
3table Mail { 8table Mail {
4 uid:string; 9 uid:string;
5 folder:string; 10 folder:string;
6 sender:string; 11 sender:MailContact;
7 senderName:string; 12 to:[MailContact];
13 cc:[MailContact];
14 bcc:[MailContact];
8 subject:string; 15 subject:string;
9 date:string; 16 date:string;
10 unread:bool = false; 17 unread:bool = false;
diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp
index d45afe6..17a2f4f 100644
--- a/common/mailpreprocessor.cpp
+++ b/common/mailpreprocessor.cpp
@@ -84,8 +84,8 @@ struct MimeMessageReader {
84static void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, KMime::Message::Ptr msg) 84static void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, KMime::Message::Ptr msg)
85{ 85{
86 mail.setExtractedSubject(msg->subject(true)->asUnicodeString()); 86 mail.setExtractedSubject(msg->subject(true)->asUnicodeString());
87 mail.setExtractedSender(msg->from(true)->asUnicodeString()); 87 /* mail.setExtractedSender(msg->from(true)->asUnicodeString()); */
88 mail.setExtractedSenderName(msg->from(true)->asUnicodeString()); 88 /* mail.setExtractedSenderName(msg->from(true)->asUnicodeString()); */
89 mail.setExtractedDate(msg->date(true)->dateTime()); 89 mail.setExtractedDate(msg->date(true)->dateTime());
90 90
91 //The rest should never change, unless we didn't have the headers available initially. 91 //The rest should never change, unless we didn't have the headers available initially.
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp
index 9fe2d30..78c5021 100644
--- a/common/propertymapper.cpp
+++ b/common/propertymapper.cpp
@@ -18,7 +18,10 @@
18 */ 18 */
19 19
20#include "propertymapper.h" 20#include "propertymapper.h"
21
22#include "applicationdomaintype.h"
21#include <QDateTime> 23#include <QDateTime>
24#include "mail_generated.h"
22 25
23template <> 26template <>
24flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 27flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
@@ -63,6 +66,26 @@ flatbuffers::uoffset_t variantToProperty<QByteArrayList>(const QVariant &propert
63} 66}
64 67
65template <> 68template <>
69flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Mail::Contact>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
70{
71 if (property.isValid()) {
72 const auto value = property.value<Sink::ApplicationDomain::Mail::Contact>();
73 return Sink::ApplicationDomain::Buffer::CreateMailContactDirect(fbb, value.name.toUtf8().constData(), value.name.toUtf8().constData()).o;
74 }
75 return 0;
76}
77
78
79QString propertyToString(const flatbuffers::String *property)
80{
81 if (property) {
82 // We have to copy the memory, otherwise it would become eventually invalid
83 return QString::fromStdString(property->c_str());
84 }
85 return QString();
86}
87
88template <>
66QVariant propertyToVariant<QString>(const flatbuffers::String *property) 89QVariant propertyToVariant<QString>(const flatbuffers::String *property)
67{ 90{
68 if (property) { 91 if (property) {
@@ -108,6 +131,16 @@ QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers
108} 131}
109 132
110template <> 133template <>
134QVariant propertyToVariant<Sink::ApplicationDomain::Mail::Contact>(const Sink::ApplicationDomain::Buffer::MailContact *property)
135{
136 if (property) {
137 return QVariant::fromValue(Sink::ApplicationDomain::Mail::Contact{propertyToString(property->name()), propertyToString(property->email())});
138 }
139 return QVariant();
140
141}
142
143template <>
111QVariant propertyToVariant<bool>(uint8_t property) 144QVariant propertyToVariant<bool>(uint8_t property)
112{ 145{
113 return static_cast<bool>(property); 146 return static_cast<bool>(property);
diff --git a/common/propertymapper.h b/common/propertymapper.h
index 8227940..a63b7e7 100644
--- a/common/propertymapper.h
+++ b/common/propertymapper.h
@@ -25,6 +25,14 @@
25#include <functional> 25#include <functional>
26#include <flatbuffers/flatbuffers.h> 26#include <flatbuffers/flatbuffers.h>
27 27
28namespace Sink {
29namespace ApplicationDomain {
30namespace Buffer {
31 struct MailContact;
32}
33}
34}
35
28/** 36/**
29 * Defines how to convert qt primitives to flatbuffer ones 37 * Defines how to convert qt primitives to flatbuffer ones
30 */ 38 */
@@ -42,6 +50,8 @@ template <typename T>
42QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); 50QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *);
43template <typename T> 51template <typename T>
44QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *); 52QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *);
53template <typename T>
54QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *);
45 55
46/** 56/**
47 * The property mapper is a non-typesafe virtual dispatch. 57 * The property mapper is a non-typesafe virtual dispatch.
@@ -107,6 +117,12 @@ public:
107 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); }); 117 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); });
108 } 118 }
109 119
120 template <typename T, typename Buffer>
121 void addMapping(const Sink::ApplicationDomain::Buffer::MailContact *(Buffer::*f)() const)
122 {
123 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); });
124 }
125
110private: 126private:
111 QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; 127 QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors;
112}; 128};
@@ -176,6 +192,15 @@ public:
176 }); 192 });
177 } 193 }
178 194
195 template <typename T>
196 void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>))
197 {
198 addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> {
199 auto offset = variantToProperty<typename T::Type>(value, fbb);
200 return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); };
201 });
202 }
203
179private: 204private:
180 QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; 205 QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors;
181}; 206};