summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <[email protected]>2015-10-09 11:27:47 +0200
committerSandro Knauß <[email protected]>2015-10-14 00:16:34 +0200
commita4214c0b6f781a522d2125bcc88fa859deeea1ec (patch)
tree6787e3c3274204bc8c1102dcbb7bdb938689c156
parent1c309899f32cbb8c9e96a9c2a4212f710a8ae75e (diff)
replace processMessageRfc822Subtype with a propper Formatter&renderer
-rw-r--r--messageviewer/src/viewer/bodypartformatter.cpp45
-rw-r--r--messageviewer/src/viewer/messagepart.cpp64
-rw-r--r--messageviewer/src/viewer/messagepart.h16
-rw-r--r--messageviewer/src/viewer/objecttreeparser.cpp150
-rw-r--r--messageviewer/src/viewer/objecttreeparser.h15
5 files changed, 156 insertions, 134 deletions
diff --git a/messageviewer/src/viewer/bodypartformatter.cpp b/messageviewer/src/viewer/bodypartformatter.cpp
index 58eb20a..c7ed856 100644
--- a/messageviewer/src/viewer/bodypartformatter.cpp
+++ b/messageviewer/src/viewer/bodypartformatter.cpp
@@ -32,10 +32,12 @@
#include "bodypartformatter.h"
#include "messageviewer_debug.h"
#include "viewer/bodypartformatterfactory_p.h"
+#include "viewer/attachmentstrategy.h"
#include "interfaces/bodypartformatter.h"
#include "interfaces/bodypart.h"
#include "viewer/objecttreeparser.h"
+#include "messagepart.h"
#include <kmime/kmime_content.h>
@@ -104,6 +106,47 @@ public:
const ImageTypeBodyPartFormatter *ImageTypeBodyPartFormatter::self = 0;
+class MessageRfc822BodyPartFormatter
+ : public BodyPartFormatter
+ , public MessageViewer::Interface::BodyPartFormatter
+{
+ static const MessageRfc822BodyPartFormatter * self;
+public:
+ bool process(ObjectTreeParser *, KMime::Content *, ProcessResult &) const Q_DECL_OVERRIDE;
+ MessageViewer::Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE;
+ using MessageViewer::Interface::BodyPartFormatter::format;
+ static const ::BodyPartFormatter *create();
+};
+
+const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self;
+
+const ::BodyPartFormatter *MessageRfc822BodyPartFormatter::create() {
+ if (!self) {
+ self = new MessageRfc822BodyPartFormatter();
+ }
+ return self;
+}
+
+bool MessageRfc822BodyPartFormatter::process(ObjectTreeParser * otp, KMime::Content * node, ProcessResult & result) const
+{
+ PartMetaData metaData;
+ const KMime::Message::Ptr message = node->bodyAsMessage();
+ EncapsulatedRfc822MessagePart mp(otp, &metaData, node, message);
+
+ if (!otp->attachmentStrategy()->inlineNestedMessages() && !otp->showOnlyOneMimePart()) {
+ return false;
+ } else {
+ mp.html(true);
+ return true;
+ }
+}
+
+MessageViewer::Interface::BodyPartFormatter::Result MessageRfc822BodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const
+{
+ bool ret = process(part->objectTreeParser(), part->content(), *part->processResult());
+ return ret ? Ok: Failed;
+}
+
#define CREATE_BODY_PART_FORMATTER(subtype) \
class subtype##BodyPartFormatter \
: public BodyPartFormatter \
@@ -142,8 +185,6 @@ CREATE_BODY_PART_FORMATTER(ApplicationPkcs7Mime)
CREATE_BODY_PART_FORMATTER(ApplicationChiasmusText)
//CREATE_BODY_PART_FORMATTER(ApplicationPgp)
-CREATE_BODY_PART_FORMATTER(MessageRfc822)
-
CREATE_BODY_PART_FORMATTER(MultiPartMixed)
CREATE_BODY_PART_FORMATTER(MultiPartAlternative)
CREATE_BODY_PART_FORMATTER(MultiPartSigned)
diff --git a/messageviewer/src/viewer/messagepart.cpp b/messageviewer/src/viewer/messagepart.cpp
index c5cf7d3..32bc1d8 100644
--- a/messageviewer/src/viewer/messagepart.cpp
+++ b/messageviewer/src/viewer/messagepart.cpp
@@ -18,6 +18,7 @@
*/
#include "messagepart.h"
+#include "messageviewer_debug.h"
#include "objecttreeparser.h"
#include <interfaces/htmlwriter.h>
@@ -377,3 +378,66 @@ void CryptoMessagePart::html(bool decorate) const
}
}
}
+
+EncapsulatedRfc822MessagePart::EncapsulatedRfc822MessagePart(ObjectTreeParser* otp, PartMetaData* block, KMime::Content* node, const KMime::Message::Ptr& message)
+: MessagePart(otp, block, QString())
+, mMessage(message)
+, mNode(node)
+, mSubOtp(0)
+{
+ mMetaData->isEncrypted = false;
+ mMetaData->isSigned = false;
+ mMetaData->isEncapsulatedRfc822Message = true;
+
+ mOtp->nodeHelper()->setNodeDisplayedEmbedded(mNode, true);
+ mOtp->nodeHelper()->setPartMetaData(mNode, *mMetaData);
+
+ if (!mMessage) {
+ qCWarning(MESSAGEVIEWER_LOG) << "Node is of type message/rfc822 but doesn't have a message!";
+ return;
+ }
+
+ // The link to "Encapsulated message" is clickable, therefore the temp file needs to exists,
+ // since the user can click the link and expect to have normal attachment operations there.
+ mOtp->nodeHelper()->writeNodeToTempFile(message.data());
+
+ mSubOtp = new ObjectTreeParser(mOtp, true);
+ mSubOtp->setAllowAsync(mOtp->allowAsync());
+ if (mOtp->htmlWriter()) {
+ mSubOtp->mHtmlWriter = new QueueHtmlWriter(mOtp->htmlWriter());
+ }
+ mSubOtp->parseObjectTreeInternal(message.data());
+}
+
+EncapsulatedRfc822MessagePart::~EncapsulatedRfc822MessagePart()
+{
+
+}
+
+void EncapsulatedRfc822MessagePart::html(bool decorate) const
+{
+ if (!mSubOtp) {
+ return;
+ }
+
+ MessageViewer::HtmlWriter* writer = mOtp->htmlWriter();
+
+ if (!writer) {
+ return;
+ }
+
+ const CryptoBlock block(mOtp, mMetaData, 0, mMessage->from()->asUnicodeString(), mMessage.data());
+ writer->queue(mOtp->mSource->createMessageHeader(mMessage.data()));
+ static_cast<QueueHtmlWriter*>(mSubOtp->htmlWriter())->replay();
+
+ mOtp->nodeHelper()->setPartMetaData(mNode, *mMetaData);
+}
+
+
+QString EncapsulatedRfc822MessagePart::text() const
+{
+ if (!mSubOtp) {
+ return QString();
+ }
+ return mSubOtp->plainTextContent();
+}
diff --git a/messageviewer/src/viewer/messagepart.h b/messageviewer/src/viewer/messagepart.h
index 261ad4b..c45c12b 100644
--- a/messageviewer/src/viewer/messagepart.h
+++ b/messageviewer/src/viewer/messagepart.h
@@ -102,6 +102,22 @@ protected:
PartMetaData *mMetaData;
};
+class EncapsulatedRfc822MessagePart : public MessagePart
+{
+public:
+ typedef QSharedPointer<EncapsulatedRfc822MessagePart> Ptr;
+ EncapsulatedRfc822MessagePart(MessageViewer::ObjectTreeParser *otp, MessageViewer::PartMetaData *block, KMime::Content *node, const KMime::Message::Ptr &message);
+ virtual ~EncapsulatedRfc822MessagePart();
+
+ QString text() const Q_DECL_OVERRIDE;
+ void html(bool decorate) const Q_DECL_OVERRIDE;
+
+private:
+ const KMime::Message::Ptr mMessage;
+ KMime::Content* mNode;
+ ObjectTreeParser *mSubOtp;
+};
+
class CryptoMessagePart : public MessagePart
{
public:
diff --git a/messageviewer/src/viewer/objecttreeparser.cpp b/messageviewer/src/viewer/objecttreeparser.cpp
index 33ff187..d7a3045 100644
--- a/messageviewer/src/viewer/objecttreeparser.cpp
+++ b/messageviewer/src/viewer/objecttreeparser.cpp
@@ -560,67 +560,6 @@ static int signatureToStatus(const GpgME::Signature &sig)
}
}
-bool ObjectTreeParser::writeOpaqueOrMultipartSignedData(KMime::Content *data,
- KMime::Content &sign,
- const QString &fromAddress,
- bool hideErrors)
-{
- bool bIsOpaqueSigned = false;
-
- const Kleo::CryptoBackend::Protocol *cryptProto = cryptoProtocol();
-
-#ifdef DEBUG_SIGNATURE
-#ifndef NDEBUG
- if (data) {
- qCDebug(MESSAGEVIEWER_LOG) << "processing Multipart Signed data";
- } else {
- qCDebug(MESSAGEVIEWER_LOG) << "processing Opaque Signed data";
- }
-#endif
-#endif
-
- QByteArray cleartext;
- QByteArray signaturetext;
- const QTextCodec *aCodec(data ? codecFor(data) : codecFor(&sign));
-
- if (cryptProto) {
- if (data) {
- cleartext = data->encodedContent();
- cleartext = KMime::LFtoCRLF(cleartext);
- }
-
- dumpToFile("dat_02_reader_signedtext_after_canonicalization",
- cleartext.data(), cleartext.length());
-
- signaturetext = sign.decodedContent();
- dumpToFile("dat_03_reader.sig", signaturetext.data(),
- signaturetext.size());
- }
-
- PartMetaData messagePart;
-
- CryptoMessagePart mp(this, &messagePart,
- aCodec->toUnicode(data ? cleartext : signaturetext), cryptProto,
- fromAddress, &sign);
-
- messagePart.isSigned = true;
-
- if (cryptProto) {
- if (data) { // detached
- mp.startVerificationDetached(cleartext, data, signaturetext);
- } else { // opaque
- mp.startVerificationDetached(signaturetext, Q_NULLPTR, QByteArray());
- bIsOpaqueSigned = true;
- }
- } else {
- messagePart.auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED);
- }
-
- mp.html(false);
-
- return bIsOpaqueSigned;
-}
-
void ObjectTreeParser::writeCertificateImportResult(const GpgME::ImportResult &res)
{
if (res.error()) {
@@ -1292,8 +1231,23 @@ bool ObjectTreeParser::processMultiPartSignedSubtype(KMime::Content *node, Proce
CryptoProtocolSaver saver(this, protocol);
mNodeHelper->setSignatureState(node, KMMsgFullySigned);
- writeOpaqueOrMultipartSignedData(signedData, *signature,
- NodeHelper::fromAsString(node));
+ const QByteArray cleartext = KMime::LFtoCRLF(signedData->encodedContent());
+ const QTextCodec *aCodec(codecFor(signedData));
+ PartMetaData messagePart;
+
+ CryptoMessagePart mp(this, &messagePart,
+ aCodec->toUnicode(cleartext), cryptoProtocol(),
+ NodeHelper::fromAsString(node), signature);
+ messagePart.isSigned = true;
+
+ if (cryptoProtocol()) {
+ mp.startVerificationDetached(cleartext, signedData, signature->decodedContent());
+ } else {
+ messagePart.auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED);
+ }
+
+ mp.html(false);
+
return true;
}
@@ -1391,56 +1345,6 @@ bool ObjectTreeParser::processMultiPartEncryptedSubtype(KMime::Content *node, Pr
return true;
}
-bool ObjectTreeParser::processMessageRfc822Subtype(KMime::Content *node, ProcessResult &)
-{
- if (htmlWriter() && !attachmentStrategy()->inlineNestedMessages() && !showOnlyOneMimePart()) {
- return false;
- }
-
- PartMetaData messagePart;
- messagePart.isEncrypted = false;
- messagePart.isSigned = false;
- messagePart.isEncapsulatedRfc822Message = true;
-
- KMime::Message::Ptr message = node->bodyAsMessage();
- if (!message) {
- qCWarning(MESSAGEVIEWER_LOG) << "Node is of type message/rfc822 but doesn't have a message!";
- }
-
- if (htmlWriter() && message) {
-
- // The link to "Encapsulated message" is clickable, therefore the temp file needs to exists,
- // since the user can click the link and expect to have normal attachment operations there.
- mNodeHelper->writeNodeToTempFile(message.data());
-
- // Paint the frame header
- htmlWriter()->queue(writeSigstatHeader(messagePart,
- cryptoProtocol(),
- message->from()->asUnicodeString(),
- message.data()));
-
- // Paint the message header
- htmlWriter()->queue(mSource->createMessageHeader(message.data()));
-
- // Process the message, i.e. paint it by processing it with an OTP
- ObjectTreeParser otp(this);
- otp.parseObjectTreeInternal(message.data());
-
- // Don't add the resulting textual content to our textual content here.
- // That is unwanted when inline forwarding a message, since the encapsulated message will
- // already be in the forward message as attachment, so don't duplicate the textual content
- // by adding it to the inline body as well
-
- // Paint the frame footer
- htmlWriter()->queue(writeSigstatFooter(messagePart));
- }
-
- mNodeHelper->setNodeDisplayedEmbedded(node, true);
- mNodeHelper->setPartMetaData(node, messagePart);
-
- return true;
-}
-
bool ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result)
{
if (KMime::Content *child = mNodeHelper->decryptedNodeForContent(node)) {
@@ -1551,11 +1455,21 @@ bool ObjectTreeParser::processApplicationPkcs7MimeSubtype(KMime::Content *node,
qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - type unknown - opaque signed data ?";
}
- bool sigFound = writeOpaqueOrMultipartSignedData(0,
- *signTestNode,
- NodeHelper::fromAsString(node),
- isEncrypted);
- if (sigFound) {
+ const QTextCodec *aCodec(codecFor(signTestNode));
+ const QByteArray signaturetext = signTestNode->decodedContent();
+ PartMetaData messagePart;
+ CryptoMessagePart mp(this, &messagePart,
+ aCodec->toUnicode(signaturetext), cryptoProtocol(),
+ NodeHelper::fromAsString(node), signTestNode);
+
+ if (cryptoProtocol()) {
+ mp.startVerificationDetached(signaturetext, 0, QByteArray());
+ } else {
+ messagePart.auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED);
+ }
+
+ mp.html(false /*, hideErrors = isEncrypted*/);
+ if (messagePart.isSigned) {
if (!isSigned) {
qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - signature found - opaque signed data !";
isSigned = true;
diff --git a/messageviewer/src/viewer/objecttreeparser.h b/messageviewer/src/viewer/objecttreeparser.h
index f758683..55264c0 100644
--- a/messageviewer/src/viewer/objecttreeparser.h
+++ b/messageviewer/src/viewer/objecttreeparser.h
@@ -385,18 +385,6 @@ private:
*/
void createAndParseTempNode(KMime::Content *parentNode, const char *content, const char *cntDesc);
- /** if data is 0:
- Feeds the HTML widget with the contents of the opaque signed
- data found in partNode 'sign'.
- if data is set:
- Feeds the HTML widget with the contents of the given
- multipart/signed object.
- Signature is tested. May contain body parts.
-
- Returns whether a signature was found or not: use this to
- find out if opaque data is signed or not. */
- bool writeOpaqueOrMultipartSignedData(KMime::Content *data, KMime::Content &sign, const QString &fromAddress, bool hideErrors = false);
-
/** Writes out the information contained in a GpgME::ImportResult */
void writeCertificateImportResult(const GpgME::ImportResult &res);
@@ -435,8 +423,6 @@ public:// (during refactoring)
bool processMultiPartSignedSubtype(KMime::Content *node, ProcessResult &result);
bool processMultiPartEncryptedSubtype(KMime::Content *node, ProcessResult &result);
- bool processMessageRfc822Subtype(KMime::Content *node, ProcessResult &result);
-
bool processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result);
bool processApplicationChiasmusTextSubtype(KMime::Content *node, ProcessResult &result);
@@ -535,6 +521,7 @@ private:
friend class MessagePart;
friend class CryptoMessagePart;
+ friend class EncapsulatedRfc822MessagePart;
};
}