Messagelib

applicationpgpencrypted.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 "applicationpgpencrypted.h"
8
9#include "utils.h"
10
11#include "messagepart.h"
12#include "objecttreeparser.h"
13
14#include <QGpgME/Protocol>
15
16#include <KMime/Content>
17
18#include "mimetreeparser_debug.h"
19
20using namespace MimeTreeParser;
21
22const ApplicationPGPEncryptedBodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::self;
23
24const Interface::BodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::create()
25{
26 if (!self) {
27 self = new ApplicationPGPEncryptedBodyPartFormatter();
28 }
29 return self;
30}
31
32MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const
33{
34 KMime::Content *node(part.content());
35
36 if (node->decodedContent().trimmed() != "Version: 1") {
37 qCWarning(MIMETREEPARSER_LOG) << "Unknown PGP Version String:" << node->decodedContent().trimmed();
38 }
39
40 if (!part.content()->parent()) {
41 return {};
42 }
43
44 KMime::Content *data = findTypeInDirectChilds(part.content()->parent(), "application/octet-stream");
45
46 if (!data) {
47 return {}; // new MimeMessagePart(part.objectTreeParser(), node, false));
48 }
49
50 part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
51
53 new EncryptedMessagePart(part.objectTreeParser(), data->decodedText(), QGpgME::openpgp(), part.nodeHelper()->fromAsString(data), node));
54 mp->setIsEncrypted(true);
55 mp->setDecryptMessage(part.source()->decryptMessage());
56 PartMetaData *messagePart(mp->partMetaData());
57 if (!part.source()->decryptMessage()) {
58 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
59 } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) {
60 part.nodeHelper()->registerOverrideHeader(data->parent(), mp);
61 // if we already have a decrypted node for this encrypted node, don't do the decryption again
62 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, false));
63 } else {
64 mp->startDecryption(data);
65 if (!messagePart->inProgress) {
66 part.nodeHelper()->registerOverrideHeader(data->parent(), mp);
67 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
68 if (messagePart->isDecryptable && messagePart->isSigned) {
69 part.nodeHelper()->setSignatureState(node, KMMsgFullySigned);
70 }
71 }
72 }
73 return mp;
74}
QString decodedText(bool trimText, bool removeTrailingNewlines=false) const
Content * parent()
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.