Messagelib

multipartencrypted.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Sandro Knauß <sknauss@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "multipartencrypted.h"
8
9#include "utils.h"
10
11#include "messagepart.h"
12#include "objecttreeparser.h"
13
14#include <KMime/Content>
15
16#include <QGpgME/Protocol>
17
18#include "mimetreeparser_debug.h"
19
20using namespace MimeTreeParser;
21
22const MultiPartEncryptedBodyPartFormatter *MultiPartEncryptedBodyPartFormatter::self;
23
24const Interface::BodyPartFormatter *MultiPartEncryptedBodyPartFormatter::create()
25{
26 if (!self) {
27 self = new MultiPartEncryptedBodyPartFormatter();
28 }
29 return self;
30}
31
32MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const
33{
34 KMime::Content *node = part.content();
35
36 if (node->contents().isEmpty()) {
37 Q_ASSERT(false);
38 return {};
39 }
40
41 const QGpgME::Protocol *useThisCryptProto = nullptr;
42
43 /*
44 ATTENTION: This code is to be replaced by the new 'auto-detect' feature. --------------------------------------
45 */
46 KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream");
47 if (data) {
48 useThisCryptProto = QGpgME::openpgp();
49 }
50 if (!data) {
51 data = findTypeInDirectChilds(node, "application/pkcs7-mime");
52 if (data) {
53 useThisCryptProto = QGpgME::smime();
54 }
55 }
56 /*
57 ---------------------------------------------------------------------------------------------------------------
58 */
59
60 if (!data) {
61 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
62 }
63
64 part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
65
67 new EncryptedMessagePart(part.objectTreeParser(), data->decodedText(), useThisCryptProto, part.nodeHelper()->fromAsString(data), node));
68 mp->setIsEncrypted(true);
69 mp->setDecryptMessage(part.source()->decryptMessage());
70 PartMetaData *messagePart(mp->partMetaData());
71
72 if (!part.source()->decryptMessage()) {
73 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
74 } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) {
75 part.nodeHelper()->registerOverrideHeader(data->parent(), mp);
76
77 // if we already have a decrypted node for part.objectTreeParser() encrypted node, don't do the decryption again
78 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, true));
79 } else {
80 mp->startDecryption(data);
81 qCDebug(MIMETREEPARSER_LOG) << "decrypted, signed?:" << messagePart->isSigned;
82
83 if (!messagePart->inProgress) {
84 part.nodeHelper()->registerOverrideHeader(data->parent(), mp);
85 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
86 }
87 }
88 return mp;
89}
QString decodedText(bool trimText, bool removeTrailingNewlines=false) const
Content * parent()
QList< Content * > contents()
interface of message body parts.
Definition bodypart.h:45
virtual MimeTreeParser::ObjectTreeParser * objectTreeParser() const =0
For making it easier to refactor, add objectTreeParser.
virtual MimeTreeParser::NodeHelper * nodeHelper() const =0
Ok, this is ugly, exposing the node helper here, but there is too much useful stuff in there for real...
virtual KMime::Content * content() const =0
Returns the KMime::Content node represented here.
virtual bool decryptMessage() const =0
Return true if an encrypted mail should be decrypted.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.