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