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