Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/viewer/objecttreeparser.cpp
Show First 20 Lines • Show All 461 Lines • ▼ Show 20 Line(s) | 461 | } else { | |||
---|---|---|---|---|---|
462 | mNodeHelper->setNodeDisplayedHidden(node, true); | 462 | mNodeHelper->setNodeDisplayedHidden(node, true); | ||
463 | } | 463 | } | ||
464 | } else if (result.isImage()) { | 464 | } else if (result.isImage()) { | ||
465 | // Embed the image | 465 | // Embed the image | ||
466 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | 466 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | ||
467 | writePartIcon(node, true); | 467 | writePartIcon(node, true); | ||
468 | } else { | 468 | } else { | ||
469 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | 469 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | ||
470 | const auto mp = TextMessagePart::Ptr(new TextMessagePart(this, node, false, false)); | 470 | const auto mp = TextMessagePart::Ptr(new TextMessagePart(this, node, false, false, mSource->decryptMessage())); | ||
471 | result.setInlineSignatureState(mp->signatureState()); | 471 | result.setInlineSignatureState(mp->signatureState()); | ||
472 | result.setInlineEncryptionState(mp->encryptionState()); | 472 | result.setInlineEncryptionState(mp->encryptionState()); | ||
473 | return mp; | 473 | return mp; | ||
474 | } | 474 | } | ||
475 | return MessagePart::Ptr(); | 475 | return MessagePart::Ptr(); | ||
476 | } | 476 | } | ||
477 | 477 | | |||
478 | KMMsgSignatureState ProcessResult::inlineSignatureState() const | 478 | KMMsgSignatureState ProcessResult::inlineSignatureState() const | ||
▲ Show 20 Lines • Show All 443 Lines • ▼ Show 20 Line(s) | 920 | const bool bDrawFrame = !isFirstTextPart | |||
922 | && !label.isEmpty(); | 922 | && !label.isEmpty(); | ||
923 | const QString fileName = mNodeHelper->writeNodeToTempFile(curNode); | 923 | const QString fileName = mNodeHelper->writeNodeToTempFile(curNode); | ||
924 | 924 | | |||
925 | // process old style not-multipart Mailman messages to | 925 | // process old style not-multipart Mailman messages to | ||
926 | // enable verification of the embedded messages' signatures | 926 | // enable verification of the embedded messages' signatures | ||
927 | //if (!isMailmanMessage(curNode) || | 927 | //if (!isMailmanMessage(curNode) || | ||
928 | // !processMailmanMessage(curNode)) { | 928 | // !processMailmanMessage(curNode)) { | ||
929 | 929 | | |||
930 | TextMessagePart::Ptr mp(new TextMessagePart(this, curNode, bDrawFrame, !fileName.isEmpty())); | 930 | TextMessagePart::Ptr mp(new TextMessagePart(this, curNode, bDrawFrame, !fileName.isEmpty(), mSource->decryptMessage())); | ||
931 | 931 | | |||
932 | result.setInlineSignatureState(mp->signatureState()); | 932 | result.setInlineSignatureState(mp->signatureState()); | ||
933 | result.setInlineEncryptionState(mp->encryptionState()); | 933 | result.setInlineEncryptionState(mp->encryptionState()); | ||
934 | 934 | | |||
935 | if (isFirstTextPart) { | 935 | if (isFirstTextPart) { | ||
936 | mPlainTextContent = mp->text(); | 936 | mPlainTextContent = mp->text(); | ||
937 | } | 937 | } | ||
938 | 938 | | |||
▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Line(s) | 1238 | if (signTestNode) { | |||
1268 | } else { | 1268 | } else { | ||
1269 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO signature found :-("; | 1269 | qCDebug(MESSAGEVIEWER_LOG) << "pkcs7 mime - NO signature found :-("; | ||
1270 | } | 1270 | } | ||
1271 | } | 1271 | } | ||
1272 | 1272 | | |||
1273 | return mp; | 1273 | return mp; | ||
1274 | } | 1274 | } | ||
1275 | 1275 | | |||
1276 | void ObjectTreeParser::writeBodyString(const QByteArray &bodyString, | | |||
1277 | const QString &fromAddress, | | |||
1278 | const QTextCodec *codec, | | |||
1279 | ProcessResult &result, | | |||
1280 | bool decorate) | | |||
1281 | { | | |||
1282 | assert(codec); | | |||
1283 | KMMsgSignatureState inlineSignatureState = result.inlineSignatureState(); | | |||
1284 | KMMsgEncryptionState inlineEncryptionState = result.inlineEncryptionState(); | | |||
1285 | writeBodyStr(bodyString, codec, fromAddress, | | |||
1286 | inlineSignatureState, inlineEncryptionState, decorate); | | |||
1287 | result.setInlineSignatureState(inlineSignatureState); | | |||
1288 | result.setInlineEncryptionState(inlineEncryptionState); | | |||
1289 | } | | |||
1290 | | ||||
1291 | void ObjectTreeParser::writePartIcon(KMime::Content *msgPart, bool inlineImage) | 1276 | void ObjectTreeParser::writePartIcon(KMime::Content *msgPart, bool inlineImage) | ||
1292 | { | 1277 | { | ||
1293 | if (!htmlWriter() || !msgPart) { | 1278 | if (!htmlWriter() || !msgPart) { | ||
1294 | return; | 1279 | return; | ||
1295 | } | 1280 | } | ||
1296 | 1281 | | |||
1297 | const QString name = msgPart->contentType()->name(); | 1282 | const QString name = msgPart->contentType()->name(); | ||
1298 | QString label = name.isEmpty() ? NodeHelper::fileName(msgPart) : name; | 1283 | QString label = name.isEmpty() ? NodeHelper::fileName(msgPart) : name; | ||
▲ Show 20 Lines • Show All 910 Lines • ▼ Show 20 Line(s) | 2191 | if (!messagePart.signerMailAddresses.empty()) { | |||
2209 | } else { | 2194 | } else { | ||
2210 | messagePart.signer += QLatin1String(" <") + messagePart.signerMailAddresses.front() + QLatin1Char('>'); | 2195 | messagePart.signer += QLatin1String(" <") + messagePart.signerMailAddresses.front() + QLatin1Char('>'); | ||
2211 | } | 2196 | } | ||
2212 | } | 2197 | } | ||
2213 | } | 2198 | } | ||
2214 | } | 2199 | } | ||
2215 | } | 2200 | } | ||
2216 | 2201 | | |||
2217 | //----------------------------------------------------------------------------- | | |||
2218 | QVector<MessagePart::Ptr> ObjectTreeParser::writeBodyStr2(const QByteArray &aStr, const QTextCodec *aCodec, | | |||
2219 | const QString &fromAddress, | | |||
2220 | KMMsgSignatureState &inlineSignatureState, | | |||
2221 | KMMsgEncryptionState &inlineEncryptionState) | | |||
2222 | { | | |||
2223 | inlineSignatureState = KMMsgNotSigned; | | |||
2224 | inlineEncryptionState = KMMsgNotEncrypted; | | |||
2225 | QList<Block> blocks = prepareMessageForDecryption(aStr); | | |||
2226 | | ||||
2227 | QVector<MessagePart::Ptr> mpl; | | |||
2228 | | ||||
2229 | if (!blocks.isEmpty()) { | | |||
2230 | | ||||
2231 | if (blocks.count() > 1 || blocks.at(0).type() != MessageViewer::NoPgpBlock) { | | |||
2232 | const Kleo::CryptoBackend::Protocol *cryptProto = Kleo::CryptoBackendFactory::instance()->openpgp(); | | |||
2233 | setCryptoProtocol(cryptProto); | | |||
2234 | } | | |||
2235 | | ||||
2236 | QString htmlStr; | | |||
2237 | QString plainTextStr; | | |||
2238 | | ||||
2239 | /* The (overall) signature/encrypted status is broken | | |||
2240 | * if one unencrypted part is at the beginning or in the middle | | |||
2241 | * because mailmain adds an unencrypted part at the end this should not break the overall status | | |||
2242 | * | | |||
2243 | * That's why we first set the tmp status and if one crypted/signed block comes afterwards, than | | |||
2244 | * the status is set to unencryped | | |||
2245 | */ | | |||
2246 | bool fullySignedOrEncrypted = true; | | |||
2247 | bool fullySignedOrEncryptedTmp = true; | | |||
2248 | | ||||
2249 | Q_FOREACH (const Block &block, blocks) { | | |||
2250 | | ||||
2251 | if (!fullySignedOrEncryptedTmp) { | | |||
2252 | fullySignedOrEncrypted = false; | | |||
2253 | } | | |||
2254 | | ||||
2255 | if (block.type() == NoPgpBlock && !block.text().trimmed().isEmpty()) { | | |||
2256 | fullySignedOrEncryptedTmp = false; | | |||
2257 | mpl.append(MessagePart::Ptr(new MessagePart(this, aCodec->toUnicode(block.text())))); | | |||
2258 | } else if (block.type() == PgpMessageBlock) { | | |||
2259 | CryptoMessagePart::Ptr mp(new CryptoMessagePart(this, QString(), cryptoProtocol(), fromAddress, 0)); | | |||
2260 | mpl.append(mp); | | |||
2261 | if (!mSource->decryptMessage()) { | | |||
2262 | continue; | | |||
2263 | } | | |||
2264 | mp->startDecryption(block.text(), aCodec); | | |||
2265 | if (mp->partMetaData()->inProgress) { | | |||
2266 | continue; | | |||
2267 | } | | |||
2268 | } else if (block.type() == ClearsignedBlock) { | | |||
2269 | CryptoMessagePart::Ptr mp(new CryptoMessagePart(this, QString(), cryptoProtocol(), fromAddress, 0)); | | |||
2270 | mpl.append(mp); | | |||
2271 | mp->startVerification(block.text(), aCodec); | | |||
2272 | } else { | | |||
2273 | continue; | | |||
2274 | } | | |||
2275 | | ||||
2276 | const PartMetaData *messagePart(mpl.last()->partMetaData()); | | |||
2277 | | ||||
2278 | if (!messagePart->isEncrypted && !messagePart->isSigned && !block.text().trimmed().isEmpty()) { | | |||
2279 | mpl.last()->setText(aCodec->toUnicode(block.text())); | | |||
2280 | } | | |||
2281 | | ||||
2282 | if (messagePart->isEncrypted) { | | |||
2283 | inlineEncryptionState = KMMsgPartiallyEncrypted; | | |||
2284 | } | | |||
2285 | | ||||
2286 | if (messagePart->isSigned) { | | |||
2287 | inlineSignatureState = KMMsgPartiallySigned; | | |||
2288 | } | | |||
2289 | } | | |||
2290 | | ||||
2291 | //Do we have an fully Signed/Encrypted Message? | | |||
2292 | if (fullySignedOrEncrypted) { | | |||
2293 | if (inlineSignatureState == KMMsgPartiallySigned) { | | |||
2294 | inlineSignatureState = KMMsgFullySigned; | | |||
2295 | } | | |||
2296 | if (inlineEncryptionState == KMMsgPartiallyEncrypted) { | | |||
2297 | inlineEncryptionState = KMMsgFullyEncrypted; | | |||
2298 | } | | |||
2299 | } | | |||
2300 | } | | |||
2301 | return mpl; | | |||
2302 | } | | |||
2303 | | ||||
2304 | void ObjectTreeParser::writeBodyStr(const QByteArray &aStr, const QTextCodec *aCodec, | | |||
2305 | const QString &fromAddress, | | |||
2306 | KMMsgSignatureState &inlineSignatureState, | | |||
2307 | KMMsgEncryptionState &inlineEncryptionState, | | |||
2308 | bool decorate) | | |||
2309 | { | | |||
2310 | const auto mpl = writeBodyStr2(aStr, aCodec, fromAddress, inlineSignatureState, inlineEncryptionState); | | |||
2311 | | ||||
2312 | if (!mpl.isEmpty()) { | | |||
2313 | if (htmlWriter()) { | | |||
2314 | foreach (const MessagePart::Ptr &mp, mpl) { | | |||
2315 | mp->html(decorate); | | |||
2316 | } | | |||
2317 | } | | |||
2318 | | ||||
2319 | const bool updatePlainText = (inlineSignatureState != KMMsgNotSigned | | |||
2320 | || inlineEncryptionState != KMMsgNotEncrypted); | | |||
2321 | if (updatePlainText || mPlainTextContent.isEmpty()) { | | |||
2322 | mPlainTextContent.clear(); | | |||
2323 | foreach (const MessagePart::Ptr &mp, mpl) { | | |||
2324 | mPlainTextContent += mp->text(); | | |||
2325 | } | | |||
2326 | mPlainTextContentCharset = aCodec->name(); | | |||
2327 | } | | |||
2328 | } | | |||
2329 | } | | |||
2330 | | ||||
2331 | static QString iconToDataUrl(const QString &iconPath) | 2202 | static QString iconToDataUrl(const QString &iconPath) | ||
2332 | { | 2203 | { | ||
2333 | QFile f(iconPath); | 2204 | QFile f(iconPath); | ||
2334 | if (!f.open(QIODevice::ReadOnly)) { | 2205 | if (!f.open(QIODevice::ReadOnly)) { | ||
2335 | return QString(); | 2206 | return QString(); | ||
2336 | } | 2207 | } | ||
2337 | 2208 | | |||
2338 | const QByteArray ba = f.readAll(); | 2209 | const QByteArray ba = f.readAll(); | ||
▲ Show 20 Lines • Show All 402 Lines • Show Last 20 Lines |