[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [messagelib] mimetreeparser: Add new BodyFormatter for application/pgp-encrypted
From:       Sandro_Knauß <sknauss () kde ! org>
Date:       2016-03-28 14:45:00
Message-ID: E1akYPc-0000yg-DH () scm ! kde ! org
[Download RAW message or body]

Git commit db5cb4496d8a029d39374791751a96263a052ddc by Sandro Knauß.
Committed on 28/03/2016 at 14:42.
Pushed by knauss into branch 'master'.

Add new BodyFormatter for application/pgp-encrypted

FIXED-IN: 5.3
BUG: 360910

A  +52   -0    mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox
A  +40   -0    mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox.html
M  +1    -0    mimetreeparser/src/CMakeLists.txt
A  +99   -0    mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp     \
[License: LGPL (v2+)] A  +41   -0    \
mimetreeparser/src/bodyformatter/applicationpgpencrypted.h     [License: LGPL (v2+)] \
M  +2    -0    mimetreeparser/src/viewer/bodypartformatter.cpp

http://commits.kde.org/messagelib/db5cb4496d8a029d39374791751a96263a052ddc

diff --git a/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox \
b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox new file mode 100644
index 0000000..f5d083f
--- /dev/null
+++ b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox
@@ -0,0 +1,52 @@
+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_--
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 0000000..87f417f
--- /dev/null
+++ b/mimetreeparser/autotests/data/openpgp-encrypted-applemail.mbox.html
@@ -0,0 +1,40 @@
+<?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>
diff --git a/mimetreeparser/src/CMakeLists.txt b/mimetreeparser/src/CMakeLists.txt
index bd93a47..ba1b19c 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 0000000..f2d7d0f
--- /dev/null
+++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.cpp
@@ -0,0 +1,99 @@
+/*
+   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;
+}
diff --git a/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h \
b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h new file mode 100644
index 0000000..e858df0
--- /dev/null
+++ b/mimetreeparser/src/bodyformatter/applicationpgpencrypted.h
@@ -0,0 +1,41 @@
+/*
+   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
diff --git a/mimetreeparser/src/viewer/bodypartformatter.cpp \
b/mimetreeparser/src/viewer/bodypartformatter.cpp index 9270357..b6a9e64 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());


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic