diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-10-18 20:33:00 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-10-18 20:33:00 +0200 |
commit | be38c2ebaa77b116028cbe34f777e3d8e5cbc776 (patch) | |
tree | ef5372b4a87c442b7242b904396006ceecdd744a /framework/domain/messageparser_new.cpp | |
parent | 2e83f97afb05d6475bc39375400e7846bd77bdff (diff) | |
download | kube-be38c2ebaa77b116028cbe34f777e3d8e5cbc776.tar.gz kube-be38c2ebaa77b116028cbe34f777e3d8e5cbc776.zip |
output content from content item
Diffstat (limited to 'framework/domain/messageparser_new.cpp')
-rw-r--r-- | framework/domain/messageparser_new.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp index 2a3b68e9..db4b36c5 100644 --- a/framework/domain/messageparser_new.cpp +++ b/framework/domain/messageparser_new.cpp | |||
@@ -298,6 +298,7 @@ QHash<int, QByteArray> NewModel::roleNames() const | |||
298 | QHash<int, QByteArray> roles; | 298 | QHash<int, QByteArray> roles; |
299 | roles[TypeRole] = "type"; | 299 | roles[TypeRole] = "type"; |
300 | roles[ContentsRole] = "contents"; | 300 | roles[ContentsRole] = "contents"; |
301 | roles[ContentRole] = "content"; | ||
301 | roles[IsEmbededRole] = "embeded"; | 302 | roles[IsEmbededRole] = "embeded"; |
302 | roles[SecurityLevelRole] = "securityLevel"; | 303 | roles[SecurityLevelRole] = "securityLevel"; |
303 | return roles; | 304 | return roles; |
@@ -330,26 +331,27 @@ QVariant NewModel::data(const QModelIndex &index, int role) const | |||
330 | } | 331 | } |
331 | if (index.internalPointer()) { | 332 | if (index.internalPointer()) { |
332 | const auto entry = static_cast<Entry *>(index.internalPointer()); | 333 | const auto entry = static_cast<Entry *>(index.internalPointer()); |
333 | const auto data = entry->mData; | 334 | const auto _data = entry->mData; |
334 | if (data->userType() == qMetaTypeId<Signature *>()) { | 335 | if (_data->userType() == qMetaTypeId<Signature *>()) { |
335 | const auto signature = data->value<Signature *>(); | 336 | const auto signature = _data->value<Signature *>(); |
336 | int i = d->getPos(signature); | 337 | int i = d->getPos(signature); |
337 | switch(role) { | 338 | switch(role) { |
338 | case Qt::DisplayRole: | 339 | case Qt::DisplayRole: |
339 | case TypeRole: | ||
340 | return QStringLiteral("Signature%1").arg(i); | 340 | return QStringLiteral("Signature%1").arg(i); |
341 | case TypeRole: | ||
342 | return QStringLiteral("Signature"); | ||
341 | } | 343 | } |
342 | } else if (data->userType() == qMetaTypeId<Encryption *>()) { | 344 | } else if (_data->userType() == qMetaTypeId<Encryption *>()) { |
343 | const auto first = d->mParts.first(); | 345 | const auto encryption = _data->value<Encryption *>(); |
344 | const auto encryption = data->value<Encryption *>(); | ||
345 | int i = d->getPos(encryption); | 346 | int i = d->getPos(encryption); |
346 | switch(role) { | 347 | switch(role) { |
347 | case Qt::DisplayRole: | 348 | case Qt::DisplayRole: |
348 | case TypeRole: | ||
349 | return QStringLiteral("Encryption%1").arg(i); | 349 | return QStringLiteral("Encryption%1").arg(i); |
350 | case TypeRole: | ||
351 | return QStringLiteral("Encryption"); | ||
350 | } | 352 | } |
351 | } else if (data->userType() == qMetaTypeId<Part *>()) { | 353 | } else if (_data->userType() == qMetaTypeId<Part *>()) { |
352 | const auto part = data->value<Part *>(); | 354 | const auto part = _data->value<Part *>(); |
353 | switch (role) { | 355 | switch (role) { |
354 | case Qt::DisplayRole: | 356 | case Qt::DisplayRole: |
355 | case TypeRole: | 357 | case TypeRole: |
@@ -361,13 +363,42 @@ QVariant NewModel::data(const QModelIndex &index, int role) const | |||
361 | case ContentsRole: | 363 | case ContentsRole: |
362 | return QVariant::fromValue<QAbstractItemModel *>(d->mContentMap.value(part).get()); | 364 | return QVariant::fromValue<QAbstractItemModel *>(d->mContentMap.value(part).get()); |
363 | } | 365 | } |
364 | } else if (data->userType() == qMetaTypeId<Content *>()) { | 366 | } else if (_data->userType() == qMetaTypeId<Content *>()) { |
365 | const auto content = data->value<Content *>(); | 367 | const auto content = _data->value<Content *>(); |
366 | int i = d->getPos(content); | 368 | int i = d->getPos(content); |
367 | switch(role) { | 369 | switch(role) { |
368 | case Qt::DisplayRole: | 370 | case Qt::DisplayRole: |
369 | case TypeRole: | ||
370 | return QStringLiteral("Content%1").arg(i); | 371 | return QStringLiteral("Content%1").arg(i); |
372 | case TypeRole: | ||
373 | return QString::fromLatin1(content->type()); | ||
374 | case IsEmbededRole: | ||
375 | return false; | ||
376 | case ContentRole: { | ||
377 | auto text = content->encodedContent(); | ||
378 | if (data(index, TypeRole).toString() == "HtmlContent") { | ||
379 | const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); | ||
380 | int pos = 0; | ||
381 | while ((pos = rx.indexIn(text, pos)) != -1) { | ||
382 | const auto link = QUrl(rx.cap(3).toUtf8()); | ||
383 | pos += rx.matchedLength(); | ||
384 | const auto repl = d->mParser->getPart(link); | ||
385 | if (!repl) { | ||
386 | continue; | ||
387 | } | ||
388 | const auto content = repl->content(); | ||
389 | if(content.size() < 1) { | ||
390 | continue; | ||
391 | } | ||
392 | const auto mailMime = content.first()->mailMime(); | ||
393 | const auto mimetype = mailMime->mimetype().name(); | ||
394 | if (mimetype.startsWith("image/")) { | ||
395 | const auto data = content.first()->content(); | ||
396 | text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | return text; | ||
401 | } | ||
371 | } | 402 | } |
372 | } | 403 | } |
373 | } | 404 | } |