diff options
Diffstat (limited to 'framework/domain/mimetreeparser/interface.h')
-rw-r--r-- | framework/domain/mimetreeparser/interface.h | 368 |
1 files changed, 368 insertions, 0 deletions
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h new file mode 100644 index 00000000..7eadc311 --- /dev/null +++ b/framework/domain/mimetreeparser/interface.h | |||
@@ -0,0 +1,368 @@ | |||
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 Signature; | ||
57 | class SignaturePrivate; | ||
58 | class Encryption; | ||
59 | class EncryptionPrivate; | ||
60 | |||
61 | typedef std::shared_ptr<Signature> SignaturePtr; | ||
62 | typedef std::shared_ptr<Encryption> EncryptionPtr; | ||
63 | |||
64 | class Parser; | ||
65 | class ParserPrivate; | ||
66 | |||
67 | /* | ||
68 | * A MessagePart that is based on a KMime::Content | ||
69 | */ | ||
70 | class MailMime | ||
71 | { | ||
72 | public: | ||
73 | typedef std::shared_ptr<MailMime> Ptr; | ||
74 | /** | ||
75 | * Various possible values for the "Content-Disposition" header. | ||
76 | */ | ||
77 | enum Disposition { | ||
78 | Invalid, ///< Default, invalid value | ||
79 | Inline, ///< inline | ||
80 | Attachment ///< attachment | ||
81 | }; | ||
82 | |||
83 | MailMime(); | ||
84 | |||
85 | // interessting header parts of a KMime::Content | ||
86 | QMimeType mimetype() const; | ||
87 | Disposition disposition() const; | ||
88 | QUrl label() const; | ||
89 | QByteArray cid() const; | ||
90 | QByteArray charset() const; | ||
91 | QString filename() const; | ||
92 | |||
93 | // Unique identifier to ecactly this KMime::Content | ||
94 | QByteArray link() const; | ||
95 | |||
96 | QByteArray content() const; | ||
97 | //Use default charset | ||
98 | QString encodedContent() const; | ||
99 | |||
100 | // overwrite default charset with given charset | ||
101 | QString encodedContent(QByteArray charset) const; | ||
102 | |||
103 | bool isFirstTextPart() const; | ||
104 | bool isTopLevelPart() const; | ||
105 | |||
106 | private: | ||
107 | std::unique_ptr<MailMimePrivate> d; | ||
108 | |||
109 | friend class PartPrivate; | ||
110 | }; | ||
111 | |||
112 | class Content | ||
113 | { | ||
114 | public: | ||
115 | typedef std::shared_ptr<Content> Ptr; | ||
116 | Content(const QByteArray &content, Part *parent); | ||
117 | Content(ContentPrivate *d_ptr); | ||
118 | virtual ~Content(); | ||
119 | |||
120 | QByteArray content() const; | ||
121 | |||
122 | QByteArray charset() const; | ||
123 | |||
124 | //Use default charset | ||
125 | QString encodedContent() const; | ||
126 | |||
127 | // overwrite default charset with given charset | ||
128 | QString encodedContent(QByteArray charset) const; | ||
129 | |||
130 | QVector<SignaturePtr> signatures() const; | ||
131 | QVector<EncryptionPtr> encryptions() const; | ||
132 | MailMime::Ptr mailMime() const; | ||
133 | virtual QByteArray type() const; | ||
134 | Part* parent() const; | ||
135 | private: | ||
136 | std::unique_ptr<ContentPrivate> d; | ||
137 | }; | ||
138 | |||
139 | class PlainTextContent : public Content | ||
140 | { | ||
141 | public: | ||
142 | PlainTextContent(const QByteArray &content, Part *parent); | ||
143 | PlainTextContent(ContentPrivate *d_ptr); | ||
144 | QByteArray type() const Q_DECL_OVERRIDE; | ||
145 | }; | ||
146 | |||
147 | class HtmlContent : public Content | ||
148 | { | ||
149 | public: | ||
150 | HtmlContent(const QByteArray &content, Part *parent); | ||
151 | HtmlContent(ContentPrivate* d_ptr); | ||
152 | QByteArray type() const Q_DECL_OVERRIDE; | ||
153 | }; | ||
154 | |||
155 | /* | ||
156 | * importing a cert GpgMe::ImportResult | ||
157 | * checking a cert (if it is a valid cert) | ||
158 | */ | ||
159 | |||
160 | class CertContent : public Content | ||
161 | { | ||
162 | public: | ||
163 | typedef std::shared_ptr<CertContent> Ptr; | ||
164 | CertContent(const QByteArray &content, Part *parent); | ||
165 | |||
166 | QByteArray type() const Q_DECL_OVERRIDE; | ||
167 | enum CertType { | ||
168 | Pgp, | ||
169 | SMime | ||
170 | }; | ||
171 | |||
172 | enum CertSubType { | ||
173 | Public, | ||
174 | Private | ||
175 | }; | ||
176 | |||
177 | CertType certType() const; | ||
178 | CertSubType certSubType() const; | ||
179 | int keyLength() const; | ||
180 | |||
181 | private: | ||
182 | std::unique_ptr<CertContentPrivate> d; | ||
183 | }; | ||
184 | |||
185 | class Part | ||
186 | { | ||
187 | public: | ||
188 | typedef std::shared_ptr<Part> Ptr; | ||
189 | Part(); | ||
190 | virtual QByteArray type() const; | ||
191 | |||
192 | virtual QVector<QByteArray> availableContents() const; | ||
193 | virtual QVector<Content::Ptr> content(const QByteArray& ct) const; | ||
194 | QVector<Content::Ptr> content() const; | ||
195 | |||
196 | bool hasSubParts() const; | ||
197 | QVector<Part::Ptr> subParts() const; | ||
198 | Part *parent() const; | ||
199 | |||
200 | QVector<SignaturePtr> signatures() const; | ||
201 | QVector<EncryptionPtr> encryptions() const; | ||
202 | virtual MailMime::Ptr mailMime() const; | ||
203 | protected: | ||
204 | std::unique_ptr<PartPrivate> d; | ||
205 | private: | ||
206 | friend class ParserPrivate; | ||
207 | friend class PartPrivate; | ||
208 | }; | ||
209 | |||
210 | class AlternativePart : public Part | ||
211 | { | ||
212 | public: | ||
213 | typedef std::shared_ptr<AlternativePart> Ptr; | ||
214 | |||
215 | AlternativePart(); | ||
216 | virtual ~AlternativePart(); | ||
217 | |||
218 | QVector<QByteArray> availableContents() const Q_DECL_OVERRIDE; | ||
219 | QVector<Content::Ptr> content(const QByteArray& ct) const Q_DECL_OVERRIDE; | ||
220 | |||
221 | QByteArray type() const Q_DECL_OVERRIDE; | ||
222 | |||
223 | private: | ||
224 | PartPrivate *reachParentD() const; | ||
225 | std::unique_ptr<AlternativePartPrivate> d; | ||
226 | |||
227 | friend class ParserPrivate; | ||
228 | friend class AlternativePartPrivate; | ||
229 | }; | ||
230 | |||
231 | class SinglePart : public Part | ||
232 | { | ||
233 | public: | ||
234 | typedef std::shared_ptr<SinglePart> Ptr; | ||
235 | |||
236 | SinglePart(); | ||
237 | virtual ~SinglePart(); | ||
238 | |||
239 | QVector<Content::Ptr> content(const QByteArray& ct) const Q_DECL_OVERRIDE; | ||
240 | QVector<QByteArray> availableContents() const Q_DECL_OVERRIDE; | ||
241 | |||
242 | QByteArray type() const Q_DECL_OVERRIDE; | ||
243 | private: | ||
244 | PartPrivate *reachParentD() const; | ||
245 | std::unique_ptr<SinglePartPrivate> d; | ||
246 | |||
247 | friend class ParserPrivate; | ||
248 | friend class SinglePartPrivate; | ||
249 | }; | ||
250 | |||
251 | |||
252 | class EncryptionPart : public Part | ||
253 | { | ||
254 | public: | ||
255 | typedef std::shared_ptr<EncryptionPart> Ptr; | ||
256 | QByteArray type() const Q_DECL_OVERRIDE; | ||
257 | |||
258 | EncryptionError error() const; | ||
259 | private: | ||
260 | std::unique_ptr<EncryptionPartPrivate> d; | ||
261 | }; | ||
262 | |||
263 | |||
264 | /* | ||
265 | * we want to request complete headers like: | ||
266 | * from/to... | ||
267 | */ | ||
268 | |||
269 | class EncapsulatedPart : public SinglePart | ||
270 | { | ||
271 | public: | ||
272 | typedef std::shared_ptr<EncapsulatedPart> Ptr; | ||
273 | QByteArray type() const Q_DECL_OVERRIDE; | ||
274 | |||
275 | //template <class T> QByteArray header<T>(); | ||
276 | private: | ||
277 | std::unique_ptr<EncapsulatedPartPrivate> d; | ||
278 | }; | ||
279 | |||
280 | class EncryptionError | ||
281 | { | ||
282 | public: | ||
283 | int errorId() const; | ||
284 | QString errorString() const; | ||
285 | }; | ||
286 | |||
287 | class Key | ||
288 | { | ||
289 | QString keyid() const; | ||
290 | QString name() const; | ||
291 | QString email() const; | ||
292 | QString comment() const; | ||
293 | QVector<QString> emails() const; | ||
294 | enum KeyTrust { | ||
295 | Unknown, Undefined, Never, Marginal, Full, Ultimate | ||
296 | }; | ||
297 | KeyTrust keyTrust() const; | ||
298 | |||
299 | bool isRevokation() const; | ||
300 | bool isInvalid() const; | ||
301 | bool isExpired() const; | ||
302 | |||
303 | std::vector<Key> subkeys(); | ||
304 | Key parentkey() const; | ||
305 | }; | ||
306 | |||
307 | class Signature | ||
308 | { | ||
309 | public: | ||
310 | typedef std::shared_ptr<Signature> Ptr; | ||
311 | Signature(); | ||
312 | Signature(SignaturePrivate *); | ||
313 | ~Signature(); | ||
314 | |||
315 | Key key() const; | ||
316 | QDateTime creationDateTime() const; | ||
317 | QDateTime expirationTime() const; | ||
318 | bool neverExpires() const; | ||
319 | |||
320 | //template <> StatusObject<SignatureVerificationResult> verify() const; | ||
321 | private: | ||
322 | std::unique_ptr<SignaturePrivate> d; | ||
323 | }; | ||
324 | |||
325 | /* | ||
326 | * Normally the Keys for encryption are subkeys | ||
327 | * for clients the parentkeys are "more interessting", because they store the name, email etc. | ||
328 | * but a client may also wants show to what subkey the mail is really encrypted, an if this subkey isRevoked or something else | ||
329 | */ | ||
330 | class Encryption | ||
331 | { | ||
332 | public: | ||
333 | typedef std::shared_ptr<Encryption> Ptr; | ||
334 | Encryption(); | ||
335 | Encryption(EncryptionPrivate *); | ||
336 | ~Encryption(); | ||
337 | std::vector<Key> recipients() const; | ||
338 | private: | ||
339 | std::unique_ptr<EncryptionPrivate> d; | ||
340 | }; | ||
341 | |||
342 | class Parser | ||
343 | { | ||
344 | public: | ||
345 | typedef std::shared_ptr<Parser> Ptr; | ||
346 | Parser(const QByteArray &mimeMessage); | ||
347 | ~Parser(); | ||
348 | |||
349 | Part::Ptr getPart(QUrl url); | ||
350 | QUrl getPart(const QByteArray &cid); | ||
351 | |||
352 | QVector<Part::Ptr> collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const Content::Ptr &)> filter) const; | ||
353 | QVector<Part::Ptr> collectContentParts() const; | ||
354 | QVector<Part::Ptr> collectAttachmentParts() const; | ||
355 | //template <> QVector<ContentPart::Ptr> collect<ContentPart>() const; | ||
356 | |||
357 | //template <> static StatusObject<SignatureVerificationResult> verifySignature(const Signature signature) const; | ||
358 | //template <> static StatusObject<Part> decrypt(const EncryptedPart part) const; | ||
359 | |||
360 | signals: | ||
361 | void partsChanged(); | ||
362 | |||
363 | private: | ||
364 | std::unique_ptr<ParserPrivate> d; | ||
365 | |||
366 | friend class InterfaceTest; | ||
367 | }; | ||
368 | |||