summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-26 06:30:59 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-26 06:30:59 (GMT)
commitd5ccb8624ef337b8d26905860e00bbf01d0d0ea3 (patch)
tree9a5cea5040d7b9551a65e4a56f91587fd8ff8c6f
parent033c2920a26c7b729604c140ab32983ce26d454c (diff)
Cache hearder pointer
-rw-r--r--messagecomposer/src/composer/composerviewbase.cpp12
-rw-r--r--messagecomposer/src/helper/messagefactory.cpp6
-rw-r--r--messagecomposer/src/sender/akonadisender.cpp4
-rw-r--r--messagecore/src/helpers/messagehelpers.cpp8
-rw-r--r--messageviewer/src/header/headerstyle_util.cpp52
-rw-r--r--templateparser/src/templateparser.cpp24
6 files changed, 57 insertions, 49 deletions
diff --git a/messagecomposer/src/composer/composerviewbase.cpp b/messagecomposer/src/composer/composerviewbase.cpp
index 67345e6..76fa9bb 100644
--- a/messagecomposer/src/composer/composerviewbase.cpp
+++ b/messagecomposer/src/composer/composerviewbase.cpp
@@ -154,20 +154,20 @@ void MessageComposer::ComposerViewBase::setMessage(const KMime::Message::Ptr &ms
m_recipientsEditor->setFocusBottom();
// If we are loading from a draft, load unexpanded aliases as well
- if (m_msg->hasHeader("X-KMail-UnExpanded-To")) {
- const QStringList spl = m_msg->headerByType("X-KMail-UnExpanded-To")->asUnicodeString().split(QStringLiteral(","));
+ if (auto hrd = m_msg->headerByType("X-KMail-UnExpanded-To")) {
+ const QStringList spl = hrd->asUnicodeString().split(QStringLiteral(","));
foreach (const QString &addr, spl) {
m_recipientsEditor->addRecipient(addr, MessageComposer::Recipient::To);
}
}
- if (m_msg->hasHeader("X-KMail-UnExpanded-CC")) {
- const QStringList spl = m_msg->headerByType("X-KMail-UnExpanded-CC")->asUnicodeString().split(QStringLiteral(","));
+ if (auto hrd = m_msg->headerByType("X-KMail-UnExpanded-CC")) {
+ const QStringList spl = hrd->asUnicodeString().split(QStringLiteral(","));
foreach (const QString &addr, spl) {
m_recipientsEditor->addRecipient(addr, MessageComposer::Recipient::Cc);
}
}
- if (m_msg->hasHeader("X-KMail-UnExpanded-BCC")) {
- const QStringList spl = m_msg->headerByType("X-KMail-UnExpanded-BCC")->asUnicodeString().split(QStringLiteral(","));
+ if (auto hrd = m_msg->headerByType("X-KMail-UnExpanded-BCC")) {
+ const QStringList spl = hrd->asUnicodeString().split(QStringLiteral(","));
foreach (const QString &addr, spl) {
m_recipientsEditor->addRecipient(addr, MessageComposer::Recipient::Bcc);
}
diff --git a/messagecomposer/src/helper/messagefactory.cpp b/messagecomposer/src/helper/messagefactory.cpp
index b733395..848c4b9 100644
--- a/messagecomposer/src/helper/messagefactory.cpp
+++ b/messagecomposer/src/helper/messagefactory.cpp
@@ -971,7 +971,11 @@ QString MessageFactory::replaceHeadersInString(const KMime::Message::Ptr &msg, c
idx = 0;
while ((idx = rx.indexIn(result, idx)) != -1) {
- QString replacement = msg->headerByType(rx.cap(1).toLatin1().constData()) ? msg->headerByType(rx.cap(1).toLatin1().constData())->asUnicodeString() : QStringLiteral("");
+ const QByteArray ba = rx.cap(1).toLatin1();
+ QString replacement;
+ if (auto hrd = msg->headerByType(ba.constData())) {
+ replacement = hrd->asUnicodeString();
+ }
result.replace(idx, rx.matchedLength(), replacement);
idx += replacement.length();
}
diff --git a/messagecomposer/src/sender/akonadisender.cpp b/messagecomposer/src/sender/akonadisender.cpp
index fd87c8b..970c93e 100644
--- a/messagecomposer/src/sender/akonadisender.cpp
+++ b/messagecomposer/src/sender/akonadisender.cpp
@@ -134,10 +134,10 @@ void AkonadiSender::sendOrQueueMessage(const KMime::Message::Ptr &message, Messa
MessageQueueJob *qjob = new MessageQueueJob(this);
if (message->hasHeader("X-KMail-FccDisabled")) {
qjob->sentBehaviourAttribute().setSentBehaviour(MailTransport::SentBehaviourAttribute::Delete);
- } else if (message->headerByType("X-KMail-Fcc")) {
+ } else if (auto hrd = message->headerByType("X-KMail-Fcc")) {
qjob->sentBehaviourAttribute().setSentBehaviour(
SentBehaviourAttribute::MoveToCollection);
- const int sentCollectionId = message->headerByType("X-KMail-Fcc")->asUnicodeString().toInt();
+ const int sentCollectionId = hrd->asUnicodeString().toInt();
qjob->sentBehaviourAttribute().setMoveToCollection(
Akonadi::Collection(sentCollectionId));
} else {
diff --git a/messagecore/src/helpers/messagehelpers.cpp b/messagecore/src/helpers/messagehelpers.cpp
index c6a5c4f..b19612e 100644
--- a/messagecore/src/helpers/messagehelpers.cpp
+++ b/messagecore/src/helpers/messagehelpers.cpp
@@ -76,12 +76,14 @@ void MessageCore::Util::addLinkInformation(const KMime::Message::Ptr &msg, Akona
bool MessageCore::Util::getLinkInformation(const KMime::Message::Ptr &msg, QList<Akonadi::Item::Id> &id, QList<Akonadi::MessageStatus> &status)
{
- if (!msg->headerByType("X-KMail-Link-Message") || !msg->headerByType("X-KMail-Link-Type")) {
+ auto hrdLinkMsg = msg->headerByType("X-KMail-Link-Message");
+ auto hrdLinkType = msg->headerByType("X-KMail-Link-Type");
+ if (!hrdLinkMsg || !hrdLinkType) {
return false;
}
- const QStringList messages = msg->headerByType("X-KMail-Link-Message")->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
- const QStringList types = msg->headerByType("X-KMail-Link-Type")->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
+ const QStringList messages = hrdLinkMsg->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
+ const QStringList types = hrdLinkType->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
if (messages.isEmpty() || types.isEmpty()) {
return false;
diff --git a/messageviewer/src/header/headerstyle_util.cpp b/messageviewer/src/header/headerstyle_util.cpp
index 2dade57..98a8e69 100644
--- a/messageviewer/src/header/headerstyle_util.cpp
+++ b/messageviewer/src/header/headerstyle_util.cpp
@@ -346,35 +346,37 @@ HeaderStyleUtil::xfaceSettings HeaderStyleUtil::xface(const MessageViewer::Heade
useOtherPhotoSources = true;
}
- if (settings.photoURL.isEmpty() && message->headerByType("Face") && useOtherPhotoSources) {
- // no photo, look for a Face header
- const QString faceheader = message->headerByType("Face")->asUnicodeString();
- if (!faceheader.isEmpty()) {
-
- qCDebug(MESSAGEVIEWER_LOG) << "Found Face: header";
-
- const QByteArray facestring = faceheader.toUtf8();
- // Spec says header should be less than 998 bytes
- // Face: is 5 characters
- if (facestring.length() < 993) {
- const QByteArray facearray = QByteArray::fromBase64(facestring);
-
- QImage faceimage;
- if (faceimage.loadFromData(facearray, "png")) {
- // Spec says image must be 48x48 pixels
- if ((48 == faceimage.width()) && (48 == faceimage.height())) {
- settings.photoURL = MessageViewer::HeaderStyleUtil::imgToDataUrl(faceimage);
- settings.photoWidth = 48;
- settings.photoHeight = 48;
+ if (settings.photoURL.isEmpty() && useOtherPhotoSources) {
+ if (auto hrd = message->headerByType("Face")) {
+ // no photo, look for a Face header
+ const QString faceheader = hrd->asUnicodeString();
+ if (!faceheader.isEmpty()) {
+
+ qCDebug(MESSAGEVIEWER_LOG) << "Found Face: header";
+
+ const QByteArray facestring = faceheader.toUtf8();
+ // Spec says header should be less than 998 bytes
+ // Face: is 5 characters
+ if (facestring.length() < 993) {
+ const QByteArray facearray = QByteArray::fromBase64(facestring);
+
+ QImage faceimage;
+ if (faceimage.loadFromData(facearray, "png")) {
+ // Spec says image must be 48x48 pixels
+ if ((48 == faceimage.width()) && (48 == faceimage.height())) {
+ settings.photoURL = MessageViewer::HeaderStyleUtil::imgToDataUrl(faceimage);
+ settings.photoWidth = 48;
+ settings.photoHeight = 48;
+ } else {
+ qCDebug(MESSAGEVIEWER_LOG) << "Face: header image is" << faceimage.width() << "by"
+ << faceimage.height() << "not 48x48 Pixels";
+ }
} else {
- qCDebug(MESSAGEVIEWER_LOG) << "Face: header image is" << faceimage.width() << "by"
- << faceimage.height() << "not 48x48 Pixels";
+ qCDebug(MESSAGEVIEWER_LOG) << "Failed to load decoded png from Face: header";
}
} else {
- qCDebug(MESSAGEVIEWER_LOG) << "Failed to load decoded png from Face: header";
+ qCDebug(MESSAGEVIEWER_LOG) << "Face: header too long at" << facestring.length();
}
- } else {
- qCDebug(MESSAGEVIEWER_LOG) << "Face: header too long at" << facestring.length();
}
}
}
diff --git a/templateparser/src/templateparser.cpp b/templateparser/src/templateparser.cpp
index 66e61dc..836b17c 100644
--- a/templateparser/src/templateparser.cpp
+++ b/templateparser/src/templateparser.cpp
@@ -704,10 +704,10 @@ void TemplateParser::processWithTemplate(const QString &tmpl)
i += len;
if (mOrigMsg) {
const QString hdr = q;
- const QString str =
- mOrigMsg->headerByType(hdr.toLocal8Bit().constData()) ?
- mOrigMsg->headerByType(hdr.toLocal8Bit().constData())->asUnicodeString() :
- QString();
+ QString str;
+ if (auto hrdMsgOrigin = mOrigMsg->headerByType(hdr.toLocal8Bit().constData())) {
+ str = hrdMsgOrigin->asUnicodeString();
+ }
plainBody.append(str);
const QString body = plainToHtml(str);
htmlBody.append(body);
@@ -720,10 +720,10 @@ void TemplateParser::processWithTemplate(const QString &tmpl)
int len = parseQuotes(QStringLiteral("HEADER="), cmd, q);
i += len;
const QString hdr = q;
- const QString str =
- mMsg->headerByType(hdr.toLocal8Bit().constData()) ?
- mMsg->headerByType(hdr.toLocal8Bit().constData())->asUnicodeString() :
- QString();
+ QString str;
+ if (auto hrdMsgOrigin = mOrigMsg->headerByType(hdr.toLocal8Bit().constData())) {
+ str = hrdMsgOrigin->asUnicodeString();
+ }
plainBody.append(str);
const QString body = plainToHtml(str);
htmlBody.append(body);
@@ -740,10 +740,10 @@ void TemplateParser::processWithTemplate(const QString &tmpl)
} else {
i += re.matchedLength();
const QString hdr = re.cap(1);
- const QString str =
- mMsg->headerByType(hdr.toLocal8Bit().constData()) ?
- mMsg->headerByType(hdr.toLocal8Bit().constData())->asUnicodeString() :
- QString();
+ QString str;
+ if (auto hrdMsgOrigin = mOrigMsg->headerByType(hdr.toLocal8Bit().constData())) {
+ str = hrdMsgOrigin->asUnicodeString();
+ }
plainBody.append(str);
const QString body = plainToHtml(str);
htmlBody.append(body);