summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser/interface.h
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/mimetreeparser/interface.h')
-rw-r--r--framework/domain/mimetreeparser/interface.h381
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
29class Part;
30class PartPrivate;
31
32class MailMime;
33class MailMimePrivate;
34
35class AlternativePart;
36class AlternativePartPrivate;
37
38class SinglePart;
39class SinglePartPrivate;
40
41class EncryptionPart;
42class EncryptionPartPrivate;
43
44class EncapsulatedPart;
45class EncapsulatedPartPrivate;
46
47class Content;
48class ContentPrivate;
49
50class CertContent;
51class CertContentPrivate;
52
53class EncryptionError;
54
55class Key;
56class KeyPrivate;
57class Signature;
58class SignaturePrivate;
59class Encryption;
60class EncryptionPrivate;
61
62typedef std::shared_ptr<Signature> SignaturePtr;
63typedef std::shared_ptr<Encryption> EncryptionPtr;
64
65class Parser;
66class ParserPrivate;
67
68/*
69 * A MessagePart that is based on a KMime::Content
70 */
71class MailMime
72{
73public:
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
112private:
113 std::unique_ptr<MailMimePrivate> d;
114
115 friend class PartPrivate;
116};
117
118class Content
119{
120public:
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;
141private:
142 std::unique_ptr<ContentPrivate> d;
143};
144
145class PlainTextContent : public Content
146{
147public:
148 PlainTextContent(const QByteArray &content, Part *parent);
149 PlainTextContent(ContentPrivate *d_ptr);
150 QByteArray type() const Q_DECL_OVERRIDE;
151};
152
153class HtmlContent : public Content
154{
155public:
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
166class CertContent : public Content
167{
168public:
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
187private:
188 std::unique_ptr<CertContentPrivate> d;
189};
190
191class Part
192{
193public:
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;
209protected:
210 std::unique_ptr<PartPrivate> d;
211private:
212 friend class ParserPrivate;
213 friend class PartPrivate;
214};
215
216class AlternativePart : public Part
217{
218public:
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
229private:
230 PartPrivate *reachParentD() const;
231 std::unique_ptr<AlternativePartPrivate> d;
232
233 friend class ParserPrivate;
234 friend class AlternativePartPrivate;
235};
236
237class 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;
249private:
250 PartPrivate *reachParentD() const;
251 std::unique_ptr<SinglePartPrivate> d;
252
253 friend class ParserPrivate;
254 friend class SinglePartPrivate;
255};
256
257
258class EncryptionPart : public Part
259{
260public:
261 typedef std::shared_ptr<EncryptionPart> Ptr;
262 QByteArray type() const Q_DECL_OVERRIDE;
263
264 EncryptionError error() const;
265private:
266 std::unique_ptr<EncryptionPartPrivate> d;
267};
268
269/*
270 * we want to request complete headers like:
271 * from/to...
272 */
273
274class EncapsulatedPart : public SinglePart
275{
276public:
277 typedef std::shared_ptr<EncapsulatedPart> Ptr;
278 QByteArray type() const Q_DECL_OVERRIDE;
279
280 //template <class T> QByteArray header<T>();
281private:
282 std::unique_ptr<EncapsulatedPartPrivate> d;
283};
284
285class EncryptionError
286{
287public:
288 int errorId() const;
289 QString errorString() const;
290};
291
292class Key
293{
294public:
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;
316private:
317 std::unique_ptr<KeyPrivate> d;
318};
319
320class Signature
321{
322public:
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 */
343class Encryption
344{
345public:
346 typedef std::shared_ptr<Encryption> Ptr;
347 Encryption();
348 Encryption(EncryptionPrivate *);
349 ~Encryption();
350 std::vector<Key::Ptr> recipients() const;
351private:
352 std::unique_ptr<EncryptionPrivate> d;
353};
354
355class Parser
356{
357public:
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
373signals:
374 void partsChanged();
375
376private:
377 std::unique_ptr<ParserPrivate> d;
378
379 friend class InterfaceTest;
380};
381