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