Commit c2965204 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to optimize code

parent e6ea9a3d
Pipeline #25582 passed with stage
in 55 minutes and 14 seconds
......@@ -1398,20 +1398,20 @@ void ComposerViewBase::addAttachmentPart(KMime::Content *partToAttach)
{
MessageCore::AttachmentPart::Ptr part(new MessageCore::AttachmentPart);
if (partToAttach->contentType()->mimeType() == "multipart/digest"
|| partToAttach->contentType()->mimeType() == "message/rfc822") {
|| partToAttach->contentType(false)->mimeType() == "message/rfc822") {
// if it is a digest or a full message, use the encodedContent() of the attachment,
// which already has the proper headers
part->setData(partToAttach->encodedContent());
} else {
part->setData(partToAttach->decodedContent());
}
part->setMimeType(partToAttach->contentType()->mimeType());
part->setMimeType(partToAttach->contentType(false)->mimeType());
if (auto cd = partToAttach->contentDescription(false)) {
part->setDescription(cd->asUnicodeString());
}
if (partToAttach->contentType(false)) {
if (partToAttach->contentType()->hasParameter(QStringLiteral("name"))) {
part->setName(partToAttach->contentType()->parameter(QStringLiteral("name")));
if (auto ct = partToAttach->contentType(false)) {
if (ct->hasParameter(QStringLiteral("name"))) {
part->setName(ct->parameter(QStringLiteral("name")));
}
}
if (auto cd = partToAttach->contentDisposition(false)) {
......
......@@ -324,15 +324,15 @@ void MessageFactoryNG::createForwardAsync()
// This is a non-multipart, non-text mail (e.g. text/calendar). Construct
// a multipart/mixed mail and add the original body as an attachment.
if (!mOrigMsg->contentType()->isMultipart()
&& (!mOrigMsg->contentType()->isText()
|| (mOrigMsg->contentType()->isText() && mOrigMsg->contentType()->subType() != "html"
&& mOrigMsg->contentType()->subType() != "plain"))) {
&& (!mOrigMsg->contentType(false)->isText()
|| (mOrigMsg->contentType(false)->isText() && mOrigMsg->contentType(false)->subType() != "html"
&& mOrigMsg->contentType(false)->subType() != "plain"))) {
const uint originalIdentity = identityUoid(mOrigMsg);
MessageHelper::initFromMessage(msg, mOrigMsg, mIdentityManager, originalIdentity);
msg->removeHeader<KMime::Headers::ContentType>();
msg->removeHeader<KMime::Headers::ContentTransferEncoding>();
msg->contentType()->setMimeType("multipart/mixed");
msg->contentType(false)->setMimeType("multipart/mixed");
//TODO: Andras: somebody should check if this is correct. :)
// empty text part
......@@ -356,7 +356,7 @@ void MessageFactoryNG::createForwardAsync()
//TODO Check if this is ok
msg->setHead(mOrigMsg->head());
msg->setBody(mOrigMsg->body());
QString oldContentType = msg->contentType()->asUnicodeString();
const QString oldContentType = msg->contentType()->asUnicodeString();
const uint originalIdentity = identityUoid(mOrigMsg);
MessageHelper::initFromMessage(msg, mOrigMsg, mIdentityManager, originalIdentity);
......
......@@ -865,9 +865,9 @@ bool DefaultRendererPrivate::isHiddenHint(const MimeTreeParser::MessagePart::Ptr
bool isHtmlPreferred = (preferredMode == MimeTreeParser::Util::Html) || (preferredMode == MimeTreeParser::Util::MultipartHtml);
QByteArray mediaType("text");
if (content->contentType(false) && !content->contentType()->mediaType().isEmpty()
&& !content->contentType()->subType().isEmpty()) {
mediaType = content->contentType()->mediaType();
if (content->contentType(false) && !content->contentType(false)->mediaType().isEmpty()
&& !content->contentType(false)->subType().isEmpty()) {
mediaType = content->contentType(false)->mediaType();
}
const bool isTextPart = (mediaType == QByteArrayLiteral("text"));
......
......@@ -100,7 +100,7 @@ public:
if (node->contentType()->isText()
&& (!node->parent()
|| (node->contentDisposition()->filename().trimmed().isEmpty()
&& node->contentType()->name().trimmed().isEmpty()))) {
&& node->contentType(false)->name().trimmed().isEmpty()))) {
// text/* w/o filename parameter:
return Inline;
}
......@@ -210,7 +210,7 @@ public:
{
if (node->contentType()->isText()
&& node->contentDisposition()->filename().trimmed().isEmpty()
&& node->contentType()->name().trimmed().isEmpty()) {
&& node->contentType(false)->name().trimmed().isEmpty()) {
// text/* w/o filename parameter:
return Inline;
}
......@@ -219,7 +219,7 @@ public:
}
if (node->parent() && node->parent()->contentType()->isMultipart()
&& node->parent()->contentType()->subType() == "related") {
&& node->parent()->contentType(false)->subType() == "related") {
return Inline;
}
......
......@@ -65,8 +65,8 @@ public:
if (!name.isEmpty()) {
return name;
}
if (content->contentDescription(false)) {
const QString desc = content->contentDescription()->asUnicodeString();
if (auto ct = content->contentDescription(false)) {
const QString desc = ct->asUnicodeString();
if (!desc.isEmpty()) {
return desc;
}
......@@ -84,9 +84,9 @@ public:
QString typeForContent(KMime::Content *content)
{
if (content->contentType(false)) {
const QString contentMimeType = QString::fromLatin1(content->contentType()->mimeType());
auto mimeType = m_mimeDb.mimeTypeForName(contentMimeType);
if (auto ct = content->contentType(false)) {
const QString contentMimeType = QString::fromLatin1(ct->mimeType());
const auto mimeType = m_mimeDb.mimeTypeForName(contentMimeType);
if (!mimeType.isValid()) {
return contentMimeType;
}
......
......@@ -413,7 +413,7 @@ bool ViewerPrivate::deleteAttachment(KMime::Content *node, bool showWarning)
deletePart->contentDisposition(true)->setDisposition(KMime::Headers::CDattachment);
deletePart->contentDisposition(false)->setFilename(QStringLiteral("Deleted: %1").arg(name));
deletePart->contentType()->setCharset("utf-8");
deletePart->contentType(false)->setCharset("utf-8");
deletePart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit);
QByteArray bodyMessage = QByteArrayLiteral(
"\nYou deleted an attachment from this message. The original MIME headers for the attachment were:");
......
......@@ -58,12 +58,13 @@ MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyP
}
// we are also registered for octet-stream, in that case stop here if that's not a part for us
const auto mt = node->contentType()->mimeType();
const auto ct = node->contentType(); //Create
const auto mt = ct->mimeType();
const auto isCorrectMimeType = mt == QByteArrayLiteral("application/pkcs7-mime") || mt == QByteArrayLiteral("application/x-pkcs7-mime");
const auto hasCorrectName = mt == QByteArrayLiteral("application/octet-stream")
&& (node->contentType()->name().endsWith(QLatin1String("p7m"))
|| node->contentType()->name().endsWith(QLatin1String("p7s"))
|| node->contentType()->name().endsWith(QLatin1String("p7c")));
&& (ct->name().endsWith(QLatin1String("p7m"))
|| ct->name().endsWith(QLatin1String("p7s"))
|| ct->name().endsWith(QLatin1String("p7c")));
if (!isCorrectMimeType && !hasCorrectName) {
return {};
}
......
......@@ -992,23 +992,23 @@ bool NodeHelper::unencryptedMessage_helper(KMime::Content *node, QByteArray &res
KMime::Content headers;
headers.setHead(curNode->head());
headers.parse();
if (decryptedNode->contentType(false)) {
headers.contentType()->from7BitString(decryptedNode->contentType(false)->as7BitString(false));
if (auto ct = decryptedNode->contentType(false)) {
headers.contentType()->from7BitString(ct->as7BitString(false));
} else {
headers.removeHeader<KMime::Headers::ContentType>();
}
if (decryptedNode->contentTransferEncoding(false)) {
headers.contentTransferEncoding()->from7BitString(decryptedNode->contentTransferEncoding(false)->as7BitString(false));
if (auto ct = decryptedNode->contentTransferEncoding(false)) {
headers.contentTransferEncoding()->from7BitString(ct->as7BitString(false));
} else {
headers.removeHeader<KMime::Headers::ContentTransferEncoding>();
}
if (decryptedNode->contentDisposition(false)) {
headers.contentDisposition()->from7BitString(decryptedNode->contentDisposition(false)->as7BitString(false));
if (auto cd = decryptedNode->contentDisposition(false)) {
headers.contentDisposition()->from7BitString(cd->as7BitString(false));
} else {
headers.removeHeader<KMime::Headers::ContentDisposition>();
}
if (decryptedNode->contentDescription(false)) {
headers.contentDescription()->from7BitString(decryptedNode->contentDescription(false)->as7BitString(false));
if (auto cd = decryptedNode->contentDescription(false)) {
headers.contentDescription()->from7BitString(cd->as7BitString(false));
} else {
headers.removeHeader<KMime::Headers::ContentDescription>();
}
......
......@@ -227,14 +227,14 @@ MessagePart::Ptr ObjectTreeParser::parseObjectTreeInternal(KMime::Content *node,
ProcessResult processResult(mNodeHelper);
QByteArray mimeType("text/plain");
if (node->contentType(false) && !node->contentType()->mimeType().isEmpty()) {
mimeType = node->contentType()->mimeType();
if (auto ct = node->contentType(false)) {
mimeType = ct->mimeType();
}
// unfortunately there's many emails where we can't trust the attachment mimetype
// so try to see if we can find something better
if (mimeType == "application/octet-stream") {
NodeHelper::magicSetType(node);
mimeType = node->contentType()->mimeType();
mimeType = node->contentType(false)->mimeType();
}
const auto mp = processType(node, processResult, mimeType);
......
......@@ -32,7 +32,8 @@ using namespace MimeTreeParser::Util;
bool MimeTreeParser::Util::isTypeBlacklisted(KMime::Content *node)
{
const QByteArray mediaTypeLower = node->contentType()->mediaType().toLower();
auto contentType = node->contentType(); //Create
const QByteArray mediaTypeLower = contentType->mediaType().toLower();
bool typeBlacklisted = mediaTypeLower == QByteArrayLiteral("multipart");
if (!typeBlacklisted) {
typeBlacklisted = KMime::isCryptoPart(node);
......@@ -40,7 +41,7 @@ bool MimeTreeParser::Util::isTypeBlacklisted(KMime::Content *node)
typeBlacklisted = typeBlacklisted || node == node->topLevel();
const bool firstTextChildOfEncapsulatedMsg
= mediaTypeLower == "text"
&& node->contentType()->subType().toLower() == "plain"
&& contentType->subType().toLower() == "plain"
&& node->parent() && node->parent()->contentType()->mediaType().toLower() == "message";
return typeBlacklisted || firstTextChildOfEncapsulatedMsg;
}
......@@ -126,7 +127,8 @@ QString MimeTreeParser::Util::iconNameForContent(KMime::Content *node)
return QString();
}
QByteArray mimeType = node->contentType()->mimeType();
auto ct = node->contentType(); //Create
QByteArray mimeType = ct->mimeType();
if (mimeType.isNull() || mimeType == "application/octet-stream") {
const QString fileName = node->contentDisposition()->filename();
if (!fileName.isEmpty()) {
......@@ -136,7 +138,7 @@ QString MimeTreeParser::Util::iconNameForContent(KMime::Content *node)
}
mimeType = mimeType.toLower();
return MimeTreeParser::Util::iconNameForMimetype(QLatin1String(mimeType), node->contentDisposition()->filename(),
node->contentType()->name());
ct->name());
}
QString MimeTreeParser::Util::htmlModeToString(HtmlMode mode)
......
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