diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-10-24 13:02:40 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-10-24 13:02:40 +0200 |
commit | 6aa695939b63fc7370e5eb80ecf7528aea1bd5e1 (patch) | |
tree | 91e7951411f541d7b71d64f15a2a38c6bbd7c577 /framework/domain/mimetreeparser/interface.h | |
parent | 9be2b6515cf538673babda8764219b9af9691f6f (diff) | |
parent | a93a649f34ffa794884019e05c57869bd3bd4672 (diff) | |
download | kube-6aa695939b63fc7370e5eb80ecf7528aea1bd5e1.tar.gz kube-6aa695939b63fc7370e5eb80ecf7528aea1bd5e1.zip |
Merge branch 'dev/mimetreeinterface' into develop
Diffstat (limited to 'framework/domain/mimetreeparser/interface.h')
-rw-r--r-- | framework/domain/mimetreeparser/interface.h | 381 |
1 files changed, 381 insertions, 0 deletions
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h new file mode 100644 index 00000000..3ff29d5d --- /dev/null +++ b/framework/domain/mimetreeparser/interface.h | |||
@@ -0,0 +1,381 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Sandro Knauß <knauss@kolabsystems.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <functional> | ||
23 | #include <memory> | ||
24 | |||
25 | #include <QDateTime> | ||
26 | #include <QUrl> | ||
27 | #include <QMimeType> | ||
28 | |||
29 | class Part; | ||
30 | class PartPrivate; | ||
31 | |||
32 | class MailMime; | ||
33 | class MailMimePrivate; | ||
34 | |||
35 | class AlternativePart; | ||
36 | class AlternativePartPrivate; | ||
37 | |||
38 | class SinglePart; | ||
39 | class SinglePartPrivate; | ||
40 | |||
41 | class EncryptionPart; | ||
42 | class EncryptionPartPrivate; | ||
43 | |||
44 | class EncapsulatedPart; | ||
45 | class EncapsulatedPartPrivate; | ||
46 | |||
47 | class Content; | ||
48 | class ContentPrivate; | ||
49 | |||
50 | class CertContent; | ||
51 | class CertContentPrivate; | ||
52 | |||
53 | class EncryptionError; | ||
54 | |||
55 | class Key; | ||
56 | class KeyPrivate; | ||
57 | class Signature; | ||
58 | class SignaturePrivate; | ||
59 | class Encryption; | ||
60 | class EncryptionPrivate; | ||
61 | |||
62 | typedef std::shared_ptr<Signature> SignaturePtr; | ||
63 | typedef std::shared_ptr<Encryption> EncryptionPtr; | ||
64 | |||
65 | class Parser; | ||
66 | class ParserPrivate; | ||
67 | |||
68 | /* | ||
69 | * A MessagePart that is based on a KMime::Content | ||
70 | */ | ||
71 | class MailMime | ||
72 | { | ||
73 | public: | ||
74 | typedef std::shared_ptr<MailMime> Ptr; | ||
75 | /** | ||
76 | * Various possible values for the "Content-Disposition" header. | ||
77 | */ | ||
78 | enum Disposition { | ||
79 | Invalid, ///< Default, invalid value | ||
80 | Inline, ///< inline | ||
81 | Attachment ///< attachment | ||
82 | }; | ||
83 | |||
84 | MailMime(); | ||
85 | |||
86 | // interessting header parts of a KMime::Content | ||
87 | QMimeType mimetype() const; | ||
88 | Disposition disposition() const; | ||
89 | QUrl label() const; | ||
90 | QByteArray cid() const; | ||
91 | QByteArray charset() const; | ||
92 | QString filename() const; | ||
93 | |||
94 | // Unique identifier to ecactly this KMime::Content | ||
95 | QByteArray link() const; | ||
96 | |||
97 | QByteArray content() const; | ||
98 | //Use default charset | ||
99 | QString encodedContent() const; | ||
100 | |||
101 | // overwrite default charset with given charset | ||
102 | QString encodedContent(QByteArray charset) const; | ||
103 | |||
104 | QByteArray decodedContent() const; | ||
105 | |||
106 | bool isFirstTextPart() const; | ||
107 | bool isFirstPart() const; | ||
108 | bool isTopLevelPart() const; | ||
109 | |||
110 | MailMime::Ptr parent() const; | ||
111 | |||
112 | private: | ||
113 | std::unique_ptr<MailMimePrivate> d; | ||
114 | |||
115 | friend class PartPrivate; | ||
116 | }; | ||
117 | |||
118 | class Content | ||
119 | { | ||
120 | public: | ||
121 | typedef std::shared_ptr<Content> Ptr; | ||
122 | Content(const QByteArray &content, Part *parent); | ||
123 | Content(ContentPrivate *d_ptr); | ||
124 | virtual ~Content(); | ||
125 | |||
126 | QByteArray content() const; | ||
127 | |||
128 | QByteArray charset() const; | ||
129 | |||
130 | //Use default charset | ||
131 | QString encodedContent() const; | ||
132 | |||
133 | // overwrite default charset with given charset | ||
134 | QString encodedContent(const QByteArray &charset) const; | ||
135 | |||
136 | QVector<SignaturePtr> signatures() const; | ||
137 | QVector<EncryptionPtr> encryptions() const; | ||
138 | MailMime::Ptr mailMime() const; | ||
139 | virtual QByteArray type() const; | ||
140 | Part* parent() const; | ||
141 | private: | ||
142 | std::unique_ptr<ContentPrivate> d; | ||
143 | }; | ||
144 | |||
145 | class PlainTextContent : public Content | ||
146 | { | ||
147 | public: | ||
148 | PlainTextContent(const QByteArray &content, Part *parent); | ||
149 | PlainTextContent(ContentPrivate *d_ptr); | ||
150 | QByteArray type() const Q_DECL_OVERRIDE; | ||
151 | }; | ||
152 | |||
153 | class HtmlContent : public Content | ||
154 | { | ||
155 | public: | ||
156 | HtmlContent(const QByteArray &content, Part *parent); | ||
157 | HtmlContent(ContentPrivate* d_ptr); | ||
158 | QByteArray type() const Q_DECL_OVERRIDE; | ||
159 | }; | ||
160 | |||
161 | /* | ||
162 | * importing a cert GpgMe::ImportResult | ||
163 | * checking a cert (if it is a valid cert) | ||
164 | */ | ||
165 | |||
166 | class CertContent : public Content | ||
167 | { | ||
168 | public: | ||
169 | typedef std::shared_ptr<CertContent> Ptr; | ||
170 | CertContent(const QByteArray &content, Part *parent); | ||
171 | |||
172 | QByteArray type() const Q_DECL_OVERRIDE; | ||
173 | enum CertType { | ||
174 | Pgp, | ||
175 | SMime | ||
176 | }; | ||
177 | |||
178 | enum CertSubType { | ||
179 | Public, | ||
180 | Private | ||
181 | }; | ||
182 | |||
183 | CertType certType() const; | ||
184 | CertSubType certSubType() const; | ||
185 | int keyLength() const; | ||
186 | |||
187 | private: | ||
188 | std::unique_ptr<CertContentPrivate> d; | ||
189 | }; | ||
190 | |||
191 | class Part | ||
192 | { | ||
193 | public: | ||
194 | typedef std::shared_ptr<Part> Ptr; | ||
195 | Part(); | ||
196 | virtual QByteArray type() const; | ||
197 | |||
198 | virtual QVector<QByteArray> availableContents() const; | ||
199 | virtual QVector<Content::Ptr> content(const QByteArray& ct) const; | ||
200 | QVector<Content::Ptr> content() const; | ||
201 | |||
202 | bool hasSubParts() const; | ||
203 | QVector<Part::Ptr> subParts() const; | ||
204 | Part *parent() const; | ||
205 | |||
206 | QVector<SignaturePtr> signatures() const; | ||
207 | QVector<EncryptionPtr> encryptions() const; | ||
208 | virtual MailMime::Ptr mailMime() const; | ||
209 | protected: | ||
210 | std::unique_ptr<PartPrivate> d; | ||
211 | private: | ||
212 | friend class ParserPrivate; | ||
213 | friend class PartPrivate; | ||
214 | }; | ||
215 | |||
216 | class AlternativePart : public Part | ||
217 | { | ||
218 | public: | ||
219 | typedef std::shared_ptr<AlternativePart> Ptr; | ||
220 | |||
221 | AlternativePart(); | ||
222 | virtual ~AlternativePart(); | ||
223 | |||
224 | QVector<QByteArray> availableContents() const Q_DECL_OVERRIDE; | ||
225 | QVector<Content::Ptr> content(const QByteArray& ct) const Q_DECL_OVERRIDE; | ||
226 | |||
227 | QByteArray type() const Q_DECL_OVERRIDE; | ||
228 | |||
229 | private: | ||
230 | PartPrivate *reachParentD() const; | ||
231 | std::unique_ptr<AlternativePartPrivate> d; | ||
232 | |||
233 | friend class ParserPrivate; | ||
234 | friend class AlternativePartPrivate; | ||
235 | }; | ||
236 | |||
237 | class SinglePart : public Part | ||
238 | { | ||
239 | public: | ||
240 | typedef std::shared_ptr<SinglePart> Ptr; | ||
241 | |||
242 | SinglePart(); | ||
243 | virtual ~SinglePart(); | ||
244 | |||
245 | QVector<Content::Ptr> content(const QByteArray& ct) const Q_DECL_OVERRIDE; | ||
246 | QVector<QByteArray> availableContents() const Q_DECL_OVERRIDE; | ||
247 | |||
248 | QByteArray type() const Q_DECL_OVERRIDE; | ||
249 | private: | ||
250 | PartPrivate *reachParentD() const; | ||
251 | std::unique_ptr<SinglePartPrivate> d; | ||
252 | |||
253 | friend class ParserPrivate; | ||
254 | friend class SinglePartPrivate; | ||
255 | }; | ||
256 | |||
257 | |||
258 | class EncryptionPart : public Part | ||
259 | { | ||
260 | public: | ||
261 | typedef std::shared_ptr<EncryptionPart> Ptr; | ||
262 | QByteArray type() const Q_DECL_OVERRIDE; | ||
263 | |||
264 | EncryptionError error() const; | ||
265 | private: | ||
266 | std::unique_ptr<EncryptionPartPrivate> d; | ||
267 | }; | ||
268 | |||
269 | /* | ||
270 | * we want to request complete headers like: | ||
271 | * from/to... | ||
272 | */ | ||
273 | |||
274 | class EncapsulatedPart : public SinglePart | ||
275 | { | ||
276 | public: | ||
277 | typedef std::shared_ptr<EncapsulatedPart> Ptr; | ||
278 | QByteArray type() const Q_DECL_OVERRIDE; | ||
279 | |||
280 | //template <class T> QByteArray header<T>(); | ||
281 | private: | ||
282 | std::unique_ptr<EncapsulatedPartPrivate> d; | ||
283 | }; | ||
284 | |||
285 | class EncryptionError | ||
286 | { | ||
287 | public: | ||
288 | int errorId() const; | ||
289 | QString errorString() const; | ||
290 | }; | ||
291 | |||
292 | class Key | ||
293 | { | ||
294 | public: | ||
295 | typedef std::shared_ptr<Key> Ptr; | ||
296 | Key(); | ||
297 | Key(KeyPrivate *); | ||
298 | ~Key(); | ||
299 | |||
300 | QString keyid() const; | ||
301 | QString name() const; | ||
302 | QString email() const; | ||
303 | QString comment() const; | ||
304 | QVector<QString> emails() const; | ||
305 | enum KeyTrust { | ||
306 | Unknown, Undefined, Never, Marginal, Full, Ultimate | ||
307 | }; | ||
308 | KeyTrust keyTrust() const; | ||
309 | |||
310 | bool isRevokation() const; | ||
311 | bool isInvalid() const; | ||
312 | bool isExpired() const; | ||
313 | |||
314 | std::vector<Key::Ptr> subkeys(); | ||
315 | Key parentkey() const; | ||
316 | private: | ||
317 | std::unique_ptr<KeyPrivate> d; | ||
318 | }; | ||
319 | |||
320 | class Signature | ||
321 | { | ||
322 | public: | ||
323 | typedef std::shared_ptr<Signature> Ptr; | ||
324 | Signature(); | ||
325 | Signature(SignaturePrivate *); | ||
326 | ~Signature(); | ||
327 | |||
328 | Key::Ptr key() const; | ||
329 | QDateTime creationDateTime() const; | ||
330 | QDateTime expirationDateTime() const; | ||
331 | bool neverExpires() const; | ||
332 | |||
333 | //template <> StatusObject<SignatureVerificationResult> verify() const; | ||
334 | private: | ||
335 | std::unique_ptr<SignaturePrivate> d; | ||
336 | }; | ||
337 | |||
338 | /* | ||
339 | * Normally the Keys for encryption are subkeys | ||
340 | * for clients the parentkeys are "more interessting", because they store the name, email etc. | ||
341 | * but a client may also wants show to what subkey the mail is really encrypted, an if this subkey isRevoked or something else | ||
342 | */ | ||
343 | class Encryption | ||
344 | { | ||
345 | public: | ||
346 | typedef std::shared_ptr<Encryption> Ptr; | ||
347 | Encryption(); | ||
348 | Encryption(EncryptionPrivate *); | ||
349 | ~Encryption(); | ||
350 | std::vector<Key::Ptr> recipients() const; | ||
351 | private: | ||
352 | std::unique_ptr<EncryptionPrivate> d; | ||
353 | }; | ||
354 | |||
355 | class Parser | ||
356 | { | ||
357 | public: | ||
358 | typedef std::shared_ptr<Parser> Ptr; | ||
359 | Parser(const QByteArray &mimeMessage); | ||
360 | ~Parser(); | ||
361 | |||
362 | Part::Ptr getPart(const QUrl &url); | ||
363 | |||
364 | QVector<Part::Ptr> collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const Content::Ptr &)> filter) const; | ||
365 | Part::Ptr find(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select) const; | ||
366 | QVector<Part::Ptr> collectContentParts() const; | ||
367 | QVector<Part::Ptr> collectAttachmentParts() const; | ||
368 | //template <> QVector<ContentPart::Ptr> collect<ContentPart>() const; | ||
369 | |||
370 | //template <> static StatusObject<SignatureVerificationResult> verifySignature(const Signature signature) const; | ||
371 | //template <> static StatusObject<Part> decrypt(const EncryptedPart part) const; | ||
372 | |||
373 | signals: | ||
374 | void partsChanged(); | ||
375 | |||
376 | private: | ||
377 | std::unique_ptr<ParserPrivate> d; | ||
378 | |||
379 | friend class InterfaceTest; | ||
380 | }; | ||
381 | |||