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