diff --git a/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox new file mode 100644 index 0000000000000000000000000000000000000000..f5d083ff684e6ad29cbd6b7d0f1a22a192744cfa --- /dev/null +++ b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox @@ -0,0 +1,52 @@ +Received: from konqi +From: "Konqui" +To: "Bird" +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: +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_-- diff --git a/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox.html b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox.html new file mode 100644 index 0000000000000000000000000000000000000000..87f417f86f28c00261ccb9741d0dff9e4b9321ce --- /dev/null +++ b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox.html @@ -0,0 +1,40 @@ + + + + +
+ + +
+ + diff --git a/mimetreeparser/src/CMakeLists.txt b/mimetreeparser/src/CMakeLists.txt index bd93a4789bd506903de0b989adb363fb2ee08ac5..ba1b19c711a8fdccf1f7b2b3aaf0a0d14ff6336e 100644 --- a/mimetreeparser/src/CMakeLists.txt +++ b/mimetreeparser/src/CMakeLists.txt @@ -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 diff --git a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2d7d0f8cb92365a2e08564ed617e57b19081045 --- /dev/null +++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp @@ -0,0 +1,99 @@ +/* + Copyright (c) 2016 Sandro Knauß + + 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 + +#include + +#include + +#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(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; +} diff --git a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h new file mode 100644 index 0000000000000000000000000000000000000000..e858df0ef78a2f419713d368c552b19de71d72b4 --- /dev/null +++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h @@ -0,0 +1,41 @@ +/* + Copyright (c) 2016 Sandro Knauß + + 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 diff --git a/mimetreeparser/src/viewer/bodypartformatter.cpp b/mimetreeparser/src/viewer/bodypartformatter.cpp index 92703577c6736a127f96478eae681f7f357695c0..b6a9e649aeb64a355066ea719130cc02c68785ff 100644 --- a/mimetreeparser/src/viewer/bodypartformatter.cpp +++ b/mimetreeparser/src/viewer/bodypartformatter.cpp @@ -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());