Commit bbbdb2b4 authored by Sandro Knauß's avatar Sandro Knauß
Browse files

Do not use ObjectTreeParser::findType anymore, because this will be removed

parent 60fd6ff8
......@@ -40,6 +40,7 @@ using namespace KMime;
#include <MessageComposer/GlobalPart>
#include <MessageComposer/InfoPart>
#include <MessageComposer/TextPart>
#include "MessageComposer/Util"
#include <attachment/attachmentmodel.h>
#include <attachment/attachmentcontrollerbase.h>
using namespace MessageComposer;
......@@ -163,7 +164,7 @@ void CryptoComposerTest::testEncryptSameAttachments()
otp.parseObjectTree(message.data());
KMime::Message::Ptr unencrypted = nh->unencryptedMessage(message);
KMime::Content *testAttachment = MimeTreeParser::ObjectTreeParser::findType(unencrypted.data(), "x-some", "x-type", true, true);
KMime::Content *testAttachment = Util::findTypeInMessage(unencrypted.data(), "x-some", "x-type");
QCOMPARE(testAttachment->body(), QString::fromLatin1("abc").toUtf8());
QCOMPARE(testAttachment->contentDisposition()->filename(), QString::fromLatin1("anattachment.txt"));
......
......@@ -23,6 +23,8 @@
#include "testhtmlwriter.h"
#include "testcsshelper.h"
#include "MessageComposer/Util"
#include <Libkleo/Enum>
#include <Libkleo/KeyListJob>
#include <Libkleo/CryptoBackendFactory>
......@@ -41,6 +43,8 @@
#include <gpgme++/keylistresult.h>
#include <setupenv.h>
using namespace MessageComposer;
void ComposerTestUtil::verify(bool sign, bool encrypt, KMime::Content *content, QByteArray origContent, Kleo::CryptoMessageFormat f, KMime::Headers::contentEncoding encoding)
{
if (sign && encrypt) {
......@@ -72,7 +76,7 @@ void ComposerTestUtil::verifySignature(KMime::Content *content, QByteArray signe
// process the result..
otp.parseObjectTree(resultMessage);
KMime::Content *signedPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage, "application", "pgp-signature", true, true);
KMime::Content *signedPart = Util::findTypeInMessage(resultMessage, "application", "pgp-signature");
Q_ASSERT(signedPart);
QCOMPARE(signedPart->contentTransferEncoding()->encoding(), KMime::Headers::CE7Bit);
Q_UNUSED(signedPart);
......@@ -88,7 +92,7 @@ void ComposerTestUtil::verifySignature(KMime::Content *content, QByteArray signe
QCOMPARE(resultMessage->contentTransferEncoding()->encoding(), encoding);
} else if (f & Kleo::AnySMIME) {
if (f & Kleo::SMIMEFormat) {
KMime::Content *signedPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage, "application", "pkcs7-signature", true, true);
KMime::Content *signedPart = Util::findTypeInMessage(resultMessage, "application", "pkcs7-signature");
Q_ASSERT(signedPart);
QCOMPARE(signedPart->contentTransferEncoding()->encoding(), KMime::Headers::CEbase64);
QCOMPARE(signedPart->contentType()->mimeType(), QByteArray("application/pkcs7-signature"));
......@@ -104,7 +108,7 @@ void ComposerTestUtil::verifySignature(KMime::Content *content, QByteArray signe
QCOMPARE(resultMessage->contentType()->parameter(QString::fromLatin1("micalg")), QString::fromLatin1("sha1"));
} else if (f & Kleo::SMIMEOpaqueFormat) {
KMime::Content *signedPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage, "application", "pkcs7-mime", true, true);
KMime::Content *signedPart = Util::findTypeInMessage(resultMessage, "application", "pkcs7-mime");
Q_ASSERT(signedPart);
QCOMPARE(signedPart->contentTransferEncoding()->encoding(), KMime::Headers::CEbase64);
QCOMPARE(signedPart->contentType()->mimeType(), QByteArray("application/pkcs7-mime"));
......@@ -143,7 +147,7 @@ void ComposerTestUtil::verifyEncryption(KMime::Content *content, QByteArray encr
if (f & Kleo::OpenPGPMIMEFormat) {
// ensure the enc part exists and is parseable
KMime::Content *encPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage.data(), "application", "pgp-encrypted", true, true);
KMime::Content *encPart = Util::findTypeInMessage(resultMessage.data(), "application", "pgp-encrypted");
Q_ASSERT(encPart);
Q_UNUSED(encPart);
......@@ -164,7 +168,7 @@ void ComposerTestUtil::verifyEncryption(KMime::Content *content, QByteArray encr
QCOMPARE(nh->encryptionState(resultMessage.data()), MimeTreeParser::KMMsgFullyEncrypted);
} else if (f & Kleo::AnySMIME) {
// ensure the enc part exists and is parseable
KMime::Content *encPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage.data(), "application", "pkcs7-mime", true, true);
KMime::Content *encPart = Util::findTypeInMessage(resultMessage.data(), "application", "pkcs7-mime");
Q_ASSERT(encPart);
QCOMPARE(encPart->contentType()->mimeType(), QByteArray("application/pkcs7-mime"));
......@@ -200,7 +204,7 @@ void ComposerTestUtil::verifySignatureAndEncryption(KMime::Content *content, QBy
if (f & Kleo::OpenPGPMIMEFormat) {
// ensure the enc part exists and is parseable
KMime::Content *encPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage.data(), "application", "pgp-encrypted", true, true);
KMime::Content *encPart = Util::findTypeInMessage(resultMessage.data(), "application", "pgp-encrypted");
Q_ASSERT(encPart);
Q_UNUSED(encPart);
otp.parseObjectTree(resultMessage.data());
......@@ -215,7 +219,7 @@ void ComposerTestUtil::verifySignatureAndEncryption(KMime::Content *content, QBy
QCOMPARE(nh->encryptionState(resultMessage.data()), MimeTreeParser::KMMsgFullyEncrypted);
QCOMPARE(nh->signatureState(resultMessage.data()), MimeTreeParser::KMMsgFullySigned);
} else if (f & Kleo::AnySMIME) {
KMime::Content *encPart = MimeTreeParser::ObjectTreeParser::findType(resultMessage.data(), "application", "pkcs7-mime", true, true);
KMime::Content *encPart = Util::findTypeInMessage(resultMessage.data(), "application", "pkcs7-mime");
Q_ASSERT(encPart);
QCOMPARE(encPart->contentType()->mimeType(), QByteArray("application/pkcs7-mime"));
QCOMPARE(encPart->contentType()->name(), QString::fromLatin1("smime.p7m"));
......
......@@ -29,6 +29,7 @@
#include "MessageComposer/MessageFactory"
#include "MessageComposer/GlobalPart"
#include "MessageComposer/MessageComposerSettings"
#include "MessageComposer/Util"
#include "MessageComposer/InfoPart"
#include "MessageComposer/TextPart"
......@@ -52,7 +53,6 @@
#include <QLocale>
#include "globalsettings_templateparser.h"
using namespace MessageComposer;
using namespace MessageComposer;
namespace
......@@ -374,9 +374,6 @@ void MessageFactoryTest::testCreateMDN()
MimeTreeParser::ObjectTreeParser otp( &testSource, nh, 0, false, true, 0 );
MimeTreeParser::ProcessResult pResult( nh ); */
// qDebug() << MessageCore::NodeHelper::firstChild( mdn->mainBodyPart() )->encodedContent();
// qDebug() << MessageCore::NodeHelper::next( MimeTreeParser::ObjectTreeParser::findType( mdn.data(), "multipart", "report", true, true ) )->body();
QString mdnContent = QString::fromLatin1("The message sent on %1 to %2 with subject \"%3\" has been displayed. "
"This is no guarantee that the message has been read or understood.");
mdnContent = mdnContent.arg(KMime::DateFormatter::formatDate(KMime::DateFormatter::Localized, msg->date()->dateTime().toTime_t()))
......@@ -384,7 +381,7 @@ void MessageFactoryTest::testCreateMDN()
qDebug() << "comparing with:" << mdnContent;
QCOMPARE_OR_DIFF(MessageCore::NodeHelper::next(MimeTreeParser::ObjectTreeParser::findType(mdn.data(), "multipart", "report", true, true))->body(),
QCOMPARE_OR_DIFF(Util::findTypeInMessage(mdn.data(), "multipart", "report")->contents().at(0)->body(),
mdnContent.toLatin1());
}
......
......@@ -1650,7 +1650,7 @@ int MessageComposer::ComposerViewBase::autoSaveInterval() const
//-----------------------------------------------------------------------------
void MessageComposer::ComposerViewBase::collectImages(KMime::Content *root)
{
if (KMime::Content *n = MimeTreeParser::ObjectTreeParser::findType(root, "multipart/alternative", true, true)) {
if (KMime::Content *n = Util::findTypeInMessage(root, "multipart", "alternative")) {
KMime::Content *parentnode = n->parent();
if (parentnode &&
parentnode->contentType()->isMultipart() &&
......
......@@ -310,3 +310,29 @@ void MessageComposer::Util::removeNotNecessaryHeaders(const KMime::Message::Ptr
msg->removeHeader("X-KMail-EncryptActionEnabled");
msg->removeHeader("X-KMail-CryptoMessageFormat");
}
KMime::Content* MessageComposer::Util::findTypeInMessage(KMime::Content *data, const QByteArray &mimeType, const QByteArray &subType)
{
if (!data->contentType()->isEmpty()) {
if (mimeType.isEmpty() || subType.isEmpty()) {
return data;
}
if ((mimeType == data->contentType()->mediaType())
&& (subType == data->contentType()->subType())) {
return data;
}
}
foreach (auto child, data->contents()) {
if ((!child->contentType()->isEmpty())
&& (mimeType == child->contentType()->mimeType())
&& (subType == child->contentType()->subType())) {
return child;
}
auto ret = findTypeInMessage(child, mimeType, subType);
if (ret) {
return ret;
}
}
return Q_NULLPTR;
}
\ No newline at end of file
......@@ -79,6 +79,11 @@ MESSAGECOMPOSER_EXPORT QString cleanedUpHeaderString(const QString &s);
void addSendReplyForwardAction(const KMime::Message::Ptr &message, MailTransport::MessageQueueJob *qjob);
MESSAGECOMPOSER_EXPORT bool sendMailDispatcherIsOnline(QWidget *parent = Q_NULLPTR);
MESSAGECOMPOSER_EXPORT void removeNotNecessaryHeaders(const KMime::Message::Ptr &msg);
/**
* find mimetype in message
*/
MESSAGECOMPOSER_EXPORT KMime::Content *findTypeInMessage(KMime::Content* data, const QByteArray& mimeType, const QByteArray& subType);
}
}
......
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