Commit 1548522e authored by Sandro Knauß's avatar Sandro Knauß

create a real tree out of MessageParts

parent 2a856a31
...@@ -114,7 +114,7 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar ...@@ -114,7 +114,7 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar
digestHeaderStr += str.midRef(0, thisDelim); digestHeaderStr += str.midRef(0, thisDelim);
MessagePartList::Ptr mpl(new MessagePartList(part.objectTreeParser())); MessagePartList::Ptr mpl(new MessagePartList(part.objectTreeParser()));
mpl->appendMessagePart(createAndParseTempNode(part, part.topLevelContent(), digestHeaderStr.toLatin1(), "Digest Header")); mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), digestHeaderStr.toLatin1(), "Digest Header"));
//mReader->queueHtml("<br><hr><br>"); //mReader->queueHtml("<br><hr><br>");
// temporarily change curent node's Content-Type // temporarily change curent node's Content-Type
// to get our embedded RfC822 messages properly inserted // to get our embedded RfC822 messages properly inserted
...@@ -151,7 +151,7 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar ...@@ -151,7 +151,7 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar
} }
} }
qCDebug(MIMETREEPARSER_LOG) << " embedded message found: \"" << subject; qCDebug(MIMETREEPARSER_LOG) << " embedded message found: \"" << subject;
mpl->appendMessagePart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1(), subject.toLatin1())); mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1(), subject.toLatin1()));
//mReader->queueHtml("<br><hr><br>"); //mReader->queueHtml("<br><hr><br>");
thisDelim = nextDelim + 1; thisDelim = nextDelim + 1;
nextDelim = str.indexOf(delim1, thisDelim, Qt::CaseInsensitive); nextDelim = str.indexOf(delim1, thisDelim, Qt::CaseInsensitive);
...@@ -179,6 +179,6 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar ...@@ -179,6 +179,6 @@ Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPar
} }
partStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest footer\n\n"); partStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest footer\n\n");
partStr += str.midRef(thisDelim); partStr += str.midRef(thisDelim);
mpl->appendMessagePart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1(), "Digest Footer")); mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1(), "Digest Footer"));
return mpl; return mpl;
} }
...@@ -42,6 +42,7 @@ MessagePart::MessagePart() ...@@ -42,6 +42,7 @@ MessagePart::MessagePart()
: QObject() : QObject()
, mHtmlWriter(Q_NULLPTR) , mHtmlWriter(Q_NULLPTR)
, mPart(Q_NULLPTR) , mPart(Q_NULLPTR)
, mParentPart(Q_NULLPTR)
{ {
} }
...@@ -49,6 +50,7 @@ MessagePart::MessagePart(const BodyPart &part) ...@@ -49,6 +50,7 @@ MessagePart::MessagePart(const BodyPart &part)
: QObject() : QObject()
, mHtmlWriter(Q_NULLPTR) , mHtmlWriter(Q_NULLPTR)
, mPart(&part) , mPart(&part)
, mParentPart(Q_NULLPTR)
{ {
} }
...@@ -68,6 +70,16 @@ QString MessagePart::text() const ...@@ -68,6 +70,16 @@ QString MessagePart::text() const
return QString(); return QString();
} }
MessagePart* MessagePart::parentPart() const
{
return mParentPart;
}
void MessagePart::setParentPart(MessagePart* parentPart)
{
mParentPart = parentPart;
}
MimeTreeParser::HtmlWriter *MessagePart::htmlWriter() MimeTreeParser::HtmlWriter *MessagePart::htmlWriter()
{ {
if (!mHtmlWriter) { if (!mHtmlWriter) {
......
...@@ -63,11 +63,15 @@ public: ...@@ -63,11 +63,15 @@ public:
virtual void html(bool decorate); virtual void html(bool decorate);
virtual QString text() const; virtual QString text() const;
void setParentPart(MessagePart *parentPart);
MessagePart *parentPart() const;
private: private:
MimeTreeParser::HtmlWriter *htmlWriter(); MimeTreeParser::HtmlWriter *htmlWriter();
MimeTreeParser::HtmlWriter *mHtmlWriter; MimeTreeParser::HtmlWriter *mHtmlWriter;
const BodyPart *mPart; const BodyPart *mPart;
MessagePart *mParentPart;
friend class BodyPartFormatter; friend class BodyPartFormatter;
}; };
......
...@@ -1123,6 +1123,9 @@ void MessagePart::parseInternal(KMime::Content *node, bool onlyOneMimePart) ...@@ -1123,6 +1123,9 @@ void MessagePart::parseInternal(KMime::Content *node, bool onlyOneMimePart)
mSubOtp = new ObjectTreeParser(mOtp, onlyOneMimePart); mSubOtp = new ObjectTreeParser(mOtp, onlyOneMimePart);
mSubOtp->setAllowAsync(mOtp->allowAsync()); mSubOtp->setAllowAsync(mOtp->allowAsync());
mSubMessagePart = mSubOtp->parseObjectTreeInternal(node); mSubMessagePart = mSubOtp->parseObjectTreeInternal(node);
foreach(auto part, mSubMessagePart->subParts()) {
part->setParentPart(this);
}
} }
void MessagePart::renderInternalHtml(bool decorate) const void MessagePart::renderInternalHtml(bool decorate) const
...@@ -1157,6 +1160,22 @@ void MessagePart::fix() const ...@@ -1157,6 +1160,22 @@ void MessagePart::fix() const
} }
} }
void MessagePart::appendSubPart(const Interface::MessagePart::Ptr &messagePart)
{
messagePart->setParentPart(this);
mBlocks.append(messagePart);
}
const QVector<Interface::MessagePart::Ptr> &MessagePart::subParts() const
{
return mBlocks;
}
bool MessagePart::hasSubParts() const
{
return !mBlocks.isEmpty();
}
//-----MessagePartList---------------------- //-----MessagePartList----------------------
MessagePartList::MessagePartList(ObjectTreeParser *otp) MessagePartList::MessagePartList(ObjectTreeParser *otp)
: MessagePart(otp, QString()) : MessagePart(otp, QString())
...@@ -1187,15 +1206,6 @@ HTMLBlock::Ptr MessagePartList::rootBlock() const ...@@ -1187,15 +1206,6 @@ HTMLBlock::Ptr MessagePartList::rootBlock() const
return HTMLBlock::Ptr(); return HTMLBlock::Ptr();
} }
void MessagePartList::appendMessagePart(const Interface::MessagePart::Ptr &messagePart)
{
mBlocks.append(messagePart);
}
const QVector<Interface::MessagePart::Ptr> &MessagePartList::messageParts() const
{
return mBlocks;
}
void MessagePartList::html(bool decorate) void MessagePartList::html(bool decorate)
{ {
...@@ -1207,7 +1217,7 @@ void MessagePartList::html(bool decorate) ...@@ -1207,7 +1217,7 @@ void MessagePartList::html(bool decorate)
void MessagePartList::htmlInternal(bool decorate) void MessagePartList::htmlInternal(bool decorate)
{ {
foreach (const auto &mp, mBlocks) { foreach (const auto &mp, subParts()) {
mp->html(decorate); mp->html(decorate);
} }
} }
...@@ -1215,7 +1225,7 @@ void MessagePartList::htmlInternal(bool decorate) ...@@ -1215,7 +1225,7 @@ void MessagePartList::htmlInternal(bool decorate)
QString MessagePartList::text() const QString MessagePartList::text() const
{ {
QString text; QString text;
foreach (const auto &mp, mBlocks) { foreach (const auto &mp, subParts()) {
text += mp->text(); text += mp->text();
} }
return text; return text;
...@@ -1223,7 +1233,7 @@ QString MessagePartList::text() const ...@@ -1223,7 +1233,7 @@ QString MessagePartList::text() const
void MessagePartList::fix() const void MessagePartList::fix() const
{ {
foreach (const auto &mp, mBlocks) { foreach (const auto &mp, subParts()) {
const auto m = mp.dynamicCast<MessagePart>(); const auto m = mp.dynamicCast<MessagePart>();
if (m) { if (m) {
m->fix(); m->fix();
...@@ -1233,7 +1243,7 @@ void MessagePartList::fix() const ...@@ -1233,7 +1243,7 @@ void MessagePartList::fix() const
void MessagePartList::copyContentFrom() const void MessagePartList::copyContentFrom() const
{ {
foreach (const auto &mp, mBlocks) { foreach (const auto &mp, subParts()) {
const auto m = mp.dynamicCast<MessagePart>(); const auto m = mp.dynamicCast<MessagePart>();
if (m) { if (m) {
m->copyContentFrom(); m->copyContentFrom();
...@@ -1301,12 +1311,12 @@ void TextMessagePart::parseContent() ...@@ -1301,12 +1311,12 @@ void TextMessagePart::parseContent()
if (block.type() == NoPgpBlock && !block.text().trimmed().isEmpty()) { if (block.type() == NoPgpBlock && !block.text().trimmed().isEmpty()) {
fullySignedOrEncryptedTmp = false; fullySignedOrEncryptedTmp = false;
appendMessagePart(MessagePart::Ptr(new MessagePart(mOtp, aCodec->toUnicode(block.text())))); appendSubPart(MessagePart::Ptr(new MessagePart(mOtp, aCodec->toUnicode(block.text()))));
} else if (block.type() == PgpMessageBlock) { } else if (block.type() == PgpMessageBlock) {
CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, Q_NULLPTR)); CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, Q_NULLPTR));
mp->setDecryptMessage(decryptMessage()); mp->setDecryptMessage(decryptMessage());
mp->setIsEncrypted(true); mp->setIsEncrypted(true);
appendMessagePart(mp); appendSubPart(mp);
if (!decryptMessage()) { if (!decryptMessage()) {
continue; continue;
} }
...@@ -1316,13 +1326,13 @@ void TextMessagePart::parseContent() ...@@ -1316,13 +1326,13 @@ void TextMessagePart::parseContent()
} }
} else if (block.type() == ClearsignedBlock) { } else if (block.type() == ClearsignedBlock) {
CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, Q_NULLPTR)); CryptoMessagePart::Ptr mp(new CryptoMessagePart(mOtp, QString(), cryptProto, fromAddress, Q_NULLPTR));
appendMessagePart(mp); appendSubPart(mp);
mp->startVerification(block.text(), aCodec); mp->startVerification(block.text(), aCodec);
} else { } else {
continue; continue;
} }
const auto mp = messageParts().last().staticCast<MessagePart>(); const auto mp = subParts().last().staticCast<MessagePart>();
const PartMetaData *messagePart(mp->partMetaData()); const PartMetaData *messagePart(mp->partMetaData());
if (!messagePart->isEncrypted && !messagePart->isSigned && !block.text().trimmed().isEmpty()) { if (!messagePart->isEncrypted && !messagePart->isSigned && !block.text().trimmed().isEmpty()) {
......
...@@ -233,6 +233,10 @@ public: ...@@ -233,6 +233,10 @@ public:
virtual void fix() const; virtual void fix() const;
virtual void copyContentFrom() const; virtual void copyContentFrom() const;
void appendSubPart(const Interface::MessagePart::Ptr &messagePart);
const QVector<Interface::MessagePart::Ptr> &subParts() const;
bool hasSubParts() const;
protected: protected:
void parseInternal(KMime::Content *node, bool onlyOneMimePart); void parseInternal(KMime::Content *node, bool onlyOneMimePart);
void renderInternalHtml(bool decorate) const; void renderInternalHtml(bool decorate) const;
...@@ -245,6 +249,8 @@ protected: ...@@ -245,6 +249,8 @@ protected:
MessagePart::Ptr mSubMessagePart; MessagePart::Ptr mSubMessagePart;
PartMetaData mMetaData; PartMetaData mMetaData;
KMime::Content *mAttachmentNode; KMime::Content *mAttachmentNode;
private:
QVector<Interface::MessagePart::Ptr> mBlocks;
}; };
class MimeMessagePart : public MessagePart class MimeMessagePart : public MessagePart
...@@ -277,10 +283,6 @@ public: ...@@ -277,10 +283,6 @@ public:
void setIsRoot(bool root); void setIsRoot(bool root);
bool isRoot() const; bool isRoot() const;
void appendMessagePart(const Interface::MessagePart::Ptr &messagePart);
const QVector<Interface::MessagePart::Ptr> &messageParts() const;
void fix() const Q_DECL_OVERRIDE; void fix() const Q_DECL_OVERRIDE;
void copyContentFrom() const Q_DECL_OVERRIDE; void copyContentFrom() const Q_DECL_OVERRIDE;
...@@ -289,7 +291,6 @@ protected: ...@@ -289,7 +291,6 @@ protected:
void htmlInternal(bool decorate); void htmlInternal(bool decorate);
private: private:
QVector<Interface::MessagePart::Ptr> mBlocks;
bool mRoot; bool mRoot;
}; };
......
...@@ -308,11 +308,11 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node) ...@@ -308,11 +308,11 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node)
Interface::MessagePartPtr mp; Interface::MessagePartPtr mp;
if (processType(node, processResult, mediaType, subType, mp)) { if (processType(node, processResult, mediaType, subType, mp)) {
if (mp) { if (mp) {
mpl->appendMessagePart(mp); mpl->appendSubPart(mp);
} }
} else if (processType(node, processResult, mediaType, "*", mp)) { } else if (processType(node, processResult, mediaType, "*", mp)) {
if (mp) { if (mp) {
mpl->appendMessagePart(mp); mpl->appendSubPart(mp);
} }
} else { } else {
qCWarning(MIMETREEPARSER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; qCWarning(MIMETREEPARSER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType;
...@@ -321,7 +321,7 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node) ...@@ -321,7 +321,7 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node)
if (auto _mp = mp.dynamicCast<MessagePart>()) { if (auto _mp = mp.dynamicCast<MessagePart>()) {
_mp->setAttachmentFlag(node); _mp->setAttachmentFlag(node);
} }
mpl->appendMessagePart(mp); mpl->appendSubPart(mp);
} }
} }
mNodeHelper->setNodeProcessed(node, false); mNodeHelper->setNodeProcessed(node, false);
......
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