summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/domain/mimetreeparser/interface.h81
-rw-r--r--framework/domain/mimetreeparser/test.cpp30
2 files changed, 78 insertions, 33 deletions
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 @@
23#include <QMimeType> 23#include <QMimeType>
24 24
25class Part; 25class Part;
26typedef std::shared_ptr<Part> Part::Ptr;
26class EncryptionPart; 27class EncryptionPart;
28typedef std::shared_ptr<Part> EncryptionPart::Ptr;
27class SignaturePart; 29class SignaturePart;
30typedef std::shared_ptr<Part> SignaturePart::Ptr;
28 31
29class MimePart; 32class MimePart;
33typedef std::shared_ptr<Part> MimePart::Ptr;
30class MimePartPrivate; 34class MimePartPrivate;
31 35
32class ContentPart; 36class ContentPart;
37typedef std::shared_ptr<Part> ContentPart::Ptr;
33class ContentPartPrivate; 38class ContentPartPrivate;
34 39
35class EncryptionErrorPart; 40class EncryptionErrorPart;
41typedef std::shared_ptr<Part> EncryptionErrorPart::Ptr;
36class EncryptionErrorPartPrivate; 42class EncryptionErrorPartPrivate;
37 43
38class AttachmentPart; 44class AttachmentPart;
45typedef std::shared_ptr<Part> AttachmentPart::Ptr;
39class AttachmentPartPrivate; 46class AttachmentPartPrivate;
40 47
41class EncapsulatedPart; 48class EncapsulatedPart;
49typedef std::shared_ptr<Part> EncapsulatedPart::Ptr;
42class EncapsulatedPart; 50class EncapsulatedPart;
43 51
44class CertPart; 52class CertPart;
45class CertPart; 53typedef std::shared_ptr<Part> CertPart::Ptr;
46 54
47class Key; 55class Key;
48class Signature; 56class Signature;
49class Encryption; 57class Encryption;
50 58
51class Parser; 59class Parser;
60typedef std::shared_ptr<Parser> Parser::Ptr;
52class ParserPrivate; 61class ParserPrivate;
53 62
54class Parser 63class Parser
@@ -56,30 +65,71 @@ class Parser
56public: 65public:
57 Parser(const QByteArray &mimeMessage); 66 Parser(const QByteArray &mimeMessage);
58 67
59 std::shared_ptr<Part> getPart(QUrl url); 68 Part::Ptr getPart(QUrl url);
60 69
61 QVector<std::shared_ptr<AttachmentPart>> collect<AttachmentPart>() const; 70 QVector<AttachmentPart::Ptr> collect<AttachmentPart>() const;
62 QVector<std::shared_ptr<ContentPart>> collect<ContentPart>() const; 71 QVector<ContentPart:Ptr> collect<ContentPart>() const;
63 QVector<std::shared_ptr<T>> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const std::shared_ptr<T> &)> filter) const; 72 QVector<T::Ptr> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const T::Ptr &)> filter) const;
64 73
65private: 74private:
66 std::unique_ptr<ParserPrivate> d; 75 std::unique_ptr<ParserPrivate> d;
67}; 76};
68 77
78
69class Part 79class Part
70{ 80{
71public: 81public:
72 virtual QByteArray type() const = 0; 82 virtual QByteArray type() const = 0;
73 83
74 bool hasSubParts() const; 84 bool hasSubParts() const;
75 QList<Part> subParts() const; 85 QList<Part::Ptr> subParts() const;
76 Part partent() const; 86 Part parent() const;
87
88 virtual QVector<Signature> signatures() const;
89 virtual QVector<Encryption> encryptions() const;
77}; 90};
78 91
92//A structure element, that we need to reflect, that there is a Encryption starts
93// only add a new Encrption block to encryptions block
94class EncryptionPart : public Part
95{
96public:
97 QVector<Encryption> encryptions() const Q_DECL_OVERRIDE;
98 QByteArray type() const Q_DECL_OVERRIDE;
99};
100
101// A structure element, that we need to reflect, that there is a Signature starts
102// only add a new Signature block to signature block
103// With this we can a new Singature type like pep aka
104/*
105 * add a bodypartformatter, that returns a PEPSignaturePart with all signed subparts that are signed with pep.
106 * subclass Signature aka PEPSignature to reflect different way of properties of PEPSignatures.
107 */
108class SignaturePart : public Part
109{
110public:
111 QVector<Signature> signatures() const Q_DECL_OVERRIDE;
112 QByteArray type() const Q_DECL_OVERRIDE;
113};
114
115
116
117class TextPart : public Part
118{
119public:
120 QByteArray content() const;
121
122 //Use default charset
123 QString encodedContent() const;
124
125 // overwrite default charset with given charset
126 QString encodedContent(QByteArray charset) const;
127}
128
79/* 129/*
80 * A MessagePart that is based on a KMime::Content 130 * A MessagePart that is based on a KMime::Content
81 */ 131 */
82class MimePart : public Part 132class MimePart : public TextPart
83{ 133{
84public: 134public:
85 /** 135 /**
@@ -88,14 +138,12 @@ public:
88 enum Disposition { 138 enum Disposition {
89 Invalid, ///< Default, invalid value 139 Invalid, ///< Default, invalid value
90 Inline, ///< inline 140 Inline, ///< inline
91 Attachment, ///< attachment 141 Attachment ///< attachment
92 Parallel ///< parallel (invalid, do not use)
93 }; 142 };
94 143
95 // interessting header parts of a KMime::Content 144 // interessting header parts of a KMime::Content
96 QByteArray content() const;
97 QMimeType mimetype() const; 145 QMimeType mimetype() const;
98 Disposition dispossition() const 146 Disposition disposition() const;
99 QUrl label() const; 147 QUrl label() const;
100 QByteArray cid() const; 148 QByteArray cid() const;
101 QByteArray charset() const; 149 QByteArray charset() const;
@@ -123,7 +171,7 @@ private:
123 * for alternative, we are represating three messageparts 171 * for alternative, we are represating three messageparts
124 * - "headers" do we return?, we can use setType to make it possible to select and than return these headers 172 * - "headers" do we return?, we can use setType to make it possible to select and than return these headers
125 */ 173 */
126class ContentPart : public MimePart 174class MainContentPart : public MimePart
127{ 175{
128public: 176public:
129 enum Types { 177 enum Types {
@@ -132,14 +180,9 @@ public:
132 }; 180 };
133 Q_DECLARE_FLAGS(Types, Type) 181 Q_DECLARE_FLAGS(Types, Type)
134 182
135 QByteArray content(Content::Type ct) const; 183 QVector<TextPart> content(Content::Type ct) const;
136
137 // convert content with charset
138 QString content(Content::Type ct) const;
139 184
140 Content::Types availableContent() const; 185 Content::Types availableContent() const;
141 QVector<Signature> signature() const;
142 QVector<Encryption> encryption() const;
143 186
144 QByteArray type() const Q_DECL_OVERRIDE; 187 QByteArray type() const Q_DECL_OVERRIDE;
145 188
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")
23(Html) == cp1.availableContent() 23(Html) == cp1.availableContent()
24 24
25# alternative msg + attachment 25# alternative msg + attachment
26* ContentPart(html="HTML", plaintext="Text") => cp1 26* ContentPart(html=[TextPart("HTML"),], plaintext=[TextPart("Text"),]) => cp1
27* AttachmentPart => ap1 27* AttachmentPart => ap1
28 28
29(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages) 29(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
30(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages) 30(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
31 31
32(Html, PlainText) == cp1.availableContent() 32(Html, PlainText) == cp1.availableContent()
33"HTML" == cp1.content(Html) 33[TextPart("HTML"),] == cp1.content(Html)
34"text" == cp1.content(Plaintext) 34[TextPart("Text"),] == cp1.content(Plaintext)
35 35
36# alternative msg with GPGInline 36# alternative msg with GPGInlin
37* ContentPart(html="HTML", plaintext="Text cypted<foo>") => cp1 37* ContentPart(
38 * TextPart(text="Text") 38 plaintext=[TextPart("Text"), TextPart("foo", encryption=(enc1))],
39 * TextPart(text=foo, encryption=(enc1) 39 html=[TextPart("HTML"),]
40 ) => cp1
40 41
41(Html, PlainText) == cp1.availableContent() 42(Html, PlainText) == cp1.availableContent()
42 43
43TODO: but how to get plaintext/html content? 44[TextPart("HTML"),] == cp1.content(Html)
45[TextPart("Text"),TextPart("foo", encryption=(enc1))] == cp1.content(Plaintext)
46
44 47
45# encrypted msg (not encrypted/error) with unencrypted attachment 48# encrypted msg (not encrypted/error) with unencrypted attachment
46* EncryptionErrorPart => cp1 49* EncryptionErrorPart => cp1
@@ -59,16 +62,15 @@ TODO: but how to get plaintext/html content?
59(ap1, ap2) == collect<AttachmentParts>(select=NoEncapsulatedMessages) 62(ap1, ap2) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
60 63
61#INLINE GPG encrypted msg + attachment 64#INLINE GPG encrypted msg + attachment
62* ContentPart => cp1 65* ContentPart => cp1 with
63 * TextPart 66 plaintext=[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart]
64 * TextPart(encrytion = (enc1(rec1,rec2),))
65 * TextPart(signed = (sig1,))
66 * TextPart
67* AttachmentPart => ap1 67* AttachmentPart => ap1
68 68
69(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages) 69(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
70(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages) 70(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
71 71
72[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart] == cp1.content(Plaintext)
73
72#forwared encrypted msg + attachments 74#forwared encrypted msg + attachments
73* ContentPart => cp1 75* ContentPart => cp1
74* EncapsulatedPart => ep1 76* EncapsulatedPart => ep1
@@ -87,7 +89,7 @@ TODO: but how to get plaintext/html content?
87(ap1) = collect<AttachmentParts>(ep1, select=NoEncapsulatedMessages) 89(ap1) = collect<AttachmentParts>(ep1, select=NoEncapsulatedMessages)
88 90
89(cp1, cp2) == collect<ContentPart>() 91(cp1, cp2) == collect<ContentPart>()
90(ap1, ap2) == collect<AttachmentParts>() 92(ap1, ap2) == collect<AttachmentParts>()[TextPart, TextPart(encrytion = (enc1(rec1,rec2),)), TextPart(signed = (sig1,)), TextPart]
91 93
92 94
93# plaintext msg + attachment + cert 95# plaintext msg + attachment + cert