diff --git a/messageviewer/src/header/grantleeheaderformatter.cpp b/messageviewer/src/header/grantleeheaderformatter.cpp --- a/messageviewer/src/header/grantleeheaderformatter.cpp +++ b/messageviewer/src/header/grantleeheaderformatter.cpp @@ -25,6 +25,7 @@ #include "config-messageviewer.h" #include +#include #include #include @@ -217,6 +218,7 @@ const MessageViewer::HeaderStyle *style, KMime::Message *message, bool showEmoticons) const { QVariantHash headerObject; + const auto nodeHelper = style->nodeHelper(); // However, the direction of the message subject within the header is // determined according to the contents of the subject itself. Since @@ -240,59 +242,70 @@ headerObject.insert(QStringLiteral("subject"), d->headerStyleUtil.subjectString(message, flags)); - if (message->to(false)) { + if (nodeHelper->hasMailHeader("to", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("to",message); headerObject.insert(QStringLiteral("toi18n"), i18n("To:")); - headerObject.insert(QStringLiteral("to"), QVariant::fromValue(static_cast(message->to()))); + headerObject.insert(QStringLiteral("to"), QVariant::fromValue(static_cast(value))); } - if (message->replyTo(false)) { + if (nodeHelper->hasMailHeader("replyTo", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("replyTo",message); headerObject.insert(QStringLiteral("replyToi18n"), i18n("Reply to:")); - headerObject.insert(QStringLiteral("replyTo"), QVariant::fromValue(static_cast(message->replyTo()))); + headerObject.insert(QStringLiteral("replyTo"), QVariant::fromValue(static_cast(value))); } - if (message->cc(false)) { + if (nodeHelper->hasMailHeader("cc", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("cc",message); headerObject.insert(QStringLiteral("cci18n"), i18n("CC:")); - headerObject.insert(QStringLiteral("cc"), QVariant::fromValue(static_cast(message->cc()))); + headerObject.insert(QStringLiteral("cc"), QVariant::fromValue(static_cast(value))); } - if (message->bcc(false)) { + if (nodeHelper->hasMailHeader("bcc", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("bcc",message); headerObject.insert(QStringLiteral("bcci18n"), i18n("BCC:")); - headerObject.insert(QStringLiteral("bcc"), QVariant::fromValue(static_cast(message->bcc()))); + headerObject.insert(QStringLiteral("bcc"), QVariant::fromValue(static_cast(value))); } - headerObject.insert(QStringLiteral("fromi18n"), i18n("From:")); - headerObject.insert(QStringLiteral("from"), QVariant::fromValue(static_cast(message->from()))); + { + const auto value = nodeHelper->mailHeaderAsAddressList("from",message); + headerObject.insert(QStringLiteral("fromi18n"), i18n("From:")); + headerObject.insert(QStringLiteral("from"), QVariant::fromValue(static_cast(value))); + } //Sender headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:")); headerObject.insert(QStringLiteral("sender"), - HeaderStyleUtil::strToHtml(message->sender()->asUnicodeString())); + HeaderStyleUtil::strToHtml(nodeHelper->mailHeaderAsBase("sender", message)->asUnicodeString())); headerObject.insert(QStringLiteral("listidi18n"), i18n("List-Id:")); - if (auto hrd = message->headerByType("List-Id")) { - headerObject.insert(QStringLiteral("listid"), hrd->asUnicodeString()); + if (nodeHelper->hasMailHeader("List-Id", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("List-Id", message); + headerObject.insert(QStringLiteral("listid"), value->asUnicodeString()); } const QString spamHtml = d->headerStyleUtil.spamStatus(message); if (!spamHtml.isEmpty()) { headerObject.insert(QStringLiteral("spamstatusi18n"), i18n("Spam Status:")); headerObject.insert(QStringLiteral("spamHTML"), spamHtml); } - headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); - headerObject.insert(QStringLiteral("date"), QVariant::fromValue(static_cast(message->date()))); + { + const auto value = nodeHelper->dateHeader(message); + headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); + // TODO: rewrite that QDateTime is expected in GRANTLEE + headerObject.insert(QStringLiteral("date"), QVariant::fromValue(static_cast(message->date()))); + } - if (message->hasHeader("Resent-From")) { + if (nodeHelper->hasMailHeader("Resent-From", message)) { + const auto value = nodeHelper->mailHeaderAsAddressList("Resent-From", message); headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from")); - headerObject.insert(QStringLiteral("resentfrom"), - QVariant::fromValue(HeaderStyleUtil::resentFromList(message))); + headerObject.insert(QStringLiteral("resentfrom"), QVariant::fromValue(static_cast(value))); } - if (message->hasHeader("Resent-To")) { - auto resentTo = HeaderStyleUtil::resentToList(message); + if (nodeHelper->hasMailHeader("Resent-To", message)) { + const auto resentTo = nodeHelper->mailHeaderAsAddressList("Resent-From", message); headerObject.insert(QStringLiteral("resenttoi18n"), i18np("receiver was", "receivers were", resentTo->mailboxes().count())); - headerObject.insert(QStringLiteral("resentto"), - QVariant::fromValue(HeaderStyleUtil::resentToList(message))); + headerObject.insert(QStringLiteral("resentto"), QVariant::fromValue(static_cast(resentTo))); } if (auto organization = message->organization(false)) { diff --git a/mimetreeparser/src/nodehelper.h b/mimetreeparser/src/nodehelper.h --- a/mimetreeparser/src/nodehelper.h +++ b/mimetreeparser/src/nodehelper.h @@ -78,6 +78,11 @@ */ static void magicSetType(KMime::Content *node, bool autoDecode = true); + bool hasMailHeader(const char *header, const KMime::Message *message) const; + KMime::Headers::Base *mailHeaderAsBase(const char *header, const KMime::Message *message) const; + KMime::Headers::Generics::AddressList *mailHeaderAsAddressList(const char *header, KMime::Message *message) const; + QDateTime dateHeader(KMime::Message *message) const; + /** Attach an extra node to an existing node */ void attachExtraContent(KMime::Content *topLevelNode, KMime::Content *content); diff --git a/mimetreeparser/src/nodehelper.cpp b/mimetreeparser/src/nodehelper.cpp --- a/mimetreeparser/src/nodehelper.cpp +++ b/mimetreeparser/src/nodehelper.cpp @@ -501,6 +501,39 @@ node->contentType()->setMimeType(mimetype.toLatin1()); } +bool NodeHelper::hasMailHeader(const char *header, const KMime::Message *message) const +{ + return message->hasHeader(header); +} + +KMime::Headers::Base * NodeHelper::mailHeaderAsBase(const char *header, const KMime::Message *message) const +{ + return message->headerByType(header); +} + +KMime::Headers::Generics::AddressList * NodeHelper::mailHeaderAsAddressList(const char *header, KMime::Message *message) const +{ + /* works without this is maybe faster ? + if(strcmp(header, "to") == 0) { + return message->to(); + } else if(strcmp(header, "replyTo") == 0) { + return message->replyTo(); + } else if(strcmp(header, "bcc") == 0) { + return message->bcc(); + } else if(strcmp(header, "cc") == 0) { + return message->cc(); + } */ + auto addressList = new KMime::Headers::Generics::AddressList(); + const auto hrd = message->headerByType(header); + const QByteArray &data = hrd->as7BitString(false); + addressList->from7BitString(data); + return addressList; +} + +QDateTime NodeHelper::dateHeader(KMime::Message *message) const +{ + return message->date()->dateTime(); +} void NodeHelper::setOverrideCodec(KMime::Content *node, const QTextCodec *codec) {