Commit db5cb449 authored by Sandro Knauß's avatar Sandro Knauß

Add new BodyFormatter for application/pgp-encrypted

FIXED-IN: 5.3
BUG: 360910
parent fc451549
Received: from konqi
From: "Konqui" <konqi@example.org>
To: "Bird" <bird@example.org>
Subject: gpg problem 1/2
Date: Tue, 22 Mar 2016 17:09:18 +0100
Message-ID: <123456@example.org>
Accept-Language: de-DE, en-US
Content-Language: en-US
Content-Type: multipart/mixed;
boundary="_003_55514CDCA78D430384C5F0810DF10C7Adsmpgde_"
MIME-Version: 1.0
--_003_55514CDCA78D430384C5F0810DF10C7Adsmpgde_
Content-Type: text/plain; charset="us-ascii"
--_003_55514CDCA78D430384C5F0810DF10C7Adsmpgde_
Content-Type: application/pgp-encrypted;
name="PGPMIME Versions Identification"
Content-Description: PGP/MIME Versions Identification
Content-Disposition: attachment; filename="PGPMIME Versions Identification";
size=77; creation-date="Tue, 22 Mar 2016 16:09:18 GMT";
modification-date="Tue, 22 Mar 2016 16:09:18 GMT"
Content-ID: <D82BB3DF89947646AD6C4C24C8C54BAC@example.org>
Content-Transfer-Encoding: base64
VmVyc2lvbjogMQ0NCg==
--_003_55514CDCA78D430384C5F0810DF10C7Adsmpgde_
Content-Type: application/octet-stream; name="encrypted.asc"
Content-Description: OpenPGP encrypted message.asc
Content-Disposition: attachment; filename="encrypted.asc"; size=872;
creation-date="Tue, 22 Mar 2016 16:09:18 GMT";
modification-date="Tue, 22 Mar 2016 16:09:18 GMT"
Content-ID: <58A712E65AB1824AB726904A6449178F@example.org>
Content-Transfer-Encoding: base64
LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tClZlcnNpb246IEdudVBHIHYxCkNvbW1lbnQ6IFVz
aW5nIEdudVBHIHdpdGggSWNlZG92ZSAtIGh0dHA6Ly93d3cuZW5pZ21haWwubmV0LwoKaEl3REdK
bHRoVFQ3b3EwQkEvOU50TExYYmlJSlZTNnBPeW53RWVTem5yUUs3a1lWbGE4Uk00My8vSkVDQ2tH
SgphekVhU0J6bmFiQnY2ZXBhRm1RdFZITE1YbENiWm5NbVc5bG95cVBCZk1vQW1zNmtLS0JkRy9q
cWh1czg5aVhFCitzZVhuZ0MyMzNWYS9nWk1iMkR4T3FJb2tWTmZqOXRwUjd4UTh3Uy9qSFREaUxO
YzFHT1FDN2t1NDJ6MmJOTEEKSVFGUkQvcWJCRno4OWhVNHdQNGNZb0F5c09uRURvakZyc3JuQ2lk
VEhKT0pybmRNNlBQVXRIL2pRQ3lmci9FRwoydFNwSndZS3ZtVDZseTN5cWFHTEJ0UlBJeGl2K2RN
ZSs3eXcwdDQwcWJqdnZhVEdhdkVyRUJKRUtYNWVXYlROCi9zamFqSHBVSHFzNlNJaU1oZUg5ZHIr
V2Z6Rk9OdFZiUEVnR1JtT0VSaGxnVGwvbkxvODZBWnBqSnJvSUdLSkoKdFRIQ2NvUUdBV0crTjd3
ckNFMVJ4UjBra01zNG5Sb3pqMFRMdTZaeVhNcytIMDYzTWV3VFBOeE5BaVFUMU5iaQp1ZEtXbWZM
Qmx4bjA2cCtKRHpVS3hqOFBGd09iZGJ4VHZBQ3piQXZCWTFhSE1RPT0KPW1MbDMKLS0tLS1FTkQg
UEdQIE1FU1NBR0UtLS0tLQoK
--_003_55514CDCA78D430384C5F0810DF10C7Adsmpgde_--
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div style="position: relative; word-wrap: break-word">
<a name="att"/>
<div id="attachmentDiv">
<a name="att1"/>
<div id="attachmentDiv1">
</div>
<a name="att2"/>
<div id="attachmentDiv2">
<table cellspacing="1" cellpadding="1" class="encr">
<tr class="encrH">
<td dir="ltr">Encrypted message</td>
</tr>
<tr class="encrB">
<td>
<div style="position: relative; word-wrap: break-word">
<a name="att"/>
<div id="attachmentDiv">
<a name="att1"/>
<div id="attachmentDiv1">
<div class="noquote">
<div dir="ltr">test</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="encrH">
<td dir="ltr">End of encrypted message</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
......@@ -9,6 +9,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libmimetreeparser\")
include_directories(${GPGME_INCLUDES})
set(libmimetreeparser_main_SRCS
bodyformatter/applicationpgpencrypted.cpp
bodyformatter/mailman.cpp
bodyformatter/utils.cpp
interfaces/bodypartformatter.cpp
......
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "applicationpgpencrypted.h"
#include "utils.h"
#include "viewer/objecttreeparser.h"
#include "viewer/messagepart.h"
#include <Libkleo/CryptoBackendFactory>
#include <MessageCore/NodeHelper>
#include <KMime/Content>
#include "mimetreeparser_debug.h"
using namespace MimeTreeParser;
const ApplicationPGPEncryptedBodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::self;
const Interface::BodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::create() {
if ( !self ) {
self = new ApplicationPGPEncryptedBodyPartFormatter();
}
return self;
}
Interface::BodyPartFormatter::Result ApplicationPGPEncryptedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const {
Q_UNUSED(writer)
const auto p = process(*part);
const auto mp = static_cast<MessagePart *>(p.data());
if (mp) {
mp->html(false);
return Ok;
}
return Failed;
}
Interface::MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const {
KMime::Content *node (part.content());
if (node->decodedContent().trimmed() != "Version: 1") {
qCWarning(MIMETREEPARSER_LOG) << "Unknown PGP Version String:" << node->decodedContent().trimmed();
}
KMime::Content *data = findType(part.content(), "application/octet-stream", false, true);
if (!data) {
return MessagePart::Ptr(); //new MimeMessagePart(part.objectTreeParser(), node, false));
}
KMime::Content *dataChild = MessageCore::NodeHelper::firstChild(data);
if (dataChild) {
Q_ASSERT(false);
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), dataChild, false));
}
part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
CryptoMessagePart::Ptr mp(new CryptoMessagePart(part.objectTreeParser(),
data->decodedText(), Kleo::CryptoBackendFactory::instance()->openpgp(),
NodeHelper::fromAsString(data), node));
mp->setIsEncrypted(true);
mp->setDecryptMessage(part.source()->decryptMessage());
PartMetaData *messagePart(mp->partMetaData());
if (!part.source()->decryptMessage()) {
part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
} else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) {
// if we already have a decrypted node for this encrypted node, don't do the decryption again
return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, part.objectTreeParser()->showOnlyOneMimePart()));
} else {
mp->startDecryption(data);
if (!messagePart->inProgress) {
part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
if (messagePart->isDecryptable && messagePart->isSigned) {
part.nodeHelper()->setSignatureState(node, KMMsgFullySigned);
}
}
}
return mp;
}
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__
#define __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__
#include "interfaces/bodypartformatter.h"
#include "interfaces/bodypart.h"
namespace MimeTreeParser
{
class ApplicationPGPEncryptedBodyPartFormatter : public Interface::BodyPartFormatter
{
static const ApplicationPGPEncryptedBodyPartFormatter *self;
public:
Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE;
Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE;
using Interface::BodyPartFormatter::format;
static const Interface::BodyPartFormatter *create();
};
}
#endif
\ No newline at end of file
......@@ -31,6 +31,7 @@
#include "mimetreeparser_debug.h"
#include "bodyformatter/applicationpgpencrypted.h"
#include "bodyformatter/mailman.h"
#include "interfaces/bodypartformatter.h"
......@@ -208,6 +209,7 @@ void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_
insert("application", "pgp", ApplicationPgpBodyPartFormatter::create());
insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create());
insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create());
insert("application", "*", AnyTypeBodyPartFormatter::create());
insert("text", "html", TextHtmlBodyPartFormatter::create());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment