From 1d245e28c9b1b18a45097a72bc4ff166c59c37ba Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 31 Oct 2016 18:45:59 +0100 Subject: Mail::Contact mapping --- common/domain/applicationdomaintype.h | 12 ++++++++++-- common/domain/mail.cpp | 6 +++--- common/domain/mail.fbs | 11 +++++++++-- common/mailpreprocessor.cpp | 4 ++-- common/propertymapper.cpp | 33 +++++++++++++++++++++++++++++++++ common/propertymapper.h | 25 +++++++++++++++++++++++++ 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 { }; struct SINK_EXPORT Mail : public Entity { + struct SINK_EXPORT Contact { + QString name; + QString emailAddress; + }; + SINK_ENTITY(Mail); SINK_PROPERTY(QString, Uid, uid); - SINK_EXTRACTED_PROPERTY(QString, Sender, sender); - SINK_EXTRACTED_PROPERTY(QString, SenderName, senderName); + SINK_PROPERTY(Contact, Sender, sender); + SINK_PROPERTY(QList, To, to); + SINK_PROPERTY(QList, Cc, cc); + SINK_PROPERTY(QList, Bcc, bcc); SINK_EXTRACTED_PROPERTY(QString, Subject, subject); SINK_EXTRACTED_PROPERTY(QDateTime, Date, date); SINK_PROPERTY(bool, Unread, unread); @@ -417,5 +424,6 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount) Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) Q_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::configure(TypeIndex &index) { index.addProperty(Mail::Uid::name); index.addProperty(Mail::Sender::name); - index.addProperty(Mail::SenderName::name); + /* index.addProperty(Mail::SenderName::name); */ /* index->addProperty(Mail::Subject::name); */ /* index->addFulltextProperty(Mail::Subject::name); */ index.addProperty(Mail::Date::name); @@ -68,7 +68,7 @@ void TypeImplementation::configure(ReadPropertyMapper &propertyMap { propertyMapper.addMapping(&Buffer::uid); propertyMapper.addMapping(&Buffer::sender); - propertyMapper.addMapping(&Buffer::senderName); + /* propertyMapper.addMapping(&Buffer::recepients); */ propertyMapper.addMapping(&Buffer::subject); propertyMapper.addMapping(&Buffer::date); propertyMapper.addMapping(&Buffer::unread); @@ -86,7 +86,7 @@ void TypeImplementation::configure(WritePropertyMapper &pro { propertyMapper.addMapping(&BufferBuilder::add_uid); propertyMapper.addMapping(&BufferBuilder::add_sender); - propertyMapper.addMapping(&BufferBuilder::add_senderName); + /* propertyMapper.addMapping(&BufferBuilder::add_senderName); */ propertyMapper.addMapping(&BufferBuilder::add_subject); propertyMapper.addMapping(&BufferBuilder::add_date); propertyMapper.addMapping(&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 @@ namespace Sink.ApplicationDomain.Buffer; +table MailContact { + name: string; + email: string; +} + table Mail { uid:string; folder:string; - sender:string; - senderName:string; + sender:MailContact; + to:[MailContact]; + cc:[MailContact]; + bcc:[MailContact]; subject:string; date:string; 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 { static void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, KMime::Message::Ptr msg) { mail.setExtractedSubject(msg->subject(true)->asUnicodeString()); - mail.setExtractedSender(msg->from(true)->asUnicodeString()); - mail.setExtractedSenderName(msg->from(true)->asUnicodeString()); + /* mail.setExtractedSender(msg->from(true)->asUnicodeString()); */ + /* mail.setExtractedSenderName(msg->from(true)->asUnicodeString()); */ mail.setExtractedDate(msg->date(true)->dateTime()); //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 @@ */ #include "propertymapper.h" + +#include "applicationdomaintype.h" #include +#include "mail_generated.h" template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) @@ -62,6 +65,26 @@ flatbuffers::uoffset_t variantToProperty(const QVariant &propert return 0; } +template <> +flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) +{ + if (property.isValid()) { + const auto value = property.value(); + return Sink::ApplicationDomain::Buffer::CreateMailContactDirect(fbb, value.name.toUtf8().constData(), value.name.toUtf8().constData()).o; + } + return 0; +} + + +QString propertyToString(const flatbuffers::String *property) +{ + if (property) { + // We have to copy the memory, otherwise it would become eventually invalid + return QString::fromStdString(property->c_str()); + } + return QString(); +} + template <> QVariant propertyToVariant(const flatbuffers::String *property) { @@ -107,6 +130,16 @@ QVariant propertyToVariant(const flatbuffers::Vector +QVariant propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *property) +{ + if (property) { + return QVariant::fromValue(Sink::ApplicationDomain::Mail::Contact{propertyToString(property->name()), propertyToString(property->email())}); + } + return QVariant(); + +} + template <> QVariant propertyToVariant(uint8_t 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 @@ #include #include +namespace Sink { +namespace ApplicationDomain { +namespace Buffer { + struct MailContact; +} +} +} + /** * Defines how to convert qt primitives to flatbuffer ones */ @@ -42,6 +50,8 @@ template QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector *); template QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector> *); +template +QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); /** * The property mapper is a non-typesafe virtual dispatch. @@ -107,6 +117,12 @@ public: addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); } + template + void addMapping(const Sink::ApplicationDomain::Buffer::MailContact *(Buffer::*f)() const) + { + addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); + } + private: QHash> mReadAccessors; }; @@ -176,6 +192,15 @@ public: }); } + template + void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset)) + { + addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + auto offset = variantToProperty(value, fbb); + return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; + }); + } + private: QHash(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; }; -- cgit v1.2.3