summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mime/mimetreeparser/messagepart.h
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/messagepart.h')
-rw-r--r--framework/src/domain/mime/mimetreeparser/messagepart.h386
1 files changed, 386 insertions, 0 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h
new file mode 100644
index 00000000..04fb30c3
--- /dev/null
+++ b/framework/src/domain/mime/mimetreeparser/messagepart.h
@@ -0,0 +1,386 @@
1/*
2 Copyright (c) 2015 Sandro Knauß <sknauss@kde.org>
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#ifndef __MIMETREEPARSER_MESSAGEPART_H__
21#define __MIMETREEPARSER_MESSAGEPART_H__
22
23#include "util.h"
24#include "enums.h"
25#include "partmetadata.h"
26
27#include <KMime/Message>
28
29#include <gpgme++/verificationresult.h>
30#include <gpgme++/decryptionresult.h>
31#include <gpgme++/importresult.h>
32
33#include <QString>
34#include <QSharedPointer>
35
36class QTextCodec;
37class PartPrivate;
38
39namespace GpgME
40{
41class ImportResult;
42}
43
44namespace QGpgME
45{
46class Protocol;
47}
48
49namespace KMime
50{
51class Content;
52}
53
54namespace MimeTreeParser
55{
56class ObjectTreeParser;
57class HTMLBlock;
58typedef QSharedPointer<HTMLBlock> HTMLBlockPtr;
59class CryptoBodyPartMemento;
60class MultiPartAlternativeBodyPartFormatter;
61
62class SignedMessagePart;
63class EncryptedMessagePart;
64
65class MessagePart : public QObject
66{
67 Q_OBJECT
68 Q_PROPERTY(bool attachment READ isAttachment)
69 Q_PROPERTY(bool root READ isRoot)
70 Q_PROPERTY(bool isHtml READ isHtml)
71 Q_PROPERTY(QString plaintextContent READ plaintextContent)
72 Q_PROPERTY(QString htmlContent READ htmlContent)
73public:
74 enum Disposition {
75 Inline,
76 Attachment,
77 Invalid
78 };
79 typedef QSharedPointer<MessagePart> Ptr;
80 MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node = nullptr);
81
82 virtual ~MessagePart();
83
84 virtual QString text() const;
85 void setText(const QString &text);
86 bool isAttachment() const;
87
88 void setIsRoot(bool root);
89 bool isRoot() const;
90
91 void setParentPart(MessagePart *parentPart);
92 MessagePart *parentPart() const;
93
94 virtual QString plaintextContent() const;
95 virtual QString htmlContent() const;
96
97 virtual bool isHtml() const;
98
99 QByteArray mimeType() const;
100 QByteArray charset() const;
101 QString filename() const;
102 Disposition disposition() const;
103 bool isText() const;
104 int error() const;
105 QString errorString() const;
106
107 PartMetaData *partMetaData();
108
109 void appendSubPart(const MessagePart::Ptr &messagePart);
110 const QVector<MessagePart::Ptr> &subParts() const;
111 bool hasSubParts() const;
112
113 KMime::Content *node() const;
114
115 QVector<SignedMessagePart*> signatures() const;
116 QVector<EncryptedMessagePart*> encryptions() const;
117
118protected:
119 void parseInternal(KMime::Content *node, bool onlyOneMimePart);
120 QString renderInternalText() const;
121
122 QString mText;
123 ObjectTreeParser *mOtp;
124 PartMetaData mMetaData;
125 MessagePart *mParentPart;
126 KMime::Content *mNode;
127
128private:
129 QVector<MessagePart::Ptr> mBlocks;
130 bool mRoot;
131};
132
133class MimeMessagePart : public MessagePart
134{
135 Q_OBJECT
136public:
137 typedef QSharedPointer<MimeMessagePart> Ptr;
138 MimeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart);
139 virtual ~MimeMessagePart();
140
141 QString text() const Q_DECL_OVERRIDE;
142
143 QString plaintextContent() const Q_DECL_OVERRIDE;
144 QString htmlContent() const Q_DECL_OVERRIDE;
145private:
146 friend class AlternativeMessagePart;
147 friend class ::PartPrivate;
148};
149
150class MessagePartList : public MessagePart
151{
152 Q_OBJECT
153public:
154 typedef QSharedPointer<MessagePartList> Ptr;
155 MessagePartList(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node = nullptr);
156 virtual ~MessagePartList();
157
158 QString text() const Q_DECL_OVERRIDE;
159
160 QString plaintextContent() const Q_DECL_OVERRIDE;
161 QString htmlContent() const Q_DECL_OVERRIDE;
162};
163
164enum IconType {
165 NoIcon = 0,
166 IconExternal,
167 IconInline
168};
169
170class TextMessagePart : public MessagePartList
171{
172 Q_OBJECT
173public:
174 typedef QSharedPointer<TextMessagePart> Ptr;
175 TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node);
176 virtual ~TextMessagePart();
177
178 KMMsgSignatureState signatureState() const;
179 KMMsgEncryptionState encryptionState() const;
180
181private:
182 void parseContent();
183
184 KMMsgSignatureState mSignatureState;
185 KMMsgEncryptionState mEncryptionState;
186
187 friend class DefaultRendererPrivate;
188 friend class ObjectTreeParser;
189 friend class ::PartPrivate;
190};
191
192class AttachmentMessagePart : public TextMessagePart
193{
194 Q_OBJECT
195public:
196 typedef QSharedPointer<AttachmentMessagePart> Ptr;
197 AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node);
198 virtual ~AttachmentMessagePart();
199
200};
201
202class HtmlMessagePart : public MessagePart
203{
204 Q_OBJECT
205public:
206 typedef QSharedPointer<HtmlMessagePart> Ptr;
207 HtmlMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node);
208 virtual ~HtmlMessagePart();
209
210 QString text() const Q_DECL_OVERRIDE;
211
212 bool isHtml() const Q_DECL_OVERRIDE;
213
214private:
215 QString mBodyHTML;
216 QByteArray mCharset;
217
218 friend class DefaultRendererPrivate;
219 friend class ::PartPrivate;
220};
221
222class AlternativeMessagePart : public MessagePart
223{
224 Q_OBJECT
225public:
226 typedef QSharedPointer<AlternativeMessagePart> Ptr;
227 AlternativeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, Util::HtmlMode preferredMode);
228 virtual ~AlternativeMessagePart();
229
230 QString text() const Q_DECL_OVERRIDE;
231
232 Util::HtmlMode preferredMode() const;
233
234 bool isHtml() const Q_DECL_OVERRIDE;
235
236 QString plaintextContent() const Q_DECL_OVERRIDE;
237 QString htmlContent() const Q_DECL_OVERRIDE;
238
239 QList<Util::HtmlMode> availableModes();
240private:
241 Util::HtmlMode mPreferredMode;
242
243 QMap<Util::HtmlMode, KMime::Content *> mChildNodes;
244 QMap<Util::HtmlMode, MimeMessagePart::Ptr> mChildParts;
245
246 friend class DefaultRendererPrivate;
247 friend class ObjectTreeParser;
248 friend class MultiPartAlternativeBodyPartFormatter;
249 friend class ::PartPrivate;
250};
251
252class CertMessagePart : public MessagePart
253{
254 Q_OBJECT
255public:
256 typedef QSharedPointer<CertMessagePart> Ptr;
257 CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const QGpgME::Protocol *cryptoProto);
258 virtual ~CertMessagePart();
259
260 QString text() const Q_DECL_OVERRIDE;
261 void import();
262
263private:
264 const QGpgME::Protocol *mCryptoProto;
265 friend class DefaultRendererPrivate;
266};
267
268class EncapsulatedRfc822MessagePart : public MessagePart
269{
270 Q_OBJECT
271public:
272 typedef QSharedPointer<EncapsulatedRfc822MessagePart> Ptr;
273 EncapsulatedRfc822MessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const KMime::Message::Ptr &message);
274 virtual ~EncapsulatedRfc822MessagePart();
275
276 QString text() const Q_DECL_OVERRIDE;
277private:
278 const KMime::Message::Ptr mMessage;
279
280 friend class DefaultRendererPrivate;
281};
282
283class EncryptedMessagePart : public MessagePart
284{
285 Q_OBJECT
286 Q_PROPERTY(bool isEncrypted READ isEncrypted)
287 Q_PROPERTY(bool passphraseError READ passphraseError)
288public:
289 typedef QSharedPointer<EncryptedMessagePart> Ptr;
290 EncryptedMessagePart(ObjectTreeParser *otp,
291 const QString &text,
292 const QGpgME::Protocol *cryptoProto,
293 const QString &fromAddress,
294 KMime::Content *node, KMime::Content *encryptedNode = nullptr);
295
296 virtual ~EncryptedMessagePart();
297
298 QString text() const Q_DECL_OVERRIDE;
299
300 void setIsEncrypted(bool encrypted);
301 bool isEncrypted() const;
302
303 bool isDecryptable() const;
304
305 bool passphraseError() const;
306
307 void startDecryption(const QByteArray &text, const QTextCodec *aCodec);
308 void startDecryption(KMime::Content *data = nullptr);
309
310 QByteArray mDecryptedData;
311
312 QString plaintextContent() const Q_DECL_OVERRIDE;
313 QString htmlContent() const Q_DECL_OVERRIDE;
314
315private:
316 /** Handles the dectyptioon of a given content
317 * returns true if the decryption was successfull
318 * if used in async mode, check if mMetaData.inProgress is true, it inicates a running decryption process.
319 */
320 bool okDecryptMIME(KMime::Content &data);
321
322protected:
323 bool mPassphraseError;
324 bool mNoSecKey;
325 const QGpgME::Protocol *mCryptoProto;
326 QString mFromAddress;
327 QByteArray mVerifiedText;
328 std::vector<GpgME::DecryptionResult::Recipient> mDecryptRecipients;
329 KMime::Content *mEncryptedNode;
330
331 friend class DefaultRendererPrivate;
332 friend class ::PartPrivate;
333};
334
335class SignedMessagePart : public MessagePart
336{
337 Q_OBJECT
338 Q_PROPERTY(bool isSigned READ isSigned)
339public:
340 typedef QSharedPointer<SignedMessagePart> Ptr;
341 SignedMessagePart(ObjectTreeParser *otp,
342 const QString &text,
343 const QGpgME::Protocol *cryptoProto,
344 const QString &fromAddress,
345 KMime::Content *node, KMime::Content *signedData);
346
347 virtual ~SignedMessagePart();
348
349 void setIsSigned(bool isSigned);
350 bool isSigned() const;
351
352 void startVerification(const QByteArray &text, const QTextCodec *aCodec);
353 void startVerificationDetached(const QByteArray &text, KMime::Content *textNode, const QByteArray &signature);
354 void startVerification();
355
356 QByteArray mDecryptedData;
357 std::vector<GpgME::Signature> mSignatures;
358
359 QString plaintextContent() const Q_DECL_OVERRIDE;
360 QString htmlContent() const Q_DECL_OVERRIDE;
361
362private:
363 /** Handles the verification of data
364 * If signature is empty it is handled as inline signature otherwise as detached signature mode.
365 * Returns true if the verfication was successfull and the block is signed.
366 * If used in async mode, check if mMetaData.inProgress is true, it inicates a running verification process.
367 */
368 bool okVerify(const QByteArray &data, const QByteArray &signature, KMime::Content *textNode);
369
370 void sigStatusToMetaData();
371
372 void setVerificationResult(const CryptoBodyPartMemento *m, KMime::Content *textNode);
373protected:
374 const QGpgME::Protocol *mCryptoProto;
375 QString mFromAddress;
376 QByteArray mVerifiedText;
377 KMime::Content *mSignedData;
378
379 friend EncryptedMessagePart;
380 friend class DefaultRendererPrivate;
381 friend class ::PartPrivate;
382};
383
384}
385
386#endif //__MIMETREEPARSER_MESSAGEPART_H__