Commit 09c2b0e6 authored by Laurent Montel's avatar Laurent Montel 😁

Cache header pointer

parent da03d3c3
......@@ -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;
......
......@@ -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));
......
......@@ -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;
......
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