1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/*
Copyright (c) 2016 Sandro Knauß <knauss@kolabsystems.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#pragma once
#include <functional>
#include <memory>
#include <QDateTime>
#include <QUrl>
#include <QMimeType>
class Part;
class PartPrivate;
class MimePart;
class MimePartPrivate;
class ContentPart;
class ContentPartPrivate;
class EncryptionPart;
class EncryptionPartPrivate;
class AttachmentPart;
class AttachmentPartPrivate;
class EncapsulatedPart;
class EncapsulatedPartPrivate;
class CertPart;
class CertPartPrivate;
class Content;
class ContentPrivate;
class Key;
class Signature;
class Encryption;
class Parser;
class ParserPrivate;
class Part
{
public:
typedef std::shared_ptr<Part> Ptr;
Part();
virtual QByteArray type() const;
bool hasSubParts() const;
QVector<Part::Ptr> subParts() const;
Part::Ptr parent() const;
virtual QVector<Signature> signatures() const;
virtual QVector<Encryption> encryptions() const;
private:
std::unique_ptr<PartPrivate> d;
friend class ParserPrivate;
friend class PartPrivate;
};
class Content
{
public:
typedef std::shared_ptr<Content> Ptr;
Content(const QByteArray &content, ContentPart *parent);
virtual ~Content();
QByteArray content() const;
//Use default charset
QString encodedContent() const;
// overwrite default charset with given charset
QString encodedContent(QByteArray charset) const;
virtual QVector<Signature> signatures() const;
virtual QVector<Encryption> encryptions() const;
private:
std::unique_ptr<ContentPrivate> d;
};
/*
* A MessagePart that is based on a KMime::Content
*/
class MimePart : public Part
{
public:
typedef std::shared_ptr<MimePart> Ptr;
/**
* Various possible values for the "Content-Disposition" header.
*/
enum Disposition {
Invalid, ///< Default, invalid value
Inline, ///< inline
Attachment ///< attachment
};
// interessting header parts of a KMime::Content
QMimeType mimetype() const;
Disposition disposition() const;
QUrl label() const;
QByteArray cid() const;
QByteArray charset() const;
// we wanna overrwrite the charset of the content, because some clients set the charset wrong
void setCharset(QByteArray charset);
// Unique identifier to ecactly this KMime::Content
QByteArray link() const;
QByteArray content() const;
//Use default charset
QString encodedContent() const;
// overwrite default charset with given charset
QString encodedContent(QByteArray charset) const;
QByteArray type() const Q_DECL_OVERRIDE;
private:
std::unique_ptr<MimePartPrivate> d;
};
/*
* The main ContentPart
* is MimePart a good parent class?
* do we wanna need parts of the header of the connected KMime::Contents
* usecases:
* -
* for htmlonly it is representating only one MimePart (ok)
* for plaintext only also only one MimePart (ok)
* for alternative, we are represating three messageparts
* - "headers" do we return?, we can use setType to make it possible to select and than return these headers
*/
class ContentPart : public Part
{
public:
typedef std::shared_ptr<ContentPart> Ptr;
enum Type {
PlainText = 0x0001,
Html = 0x0002
};
Q_DECLARE_FLAGS(Types, Type)
ContentPart();
virtual ~ContentPart();
QVector<Content> content(Type ct) const;
Types availableContents() const;
QByteArray type() const Q_DECL_OVERRIDE;
private:
std::unique_ptr<ContentPartPrivate> d;
friend class ParserPrivate;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Types);
class AttachmentPart : public MimePart
{
public:
typedef std::shared_ptr<AttachmentPart> Ptr;
QByteArray type() const Q_DECL_OVERRIDE;
private:
std::unique_ptr<AttachmentPartPrivate> d;
friend class ParserPrivate;
};
/*
* Open Questions:
* - How to make the string translateable for multiple clients, so that multiple clients can show same error messages,
* that helps users to understand what is going on ?
* - Does openpgp have translations already?
*/
class EncryptionError
{
public:
int errorId() const;
QString errorString() const;
};
class EncryptionPart : public MimePart
{
public:
typedef std::shared_ptr<EncryptionPart> Ptr;
QByteArray type() const Q_DECL_OVERRIDE;
EncryptionError error() const;
private:
std::unique_ptr<EncryptionPartPrivate> d;
};
/*
* we want to request complete headers like:
* from/to...
*/
class EncapsulatedPart : public AttachmentPart
{
public:
typedef std::shared_ptr<EncapsulatedPart> Ptr;
QByteArray type() const Q_DECL_OVERRIDE;
//template <class T> QByteArray header<T>();
private:
std::unique_ptr<EncapsulatedPartPrivate> d;
};
/*
* importing a cert GpgMe::ImportResult
* checking a cert (if it is a valid cert)
*/
class CertPart : public AttachmentPart
{
public:
typedef std::shared_ptr<CertPart> Ptr;
QByteArray type() const Q_DECL_OVERRIDE;
enum CertType {
Pgp,
SMime
};
enum CertSubType {
Public,
Private
};
CertType certType() const;
CertSubType certSubType() const;
int keyLength() const;
private:
std::unique_ptr<CertPartPrivate> d;
};
class Key
{
QString keyid() const;
QString name() const;
QString email() const;
QString comment() const;
QVector<QString> emails() const;
enum KeyTrust {
Unknown, Undefined, Never, Marginal, Full, Ultimate
};
KeyTrust keyTrust() const;
bool isRevokation() const;
bool isInvalid() const;
bool isExpired() const;
std::vector<Key> subkeys();
Key parentkey() const;
};
class Signature
{
Key key() const;
QDateTime creationDateTime() const;
QDateTime expirationTime() const;
bool neverExpires() const;
//template <> StatusObject<SignatureVerificationResult> verify() const;
};
/*
* Normally the Keys for encryption are subkeys
* for clients the parentkeys are "more interessting", because they store the name, email etc.
* but a client may also wants show to what subkey the mail is really encrypted, an if this subkey isRevoked or something else
*/
class Encryption
{
std::vector<Key> recipients() const;
};
class Parser
{
public:
typedef std::shared_ptr<Parser> Ptr;
Parser(const QByteArray &mimeMessage);
~Parser();
Part::Ptr getPart(QUrl url);
//template <typename T> QVector<T::Ptr> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const T::Ptr &)> filter) const;
QVector<AttachmentPart::Ptr> collectAttachments(Part::Ptr start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const AttachmentPart::Ptr &)> filter) const;
ContentPart::Ptr collectContentPart(Part::Ptr start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const ContentPart::Ptr &)> filter) const;
ContentPart::Ptr collectContentPart(const Part::Ptr& start) const;
ContentPart::Ptr collectContentPart() const;
//template <> QVector<ContentPart::Ptr> collect<ContentPart>() const;
//template <> static StatusObject<SignatureVerificationResult> verifySignature(const Signature signature) const;
//template <> static StatusObject<Part> decrypt(const EncryptedPart part) const;
signals:
void partsChanged();
private:
std::unique_ptr<ParserPrivate> d;
};
|