diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-07-14 18:36:02 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-07-19 09:26:49 +0200 |
commit | 7815e94c52d092701804521eee850ac35d7f7781 (patch) | |
tree | e0131346db1f826e5c8052a00c98083a0f8733bb /framework/domain | |
parent | 234daf6935043775ffce6b5a3ca78e06f56fd81e (diff) | |
download | kube-7815e94c52d092701804521eee850ac35d7f7781.tar.gz kube-7815e94c52d092701804521eee850ac35d7f7781.zip |
updated
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/mimetreeparser/interface.h | 81 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/test.cpp | 30 |
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 | ||
25 | class Part; | 25 | class Part; |
26 | typedef std::shared_ptr<Part> Part::Ptr; | ||
26 | class EncryptionPart; | 27 | class EncryptionPart; |
28 | typedef std::shared_ptr<Part> EncryptionPart::Ptr; | ||
27 | class SignaturePart; | 29 | class SignaturePart; |
30 | typedef std::shared_ptr<Part> SignaturePart::Ptr; | ||
28 | 31 | ||
29 | class MimePart; | 32 | class MimePart; |
33 | typedef std::shared_ptr<Part> MimePart::Ptr; | ||
30 | class MimePartPrivate; | 34 | class MimePartPrivate; |
31 | 35 | ||
32 | class ContentPart; | 36 | class ContentPart; |
37 | typedef std::shared_ptr<Part> ContentPart::Ptr; | ||
33 | class ContentPartPrivate; | 38 | class ContentPartPrivate; |
34 | 39 | ||
35 | class EncryptionErrorPart; | 40 | class EncryptionErrorPart; |
41 | typedef std::shared_ptr<Part> EncryptionErrorPart::Ptr; | ||
36 | class EncryptionErrorPartPrivate; | 42 | class EncryptionErrorPartPrivate; |
37 | 43 | ||
38 | class AttachmentPart; | 44 | class AttachmentPart; |
45 | typedef std::shared_ptr<Part> AttachmentPart::Ptr; | ||
39 | class AttachmentPartPrivate; | 46 | class AttachmentPartPrivate; |
40 | 47 | ||
41 | class EncapsulatedPart; | 48 | class EncapsulatedPart; |
49 | typedef std::shared_ptr<Part> EncapsulatedPart::Ptr; | ||
42 | class EncapsulatedPart; | 50 | class EncapsulatedPart; |
43 | 51 | ||
44 | class CertPart; | 52 | class CertPart; |
45 | class CertPart; | 53 | typedef std::shared_ptr<Part> CertPart::Ptr; |
46 | 54 | ||
47 | class Key; | 55 | class Key; |
48 | class Signature; | 56 | class Signature; |
49 | class Encryption; | 57 | class Encryption; |
50 | 58 | ||
51 | class Parser; | 59 | class Parser; |
60 | typedef std::shared_ptr<Parser> Parser::Ptr; | ||
52 | class ParserPrivate; | 61 | class ParserPrivate; |
53 | 62 | ||
54 | class Parser | 63 | class Parser |
@@ -56,30 +65,71 @@ class Parser | |||
56 | public: | 65 | public: |
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 | ||
65 | private: | 74 | private: |
66 | std::unique_ptr<ParserPrivate> d; | 75 | std::unique_ptr<ParserPrivate> d; |
67 | }; | 76 | }; |
68 | 77 | ||
78 | |||
69 | class Part | 79 | class Part |
70 | { | 80 | { |
71 | public: | 81 | public: |
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 | ||
94 | class EncryptionPart : public Part | ||
95 | { | ||
96 | public: | ||
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 | */ | ||
108 | class SignaturePart : public Part | ||
109 | { | ||
110 | public: | ||
111 | QVector<Signature> signatures() const Q_DECL_OVERRIDE; | ||
112 | QByteArray type() const Q_DECL_OVERRIDE; | ||
113 | }; | ||
114 | |||
115 | |||
116 | |||
117 | class TextPart : public Part | ||
118 | { | ||
119 | public: | ||
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 | */ |
82 | class MimePart : public Part | 132 | class MimePart : public TextPart |
83 | { | 133 | { |
84 | public: | 134 | public: |
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 | */ |
126 | class ContentPart : public MimePart | 174 | class MainContentPart : public MimePart |
127 | { | 175 | { |
128 | public: | 176 | public: |
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 | ||
43 | TODO: 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 |