summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-26 05:55:34 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-26 05:55:34 (GMT)
commit09c2b0e61c580b7023fea546e72f38b8d9bd1f49 (patch)
tree0c0b4dc180130be756eb88cc60436cde690d284d
parentda03d3c3b00352e6f7a86b25c43406cd5fbff86b (diff)
Cache header pointer
-rw-r--r--messagecore/src/misc/mailinglist.cpp72
-rw-r--r--messageviewer/src/header/grantleeheaderformatter.cpp12
-rw-r--r--messageviewer/src/header/headerstyle_util.cpp8
3 files changed, 58 insertions, 34 deletions
diff --git a/messagecore/src/misc/mailinglist.cpp b/messagecore/src/misc/mailinglist.cpp
index 2f4d811..a0ace95 100644
--- a/messagecore/src/misc/mailinglist.cpp
+++ b/messagecore/src/misc/mailinglist.cpp
@@ -47,7 +47,10 @@ static QString check_x_beenthere(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("X-BeenThere") ? message->headerByType("X-BeenThere")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("X-BeenThere")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isNull() || header.indexOf(QLatin1Char('@')) == -1) {
return QString();
}
@@ -64,7 +67,10 @@ static QString check_delivered_to(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("Delivered-To") ? message->headerByType("Delivered-To")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("Delivered-To")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isNull()
|| header.left(13) != QLatin1String("mailing list")
|| header.indexOf(QLatin1Char('@')) == -1) {
@@ -82,7 +88,10 @@ static QString check_x_mailing_list(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("X-Mailing-List") ? message->headerByType("X-Mailing-List")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("X-Mailing-List")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -107,7 +116,10 @@ static QString check_list_id(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("List-Id") ? message->headerByType("List-Id")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("List-Id")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -134,7 +146,10 @@ static QString check_list_post(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("List-Post") ? message->headerByType("List-Post")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("List-Post")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -157,7 +172,10 @@ static QString check_mailing_list(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("Mailing-List") ? message->headerByType("Mailing-List")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("Mailing-List")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -179,7 +197,10 @@ static QString check_x_loop(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("X-Loop") ? message->headerByType("X-Loop")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("X-Loop")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -201,7 +222,10 @@ static QString check_x_ml_name(const KMime::Message::Ptr &message,
QByteArray &headerName,
QString &headerValue)
{
- QString header = message->headerByType("X-ML-Name") ? message->headerByType("X-ML-Name")->asUnicodeString() : QString();
+ QString header;
+ if (auto hrd = message->headerByType("X-ML-Name")) {
+ header = hrd->asUnicodeString();
+ }
if (header.isEmpty()) {
return QString();
}
@@ -289,36 +313,36 @@ MailingList MailingList::detect(const KMime::Message::Ptr &message)
{
MailingList mailingList;
- if (message->headerByType("List-Post")) {
- mailingList.setPostUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Post")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Post")) {
+ mailingList.setPostUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Help")) {
- mailingList.setHelpUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Help")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Help")) {
+ mailingList.setHelpUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Subscribe")) {
- mailingList.setSubscribeUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Subscribe")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Subscribe")) {
+ mailingList.setSubscribeUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Unsubscribe")) {
- mailingList.setUnsubscribeUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Unsubscribe")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Unsubscribe")) {
+ mailingList.setUnsubscribeUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Archive")) {
- mailingList.setArchiveUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Archive")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Archive")) {
+ mailingList.setArchiveUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Owner")) {
- mailingList.setOwnerUrls(QUrl::fromStringList(headerToAddress(message->headerByType("List-Owner")->asUnicodeString())));
+ if (auto hrd = message->headerByType("List-Owner")) {
+ mailingList.setOwnerUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("Archived-At")) {
- mailingList.setArchivedAtUrls(QUrl::fromStringList(headerToAddress(message->headerByType("Archived-At")->asUnicodeString())));
+ if (auto hrd = message->headerByType("Archived-At")) {
+ mailingList.setArchivedAtUrls(QUrl::fromStringList(headerToAddress(hrd->asUnicodeString())));
}
- if (message->headerByType("List-Id")) {
- mailingList.setId(message->headerByType("List-Id")->asUnicodeString());
+ if (auto hrd = message->headerByType("List-Id")) {
+ mailingList.setId(hrd->asUnicodeString());
}
return mailingList;
diff --git a/messageviewer/src/header/grantleeheaderformatter.cpp b/messageviewer/src/header/grantleeheaderformatter.cpp
index 38ac59b..8e9a35d 100644
--- a/messageviewer/src/header/grantleeheaderformatter.cpp
+++ b/messageviewer/src/header/grantleeheaderformatter.cpp
@@ -163,8 +163,8 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:"));
headerObject.insert(QStringLiteral("listidi18n"), i18n("List-Id:"));
- if (message->headerByType("List-Id")) {
- headerObject.insert(QStringLiteral("listid"), message->headerByType("List-Id")->asUnicodeString());
+ if (auto hrd = message->headerByType("List-Id")) {
+ headerObject.insert(QStringLiteral("listid"), hrd->asUnicodeString());
}
const QString spamHtml = d->headerStyleUtil.spamStatus(message);
@@ -186,18 +186,18 @@ QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grant
headerObject.insert(QStringLiteral("useragent"), d->headerStyleUtil.strToHtml(hdr->asUnicodeString()));
}
- if (message->headerByType("X-Mailer")) {
- headerObject.insert(QStringLiteral("xmailer"), d->headerStyleUtil.strToHtml(message->headerByType("X-Mailer")->asUnicodeString()));
+ if (auto hrd = message->headerByType("X-Mailer")) {
+ headerObject.insert(QStringLiteral("xmailer"), d->headerStyleUtil.strToHtml(hrd->asUnicodeString()));
}
}
- if (message->headerByType("Resent-From")) {
+ if (message->hasHeader("Resent-From")) {
headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from"));
const QVector<KMime::Types::Mailbox> resentFrom = d->headerStyleUtil.resentFromList(message);
headerObject.insert(QStringLiteral("resentfrom"), StringUtil::emailAddrAsAnchor(resentFrom, StringUtil::DisplayFullAddress));
}
- if (message->headerByType("Resent-To")) {
+ if (message->hasHeader("Resent-To")) {
const QVector<KMime::Types::Mailbox> resentTo = d->headerStyleUtil.resentToList(message);
headerObject.insert(QStringLiteral("resenttoi18n"), i18np("receiver was", "receivers were", resentTo.count()));
headerObject.insert(QStringLiteral("resentto"), StringUtil::emailAddrAsAnchor(resentTo, StringUtil::DisplayFullAddress));
diff --git a/messageviewer/src/header/headerstyle_util.cpp b/messageviewer/src/header/headerstyle_util.cpp
index 552fdee..454d8a5 100644
--- a/messageviewer/src/header/headerstyle_util.cpp
+++ b/messageviewer/src/header/headerstyle_util.cpp
@@ -246,8 +246,8 @@ QVector<KMime::Types::Mailbox> HeaderStyleUtil::resentFromList(KMime::Message *m
{
// Get the resent-from header into a Mailbox
QVector<KMime::Types::Mailbox> resentFrom;
- if (message->headerByType("Resent-From")) {
- const QByteArray data = message->headerByType("Resent-From")->as7BitString(false);
+ if (auto hrd = message->headerByType("Resent-From")) {
+ const QByteArray data = hrd->as7BitString(false);
const char *start = data.data();
const char *end = start + data.length();
KMime::Types::AddressList addressList;
@@ -265,8 +265,8 @@ QVector<KMime::Types::Mailbox> HeaderStyleUtil::resentToList(KMime::Message *mes
{
// Get the resent-from header into a Mailbox
QVector<KMime::Types::Mailbox> resentTo;
- if (message->headerByType("Resent-To")) {
- const QByteArray data = message->headerByType("Resent-To")->as7BitString(false);
+ if (auto hrd = message->headerByType("Resent-To")) {
+ const QByteArray data = hrd->as7BitString(false);
const char *start = data.data();
const char *end = start + data.length();
KMime::Types::AddressList addressList;