diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-07-18 15:35:07 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-07-19 09:26:49 +0200 |
commit | 2fdddd2f795da4645dc9a48fee4865324143a21b (patch) | |
tree | e4127945653e9ead83d3cf7eab9ed507bbeb8470 /framework/domain/mimetreeparser/interface.h | |
parent | 7815e94c52d092701804521eee850ac35d7f7781 (diff) | |
download | kube-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.h | 281 |
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 | ||
25 | class Part; | 29 | class Part; |
26 | typedef std::shared_ptr<Part> Part::Ptr; | 30 | class PartPrivate; |
27 | class EncryptionPart; | ||
28 | typedef std::shared_ptr<Part> EncryptionPart::Ptr; | ||
29 | class SignaturePart; | ||
30 | typedef std::shared_ptr<Part> SignaturePart::Ptr; | ||
31 | 31 | ||
32 | class MimePart; | 32 | class MimePart; |
33 | typedef std::shared_ptr<Part> MimePart::Ptr; | ||
34 | class MimePartPrivate; | 33 | class MimePartPrivate; |
35 | 34 | ||
36 | class ContentPart; | 35 | class ContentPart; |
37 | typedef std::shared_ptr<Part> ContentPart::Ptr; | ||
38 | class ContentPartPrivate; | 36 | class ContentPartPrivate; |
39 | 37 | ||
40 | class EncryptionErrorPart; | 38 | class EncryptionPart; |
41 | typedef std::shared_ptr<Part> EncryptionErrorPart::Ptr; | 39 | class EncryptionPartPrivate; |
42 | class EncryptionErrorPartPrivate; | ||
43 | 40 | ||
44 | class AttachmentPart; | 41 | class AttachmentPart; |
45 | typedef std::shared_ptr<Part> AttachmentPart::Ptr; | ||
46 | class AttachmentPartPrivate; | 42 | class AttachmentPartPrivate; |
47 | 43 | ||
48 | class EncapsulatedPart; | 44 | class EncapsulatedPart; |
49 | typedef std::shared_ptr<Part> EncapsulatedPart::Ptr; | 45 | class EncapsulatedPartPrivate; |
50 | class EncapsulatedPart; | ||
51 | 46 | ||
52 | class CertPart; | 47 | class CertPart; |
53 | typedef std::shared_ptr<Part> CertPart::Ptr; | 48 | class CertPartPrivate; |
49 | |||
50 | class Content; | ||
51 | class ContentPrivate; | ||
54 | 52 | ||
55 | class Key; | 53 | class Key; |
56 | class Signature; | 54 | class Signature; |
57 | class Encryption; | 55 | class Encryption; |
58 | 56 | ||
59 | class Parser; | 57 | class Parser; |
60 | typedef std::shared_ptr<Parser> Parser::Ptr; | ||
61 | class ParserPrivate; | 58 | class ParserPrivate; |
62 | 59 | ||
63 | class Parser | ||
64 | { | ||
65 | public: | ||
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 | |||
74 | private: | ||
75 | std::unique_ptr<ParserPrivate> d; | ||
76 | }; | ||
77 | |||
78 | |||
79 | class Part | 60 | class Part |
80 | { | 61 | { |
81 | public: | 62 | public: |
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; |
73 | private: | ||
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 | 79 | class Content |
93 | // only add a new Encrption block to encryptions block | ||
94 | class EncryptionPart : public Part | ||
95 | { | ||
96 | public: | ||
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 | */ | ||
108 | class SignaturePart : public Part | ||
109 | { | 80 | { |
110 | public: | 81 | public: |
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 | |||
117 | class TextPart : public Part | ||
118 | { | ||
119 | public: | ||
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; | ||
96 | private: | ||
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 | */ |
132 | class MimePart : public TextPart | 103 | class MimePart : public Part |
133 | { | 104 | { |
134 | public: | 105 | public: |
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; |
159 | private: | 138 | private: |
@@ -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 | */ |
174 | class MainContentPart : public MimePart | 153 | class ContentPart : public Part |
175 | { | 154 | { |
176 | public: | 155 | public: |
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 | ||
189 | private: | 172 | private: |
190 | std::unique_ptr<ContentPartPrivate> d; | 173 | std::unique_ptr<ContentPartPrivate> d; |
174 | |||
175 | friend class ParserPrivate; | ||
191 | }; | 176 | }; |
192 | 177 | ||
193 | Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Type) | 178 | Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Types); |
194 | 179 | ||
195 | class AttachmentPart : public MimePart | 180 | class AttachmentPart : public MimePart |
196 | { | 181 | { |
197 | public: | 182 | public: |
183 | typedef std::shared_ptr<AttachmentPart> Ptr; | ||
198 | QByteArray type() const Q_DECL_OVERRIDE; | 184 | QByteArray type() const Q_DECL_OVERRIDE; |
199 | 185 | ||
200 | private: | 186 | private: |
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 | */ |
219 | class EncryptionErrorPart : public Part | 197 | class EncryptionError |
220 | { | 198 | { |
221 | public: | 199 | public: |
222 | Error errorId() const; | 200 | int errorId() const; |
223 | 201 | QString errorString() const; | |
224 | CryptoBackend cryptoBackend(); | 202 | }; |
225 | 203 | ||
204 | class EncryptionPart : public MimePart | ||
205 | { | ||
206 | public: | ||
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 | |||
228 | private: | 212 | private: |
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 | ||
237 | class EncapsulatedPart :: public AttachmentPart | 222 | class EncapsulatedPart : public AttachmentPart |
238 | { | 223 | { |
239 | public: | 224 | public: |
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>(); |
243 | private: | 229 | private: |
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 | ||
252 | class CertPart :: public AttachmentPart | 238 | class CertPart : public AttachmentPart |
253 | { | 239 | { |
254 | public: | 240 | public: |
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 | |
260 | private: | 247 | }; |
261 | std::unique_ptr<CertPartPrivate> d; | ||
262 | }; | ||
263 | |||
264 | /* | ||
265 | the ggme error class | ||
266 | |||
267 | // class GPGMEPP_EXPORT ErrorImportResult | ||
268 | { | ||
269 | public: | ||
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()) | ||
295 | private: | 258 | private: |
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 | */ | ||
310 | class Key | 263 | class 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 | |||
367 | class Encryption | 298 | class Encryption |
368 | { | 299 | { |
369 | std::vector<Key> recipients() const; | 300 | std::vector<Key> recipients() const; |
301 | }; | ||
302 | |||
303 | class Parser | ||
304 | { | ||
305 | public: | ||
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 | |||
322 | signals: | ||
323 | void partsChanged(); | ||
324 | |||
325 | private: | ||
326 | std::unique_ptr<ParserPrivate> d; | ||
370 | }; \ No newline at end of file | 327 | }; \ No newline at end of file |