summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser/interface.h
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-07-18 15:35:07 +0200
committerSandro Knauß <sknauss@kde.org>2016-07-19 09:26:49 +0200
commit2fdddd2f795da4645dc9a48fee4865324143a21b (patch)
treee4127945653e9ead83d3cf7eab9ed507bbeb8470 /framework/domain/mimetreeparser/interface.h
parent7815e94c52d092701804521eee850ac35d7f7781 (diff)
downloadkube-2fdddd2f795da4645dc9a48fee4865324143a21b.tar.gz
kube-2fdddd2f795da4645dc9a48fee4865324143a21b.zip
first tests with mimetreeparser interface
Diffstat (limited to 'framework/domain/mimetreeparser/interface.h')
-rw-r--r--framework/domain/mimetreeparser/interface.h281
1 files changed, 119 insertions, 162 deletions
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h
index 320030b7..82f88e73 100644
--- a/framework/domain/mimetreeparser/interface.h
+++ b/framework/domain/mimetreeparser/interface.h
@@ -19,104 +19,70 @@
19 19
20#pragma once 20#pragma once
21 21
22#include <functional>
23#include <memory>
24
25#include <QDateTime>
22#include <QUrl> 26#include <QUrl>
23#include <QMimeType> 27#include <QMimeType>
24 28
25class Part; 29class Part;
26typedef std::shared_ptr<Part> Part::Ptr; 30class PartPrivate;
27class EncryptionPart;
28typedef std::shared_ptr<Part> EncryptionPart::Ptr;
29class SignaturePart;
30typedef std::shared_ptr<Part> SignaturePart::Ptr;
31 31
32class MimePart; 32class MimePart;
33typedef std::shared_ptr<Part> MimePart::Ptr;
34class MimePartPrivate; 33class MimePartPrivate;
35 34
36class ContentPart; 35class ContentPart;
37typedef std::shared_ptr<Part> ContentPart::Ptr;
38class ContentPartPrivate; 36class ContentPartPrivate;
39 37
40class EncryptionErrorPart; 38class EncryptionPart;
41typedef std::shared_ptr<Part> EncryptionErrorPart::Ptr; 39class EncryptionPartPrivate;
42class EncryptionErrorPartPrivate;
43 40
44class AttachmentPart; 41class AttachmentPart;
45typedef std::shared_ptr<Part> AttachmentPart::Ptr;
46class AttachmentPartPrivate; 42class AttachmentPartPrivate;
47 43
48class EncapsulatedPart; 44class EncapsulatedPart;
49typedef std::shared_ptr<Part> EncapsulatedPart::Ptr; 45class EncapsulatedPartPrivate;
50class EncapsulatedPart;
51 46
52class CertPart; 47class CertPart;
53typedef std::shared_ptr<Part> CertPart::Ptr; 48class CertPartPrivate;
49
50class Content;
51class ContentPrivate;
54 52
55class Key; 53class Key;
56class Signature; 54class Signature;
57class Encryption; 55class Encryption;
58 56
59class Parser; 57class Parser;
60typedef std::shared_ptr<Parser> Parser::Ptr;
61class ParserPrivate; 58class ParserPrivate;
62 59
63class Parser
64{
65public:
66 Parser(const QByteArray &mimeMessage);
67
68 Part::Ptr getPart(QUrl url);
69
70 QVector<AttachmentPart::Ptr> collect<AttachmentPart>() const;
71 QVector<ContentPart:Ptr> collect<ContentPart>() const;
72 QVector<T::Ptr> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const T::Ptr &)> filter) const;
73
74private:
75 std::unique_ptr<ParserPrivate> d;
76};
77
78
79class Part 60class Part
80{ 61{
81public: 62public:
82 virtual QByteArray type() const = 0; 63 typedef std::shared_ptr<Part> Ptr;
64 Part();
65 virtual QByteArray type() const;
83 66
84 bool hasSubParts() const; 67 bool hasSubParts() const;
85 QList<Part::Ptr> subParts() const; 68 QVector<Part::Ptr> subParts() const;
86 Part parent() const; 69 Part::Ptr parent() const;
87 70
88 virtual QVector<Signature> signatures() const; 71 virtual QVector<Signature> signatures() const;
89 virtual QVector<Encryption> encryptions() const; 72 virtual QVector<Encryption> encryptions() const;
73private:
74 std::unique_ptr<PartPrivate> d;
75 friend class ParserPrivate;
76 friend class PartPrivate;
90}; 77};
91 78
92//A structure element, that we need to reflect, that there is a Encryption starts 79class Content
93// only add a new Encrption block to encryptions block
94class EncryptionPart : public Part
95{
96public:
97 QVector<Encryption> encryptions() const Q_DECL_OVERRIDE;
98 QByteArray type() const Q_DECL_OVERRIDE;
99};
100
101// A structure element, that we need to reflect, that there is a Signature starts
102// only add a new Signature block to signature block
103// With this we can a new Singature type like pep aka
104/*
105 * add a bodypartformatter, that returns a PEPSignaturePart with all signed subparts that are signed with pep.
106 * subclass Signature aka PEPSignature to reflect different way of properties of PEPSignatures.
107 */
108class SignaturePart : public Part
109{ 80{
110public: 81public:
111 QVector<Signature> signatures() const Q_DECL_OVERRIDE; 82 typedef std::shared_ptr<Content> Ptr;
112 QByteArray type() const Q_DECL_OVERRIDE; 83 Content(const QByteArray &content, ContentPart *parent);
113}; 84 virtual ~Content();
114
115 85
116
117class TextPart : public Part
118{
119public:
120 QByteArray content() const; 86 QByteArray content() const;
121 87
122 //Use default charset 88 //Use default charset
@@ -124,14 +90,20 @@ public:
124 90
125 // overwrite default charset with given charset 91 // overwrite default charset with given charset
126 QString encodedContent(QByteArray charset) const; 92 QString encodedContent(QByteArray charset) const;
127} 93
94 virtual QVector<Signature> signatures() const;
95 virtual QVector<Encryption> encryptions() const;
96private:
97 std::unique_ptr<ContentPrivate> d;
98};
128 99
129/* 100/*
130 * A MessagePart that is based on a KMime::Content 101 * A MessagePart that is based on a KMime::Content
131 */ 102 */
132class MimePart : public TextPart 103class MimePart : public Part
133{ 104{
134public: 105public:
106 typedef std::shared_ptr<MimePart> Ptr;
135 /** 107 /**
136 * Various possible values for the "Content-Disposition" header. 108 * Various possible values for the "Content-Disposition" header.
137 */ 109 */
@@ -154,6 +126,13 @@ public:
154 // Unique identifier to ecactly this KMime::Content 126 // Unique identifier to ecactly this KMime::Content
155 QByteArray link() const; 127 QByteArray link() const;
156 128
129 QByteArray content() const;
130
131 //Use default charset
132 QString encodedContent() const;
133
134 // overwrite default charset with given charset
135 QString encodedContent(QByteArray charset) const;
157 136
158 QByteArray type() const Q_DECL_OVERRIDE; 137 QByteArray type() const Q_DECL_OVERRIDE;
159private: 138private:
@@ -171,77 +150,84 @@ private:
171 * for alternative, we are represating three messageparts 150 * for alternative, we are represating three messageparts
172 * - "headers" do we return?, we can use setType to make it possible to select and than return these headers 151 * - "headers" do we return?, we can use setType to make it possible to select and than return these headers
173 */ 152 */
174class MainContentPart : public MimePart 153class ContentPart : public Part
175{ 154{
176public: 155public:
177 enum Types { 156 typedef std::shared_ptr<ContentPart> Ptr;
178 PlainText, 157 enum Type {
179 Html 158 PlainText = 0x0001,
159 Html = 0x0002
180 }; 160 };
181 Q_DECLARE_FLAGS(Types, Type) 161 Q_DECLARE_FLAGS(Types, Type)
182 162
183 QVector<TextPart> content(Content::Type ct) const; 163 ContentPart();
164 virtual ~ContentPart();
165
166 QVector<Content> content(Type ct) const;
184 167
185 Content::Types availableContent() const; 168 Types availableContents() const;
186 169
187 QByteArray type() const Q_DECL_OVERRIDE; 170 QByteArray type() const Q_DECL_OVERRIDE;
188 171
189private: 172private:
190 std::unique_ptr<ContentPartPrivate> d; 173 std::unique_ptr<ContentPartPrivate> d;
174
175 friend class ParserPrivate;
191}; 176};
192 177
193Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Type) 178Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Types);
194 179
195class AttachmentPart : public MimePart 180class AttachmentPart : public MimePart
196{ 181{
197public: 182public:
183 typedef std::shared_ptr<AttachmentPart> Ptr;
198 QByteArray type() const Q_DECL_OVERRIDE; 184 QByteArray type() const Q_DECL_OVERRIDE;
199 185
200private: 186private:
201 std::unique_ptr<AttachmentPartPrivate> d; 187 std::unique_ptr<AttachmentPartPrivate> d;
188 friend class ParserPrivate;
202}; 189};
203 190
204/* 191/*
205 * Faild to decrypt part
206 * thigs liks this can happen:
207 * decryption in progress
208 * have not tried at all to decrypt
209 * wrong passphrase
210 * no private key
211 * cryptobackend is not configured correctly (no gpg available)
212 * -> S/Mime and PGP have different meaning in their errors
213 *
214 * Open Questions: 192 * Open Questions:
215 * - How to make the string translateable for multiple clients, so that multiple clients can show same error messages, 193 * - How to make the string translateable for multiple clients, so that multiple clients can show same error messages,
216 * that helps users to understand what is going on ? 194 * that helps users to understand what is going on ?
217 * - Does openpgp have translations already? 195 * - Does openpgp have translations already?
218 */ 196 */
219class EncryptionErrorPart : public Part 197class EncryptionError
220{ 198{
221public: 199public:
222 Error errorId() const; 200 int errorId() const;
223 201 QString errorString() const;
224 CryptoBackend cryptoBackend(); 202};
225 203
204class EncryptionPart : public MimePart
205{
206public:
207 typedef std::shared_ptr<EncryptionPart> Ptr;
226 QByteArray type() const Q_DECL_OVERRIDE; 208 QByteArray type() const Q_DECL_OVERRIDE;
227 209
210 EncryptionError error() const;
211
228private: 212private:
229 std::unique_ptr<EncryptionErrorPartPrivate> d; 213 std::unique_ptr<EncryptionPartPrivate> d;
230}; 214};
231 215
216
232/* 217/*
233 * we want to request complete headers like: 218 * we want to request complete headers like:
234 * from/to... 219 * from/to...
235 */ 220 */
236 221
237class EncapsulatedPart :: public AttachmentPart 222class EncapsulatedPart : public AttachmentPart
238{ 223{
239public: 224public:
225 typedef std::shared_ptr<EncapsulatedPart> Ptr;
240 QByteArray type() const Q_DECL_OVERRIDE; 226 QByteArray type() const Q_DECL_OVERRIDE;
241 227
242 QByteArray header<Type>(); 228 //template <class T> QByteArray header<T>();
243private: 229private:
244 std::unique_ptr<EncryptionErrorPartPrivate> d; 230 std::unique_ptr<EncapsulatedPartPrivate> d;
245}; 231};
246 232
247/* 233/*
@@ -249,64 +235,31 @@ private:
249 * checking a cert (if it is a valid cert) 235 * checking a cert (if it is a valid cert)
250 */ 236 */
251 237
252class CertPart :: public AttachmentPart 238class CertPart : public AttachmentPart
253{ 239{
254public: 240public:
241 typedef std::shared_ptr<CertPart> Ptr;
255 QByteArray type() const Q_DECL_OVERRIDE; 242 QByteArray type() const Q_DECL_OVERRIDE;
256 243
257 bool checkCert() const; 244 enum CertType {
258 Status importCert() const; 245 Pgp,
259 246 SMime
260private: 247 };
261 std::unique_ptr<CertPartPrivate> d;
262};
263
264/*
265the ggme error class
266
267// class GPGMEPP_EXPORT ErrorImportResult
268{
269public:
270 Error() : mErr(0), mMessage() {}
271 explicit Error(unsigned int e) : mErr(e), mMessage() {}
272
273 const char *source() const;
274 const char *asString() const;
275
276 int code() const;
277 int sourceID() const;
278
279 bool isCanceled() const;
280 248
281 unsigned int encodedError() const 249 enum CertSubType {
282 { 250 Public,
283 return mErr; 251 Private
284 } 252 };
285 int toErrno() const;
286 253
287 static bool hasSystemError(); 254 CertType certType() const;
288 static Error fromSystemError(unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); 255 CertSubType certSubType() const;
289 static void setSystemError(gpg_err_code_t err); 256 int keyLength() const;
290 static void setErrno(int err);
291 static Error fromErrno(int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
292 static Error fromCode(unsigned int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
293 257
294 GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(mErr &&!isCanceled())
295private: 258private:
296 unsigned int mErr; 259 std::unique_ptr<CertPartPrivate> d;
297 mutable std::string mMessage;
298}; 260};
299*/
300 261
301/*
302 * a used smime/PGP key
303 * in the end we also need things like:
304 bool isRevokation() const;
305 bool isInvalid() const;
306 bool isExpired() const;
307 262
308 -> so we end up wrapping GpgME::Key
309 */
310class Key 263class Key
311{ 264{
312 QString keyid() const; 265 QString keyid() const;
@@ -314,8 +267,14 @@ class Key
314 QString email() const; 267 QString email() const;
315 QString comment() const; 268 QString comment() const;
316 QVector<QString> emails() const; 269 QVector<QString> emails() const;
270 enum KeyTrust {
271 Unknown, Undefined, Never, Marginal, Full, Ultimate
272 };
317 KeyTrust keyTrust() const; 273 KeyTrust keyTrust() const;
318 CryptoBackend cryptoBackend() const; 274
275 bool isRevokation() const;
276 bool isInvalid() const;
277 bool isExpired() const;
319 278
320 std::vector<Key> subkeys(); 279 std::vector<Key> subkeys();
321 Key parentkey() const; 280 Key parentkey() const;
@@ -328,35 +287,7 @@ class Signature
328 QDateTime expirationTime() const; 287 QDateTime expirationTime() const;
329 bool neverExpires() const; 288 bool neverExpires() const;
330 289
331 bool inProgress(); //if the verfication is inProgress 290 //template <> StatusObject<SignatureVerificationResult> verify() const;
332
333 enum Validity {
334 Unknown, Undefined, Never, Marginal, Full, Ultimate
335 };
336 Validity validity() const;
337
338 // to determine if we need this in our usecase (email)
339 // GpgME::VerificationResult
340 enum Summary {
341 None = 0x000,
342 Valid = 0x001,
343 Green = 0x002,
344 Red = 0x004,
345 KeyRevoked = 0x008,
346 KeyExpired = 0x010,
347 SigExpired = 0x020,
348 KeyMissing = 0x040,
349 CrlMissing = 0x080,
350 CrlTooOld = 0x100,
351 BadPolicy = 0x200,
352 SysError = 0x400
353 };
354 Summary summary() const;
355
356 const char *policyURL() const;
357 GpgME::Notation notation(unsigned int index) const;
358 std::vector<GpgME::Notation> notations() const;
359
360}; 291};
361 292
362/* 293/*
@@ -367,4 +298,30 @@ class Signature
367class Encryption 298class Encryption
368{ 299{
369 std::vector<Key> recipients() const; 300 std::vector<Key> recipients() const;
301};
302
303class Parser
304{
305public:
306 typedef std::shared_ptr<Parser> Ptr;
307 Parser(const QByteArray &mimeMessage);
308 ~Parser();
309
310 Part::Ptr getPart(QUrl url);
311
312 //template <typename T> QVector<T::Ptr> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const T::Ptr &)> filter) const;
313 QVector<AttachmentPart::Ptr> collectAttachments(Part::Ptr start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const AttachmentPart::Ptr &)> filter) const;
314 ContentPart::Ptr collectContentPart(Part::Ptr start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const ContentPart::Ptr &)> filter) const;
315 ContentPart::Ptr collectContentPart(const Part::Ptr& start) const;
316 ContentPart::Ptr collectContentPart() const;
317 //template <> QVector<ContentPart::Ptr> collect<ContentPart>() const;
318
319 //template <> static StatusObject<SignatureVerificationResult> verifySignature(const Signature signature) const;
320 //template <> static StatusObject<Part> decrypt(const EncryptedPart part) const;
321
322signals:
323 void partsChanged();
324
325private:
326 std::unique_ptr<ParserPrivate> d;
370}; \ No newline at end of file 327}; \ No newline at end of file