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.h327
1 files changed, 327 insertions, 0 deletions
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h
new file mode 100644
index 00000000..a9e394db
--- /dev/null
+++ b/framework/domain/mimetreeparser/interface.h
@@ -0,0 +1,327 @@
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 <QUrl>
23#include <QMimeType>
24
25class Part;
26class EncryptionPart;
27class SignaturePart;
28
29class MimePart;
30class MimePartPrivate;
31
32class ContentPart;
33class ContentPartPrivate;
34
35class EncryptionErrorPart;
36class EncryptionErrorPartPrivate;
37
38class AttachmentPart;
39class AttachmentPartPrivate;
40
41class EncapsulatedPart;
42class EncapsulatedPart;
43
44class CertPart;
45class CertPart;
46
47class Key;
48class Signature;
49class Encryption;
50
51class Parser;
52class ParserPrivate;
53
54class Parser
55{
56public:
57 Parser(const QByteArray &mimeMessage);
58
59 std::shared_ptr<Part> getPart(QUrl url);
60
61 QVector<std::shared_ptr<AttachmentPart>> collect<AttachmentPart>() const;
62 QVector<std::shared_ptr<ContentPart>> collect<ContentPart>() const;
63 QVector<std::shared_ptr<T>> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const std::shared_ptr<T> &)> filter) const;
64
65private:
66 std::unique_ptr<ParserPrivate> d;
67};
68
69class Part
70{
71public:
72 virtual QByteArray type() const = 0;
73
74 bool hasSubParts() const;
75 QList<Part> subParts() const;
76 Part partent() const;
77};
78
79/*
80 * A MessagePart that is based on a KMime::Content
81 */
82class MimePart : public Part
83{
84public:
85 /**
86 * Various possible values for the "Content-Disposition" header.
87 */
88 enum Disposition {
89 Invalid, ///< Default, invalid value
90 Inline, ///< inline
91 Attachment, ///< attachment
92 Parallel ///< parallel (invalid, do not use)
93 };
94
95 // interessting header parts of a KMime::Content
96 QByteArray content() const;
97 QMimeType mimetype() const;
98 Disposition dispossition() const
99 QUrl label() const;
100 QByteArray cid() const;
101 QByteArray charset() const;
102
103 // we wanna overrwrite the charset of the content, because some clients set the charset wrong
104 void setCharset(QByteArray charset);
105
106 // Unique identifier to ecactly this KMime::Content
107 QByteArray link() const;
108
109
110 QByteArray type() const Q_DECL_OVERRIDE;
111private:
112 std::unique_ptr<MimePartPrivate> d;
113};
114
115/*
116 * The main ContentPart
117 * is MimePart a good parent class?
118 * do we wanna need parts of the header of the connected KMime::Contents
119 * usecases:
120 * -
121 * for htmlonly it is representating only one MimePart (ok)
122 * for plaintext only also only one MimePart (ok)
123 * for alternative, we are represating three messageparts
124 * - "headers" do we return?, we can use setType to make it possible to select and than return these headers
125 */
126class ContentPart : public MimePart
127{
128public:
129 enum Types {
130 PlainText,
131 Html
132 };
133 Q_DECLARE_FLAGS(Types, Type)
134
135 QByteArray content(Content::Type ct) const;
136
137 // convert content with charset
138 QString content(Content::Type ct) const;
139
140 Content::Types availableContent() const;
141 QVector<Signature> signature() const;
142 QVector<Encryption> encryption() const;
143
144 QByteArray type() const Q_DECL_OVERRIDE;
145
146private:
147 std::unique_ptr<ContentPartPrivate> d;
148};
149
150Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPart::Type)
151
152class AttachmentPart : public MimePart
153{
154public:
155 QByteArray type() const Q_DECL_OVERRIDE;
156
157private:
158 std::unique_ptr<AttachmentPartPrivate> d;
159};
160
161/*
162 * Faild to decrypt part
163 * thigs liks this can happen:
164 * decryption in progress
165 * have not tried at all to decrypt
166 * wrong passphrase
167 * no private key
168 * cryptobackend is not configured correctly (no gpg available)
169 * -> S/Mime and PGP have different meaning in their errors
170 *
171 * Open Questions:
172 * - How to make the string translateable for multiple clients, so that multiple clients can show same error messages,
173 * that helps users to understand what is going on ?
174 * - Does openpgp have translations already?
175 */
176class EncryptionErrorPart : public Part
177{
178public:
179 Error errorId() const;
180
181 CryptoBackend cryptoBackend();
182
183 QByteArray type() const Q_DECL_OVERRIDE;
184
185private:
186 std::unique_ptr<EncryptionErrorPartPrivate> d;
187};
188
189/*
190 * we want to request complete headers like:
191 * from/to...
192 */
193
194class EncapsulatedPart :: public AttachmentPart
195{
196public:
197 QByteArray type() const Q_DECL_OVERRIDE;
198
199 QByteArray header<Type>();
200private:
201 std::unique_ptr<EncryptionErrorPartPrivate> d;
202};
203
204/*
205 * importing a cert GpgMe::ImportResult
206 * checking a cert (if it is a valid cert)
207 */
208
209class CertPart :: public AttachmentPart
210{
211public:
212 QByteArray type() const Q_DECL_OVERRIDE;
213
214 bool checkCert() const;
215 Status importCert() const;
216
217private:
218 std::unique_ptr<CertPartPrivate> d;
219};
220
221/*
222the ggme error class
223
224// class GPGMEPP_EXPORT ErrorImportResult
225{
226public:
227 Error() : mErr(0), mMessage() {}
228 explicit Error(unsigned int e) : mErr(e), mMessage() {}
229
230 const char *source() const;
231 const char *asString() const;
232
233 int code() const;
234 int sourceID() const;
235
236 bool isCanceled() const;
237
238 unsigned int encodedError() const
239 {
240 return mErr;
241 }
242 int toErrno() const;
243
244 static bool hasSystemError();
245 static Error fromSystemError(unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
246 static void setSystemError(gpg_err_code_t err);
247 static void setErrno(int err);
248 static Error fromErrno(int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
249 static Error fromCode(unsigned int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
250
251 GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(mErr &&!isCanceled())
252private:
253 unsigned int mErr;
254 mutable std::string mMessage;
255};
256*/
257
258/*
259 * a used smime/PGP key
260 * in the end we also need things like:
261 bool isRevokation() const;
262 bool isInvalid() const;
263 bool isExpired() const;
264
265 -> so we end up wrapping GpgME::Key
266 */
267class Key
268{
269 QString keyid() const;
270 QString name() const;
271 QString email() const;
272 QString comment() const;
273 QVector<QString> emails() const;
274 KeyTrust keyTrust() const;
275 CryptoBackend cryptoBackend() const;
276
277 std::vector<Key> subkeys();
278 Key parentkey() const;
279};
280
281class Signature
282{
283 Key key() const;
284 QDateTime creationDateTime() const;
285 QDateTime expirationTime() const;
286 bool neverExpires() const;
287
288 bool inProgress(); //if the verfication is inProgress
289
290 enum Validity {
291 Unknown, Undefined, Never, Marginal, Full, Ultimate
292 };
293 Validity validity() const;
294
295 // to determine if we need this in our usecase (email)
296 // GpgME::VerificationResult
297 enum Summary {
298 None = 0x000,
299 Valid = 0x001,
300 Green = 0x002,
301 Red = 0x004,
302 KeyRevoked = 0x008,
303 KeyExpired = 0x010,
304 SigExpired = 0x020,
305 KeyMissing = 0x040,
306 CrlMissing = 0x080,
307 CrlTooOld = 0x100,
308 BadPolicy = 0x200,
309 SysError = 0x400
310 };
311 Summary summary() const;
312
313 const char *policyURL() const;
314 GpgME::Notation notation(unsigned int index) const;
315 std::vector<GpgME::Notation> notations() const;
316
317};
318
319/*
320 * Normally the Keys for encryption are subkeys
321 * for clients the parentkeys are "more interessting", because they store the name, email etc.
322 * but a client may also wants show to what subkey the mail is really encrypted, an if this subkey isRevoked or something else
323 */
324class Encryption
325{
326 std::vector<Key> recipients() const;
327}; \ No newline at end of file