From 7815e94c52d092701804521eee850ac35d7f7781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Thu, 14 Jul 2016 18:36:02 +0200 Subject: updated --- framework/domain/mimetreeparser/interface.h | 81 ++++++++++++++++++++++------- framework/domain/mimetreeparser/test.cpp | 30 ++++++----- 2 files changed, 78 insertions(+), 33 deletions(-) (limited to 'framework') diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h index a9e394db..320030b7 100644 --- a/framework/domain/mimetreeparser/interface.h +++ b/framework/domain/mimetreeparser/interface.h @@ -23,32 +23,41 @@ #include class Part; +typedef std::shared_ptr Part::Ptr; class EncryptionPart; +typedef std::shared_ptr EncryptionPart::Ptr; class SignaturePart; +typedef std::shared_ptr SignaturePart::Ptr; class MimePart; +typedef std::shared_ptr MimePart::Ptr; class MimePartPrivate; class ContentPart; +typedef std::shared_ptr ContentPart::Ptr; class ContentPartPrivate; class EncryptionErrorPart; +typedef std::shared_ptr EncryptionErrorPart::Ptr; class EncryptionErrorPartPrivate; class AttachmentPart; +typedef std::shared_ptr AttachmentPart::Ptr; class AttachmentPartPrivate; class EncapsulatedPart; +typedef std::shared_ptr EncapsulatedPart::Ptr; class EncapsulatedPart; class CertPart; -class CertPart; +typedef std::shared_ptr CertPart::Ptr; class Key; class Signature; class Encryption; class Parser; +typedef std::shared_ptr Parser::Ptr; class ParserPrivate; class Parser @@ -56,30 +65,71 @@ class Parser public: Parser(const QByteArray &mimeMessage); - std::shared_ptr getPart(QUrl url); + Part::Ptr getPart(QUrl url); - QVector> collect() const; - QVector> collect() const; - QVector> collect(Part start, std::function select, std::function &)> filter) const; + QVector collect() const; + QVector collect() const; + QVector collect(Part start, std::function select, std::function filter) const; private: std::unique_ptr d; }; + class Part { public: virtual QByteArray type() const = 0; bool hasSubParts() const; - QList subParts() const; - Part partent() const; + QList subParts() const; + Part parent() const; + + virtual QVector signatures() const; + virtual QVector encryptions() const; }; +//A structure element, that we need to reflect, that there is a Encryption starts +// only add a new Encrption block to encryptions block +class EncryptionPart : public Part +{ +public: + QVector encryptions() const Q_DECL_OVERRIDE; + QByteArray type() const Q_DECL_OVERRIDE; +}; + +// A structure element, that we need to reflect, that there is a Signature starts +// only add a new Signature block to signature block +// With this we can a new Singature type like pep aka +/* + * add a bodypartformatter, that returns a PEPSignaturePart with all signed subparts that are signed with pep. + * subclass Signature aka PEPSignature to reflect different way of properties of PEPSignatures. + */ +class SignaturePart : public Part +{ +public: + QVector signatures() const Q_DECL_OVERRIDE; + QByteArray type() const Q_DECL_OVERRIDE; +}; + + + +class TextPart : public Part +{ +public: + QByteArray content() const; + + //Use default charset + QString encodedContent() const; + + // overwrite default charset with given charset + QString encodedContent(QByteArray charset) const; +} + /* * A MessagePart that is based on a KMime::Content */ -class MimePart : public Part +class MimePart : public TextPart { public: /** @@ -88,14 +138,12 @@ public: enum Disposition { Invalid, ///< Default, invalid value Inline, ///< inline - Attachment, ///< attachment - Parallel ///< parallel (invalid, do not use) + Attachment ///< attachment }; // interessting header parts of a KMime::Content - QByteArray content() const; QMimeType mimetype() const; - Disposition dispossition() const + Disposition disposition() const; QUrl label() const; QByteArray cid() const; QByteArray charset() const; @@ -123,7 +171,7 @@ private: * for alternative, we are represating three messageparts * - "headers" do we return?, we can use setType to make it possible to select and than return these headers */ -class ContentPart : public MimePart +class MainContentPart : public MimePart { public: enum Types { @@ -132,14 +180,9 @@ public: }; Q_DECLARE_FLAGS(Types, Type) - QByteArray content(Content::Type ct) const; - - // convert content with charset - QString content(Content::Type ct) const; + QVector content(Content::Type ct) const; Content::Types availableContent() const; - QVector signature() const; - QVector encryption() const; QByteArray type() const Q_DECL_OVERRIDE; diff --git a/framework/domain/mimetreeparser/test.cpp b/framework/domain/mimetreeparser/test.cpp index e096ea78..51aa9871 100644 --- a/framework/domain/mimetreeparser/test.cpp +++ b/framework/domain/mimetreeparser/test.cpp @@ -23,24 +23,27 @@ ap1 == getPart("cid:12345678") (Html) == cp1.availableContent() # alternative msg + attachment -* ContentPart(html="HTML", plaintext="Text") => cp1 +* ContentPart(html=[TextPart("HTML"),], plaintext=[TextPart("Text"),]) => cp1 * AttachmentPart => ap1 (cp1) == collect(select=NoEncapsulatedMessages) (ap1) == collect(select=NoEncapsulatedMessages) (Html, PlainText) == cp1.availableContent() -"HTML" == cp1.content(Html) -"text" == cp1.content(Plaintext) +[TextPart("HTML"),] == cp1.content(Html) +[TextPart("Text"),] == cp1.content(Plaintext) -# alternative msg with GPGInline -* ContentPart(html="HTML", plaintext="Text cypted") => cp1 - * TextPart(text="Text") - * TextPart(text=foo, encryption=(enc1) +# alternative msg with GPGInlin +* ContentPart( + plaintext=[TextPart("Text"), TextPart("foo", encryption=(enc1))], + html=[TextPart("HTML"),] + ) => cp1 (Html, PlainText) == cp1.availableContent() -TODO: but how to get plaintext/html content? +[TextPart("HTML"),] == cp1.content(Html) +[TextPart("Text"),TextPart("foo", encryption=(enc1))] == cp1.content(Plaintext) + # encrypted msg (not encrypted/error) with unencrypted attachment * EncryptionErrorPart => cp1 @@ -59,16 +62,15 @@ TODO: but how to get plaintext/html content? (ap1, ap2) == collect(select=NoEncapsulatedMessages) #INLINE GPG encrypted msg + attachment -* ContentPart => cp1 - * TextPart - * TextPart(encrytion = (enc1(rec1,rec2),)) - * TextPart(signed = (sig1,)) - * TextPart +* ContentPart => cp1 with + plaintext=[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart] * AttachmentPart => ap1 (cp1) == collect(select=NoEncapsulatedMessages) (ap1) == collect(select=NoEncapsulatedMessages) +[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart] == cp1.content(Plaintext) + #forwared encrypted msg + attachments * ContentPart => cp1 * EncapsulatedPart => ep1 @@ -87,7 +89,7 @@ TODO: but how to get plaintext/html content? (ap1) = collect(ep1, select=NoEncapsulatedMessages) (cp1, cp2) == collect() -(ap1, ap2) == collect() +(ap1, ap2) == collect()[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart] # plaintext msg + attachment + cert -- cgit v1.2.3