viewer_p.cpp 113 KB
Newer Older
1 2 3 4 5
/*
  Copyright (c) 1997 Markus Wuebben <markus.wuebben@kde.org>
  Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
  Copyright (c) 2009 Andras Mantia <andras@kdab.net>
  Copyright (c) 2010 Torgny Nyblom <nyblom@kde.org>
Laurent Montel's avatar
Laurent Montel committed
6
  Copyright (C) 2011-2017 Laurent Montel <montel@kde.org>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//#define MESSAGEVIEWER_READER_HTML_DEBUG 1
#include "viewer_p.h"
#include "viewer.h"
25

26
#include "messageviewer_debug.h"
Sandro Knauß's avatar
Sandro Knauß committed
27
#include "utils/mimetype.h"
28 29 30
#include "viewer/objecttreeemptysource.h"
#include "viewer/objecttreeviewersource.h"
#include "messagedisplayformatattribute.h"
31
#include "utils/iconnamecache.h"
32 33 34 35 36 37 38 39 40 41 42
#include "scamdetection/scamdetectionwarningwidget.h"
#include "scamdetection/scamattribute.h"
#include "viewer/mimeparttree/mimeparttreeview.h"
#include "widgets/openattachmentfolderwidget.h"
#include "messageviewer/headerstyle.h"
#include "messageviewer/headerstrategy.h"
#include "kpimtextedit/slidecontainer.h"
#include "Gravatar/GravatarCache"
#include "gravatarsettings.h"
#include "job/attachmenteditjob.h"
#include "job/modifymessagedisplayformatjob.h"
43
#include "config-messageviewer.h"
44
#include "webengine/mailwebenginescript.h"
45
#include "viewerplugins/viewerplugintoolmanager.h"
Laurent Montel's avatar
Laurent Montel committed
46
#include <WebEngineViewer/WebEnginePrintMessageBox>
Laurent Montel's avatar
Laurent Montel committed
47
#include <KContacts/VCardConverter>
Laurent Montel's avatar
Laurent Montel committed
48
#include <webengineviewer/config-webengineviewer.h>
49
#include "htmlwriter/webengineembedpart.h"
50
#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
51
#include <MimeMessagePart/FileHtmlWriter>
52 53
#include "htmlwriter/teehtmlwriter.h"
#endif
54
#include <PimCommon/NetworkUtil>
55 56 57 58 59 60 61 62 63
#include <unistd.h> // link()
#include <errno.h>
//KDE includes
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QAction>
#include <KActionCollection>
#include <KActionMenu>
#include <KCharsets>
Laurent Montel's avatar
Laurent Montel committed
64

65 66 67 68 69 70
#include <QMenu>
#include <KMessageBox>
#include <KMimeTypeChooser>
#include <KMimeTypeTrader>
#include <KRun>
#include <KSelectAction>
71
#include <KSharedConfig>
72 73 74 75 76 77 78 79 80 81 82
#include <KStandardGuiItem>
#include <QTemporaryDir>
#include <KToggleAction>
#include <QIcon>
#include <kfileitemactions.h>
#include <KLocalizedString>
#include <QMimeData>
#include <KEmailAddress>
#include <AkonadiCore/ItemModifyJob>
#include <AkonadiCore/ItemCreateJob>

Laurent Montel's avatar
Laurent Montel committed
83
#include <mailtransportakonadi/errorattribute.h>
84 85 86 87 88 89 90 91

//Qt includes
#include <QClipboard>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QItemSelectionModel>
#include <QSignalMapper>
#include <QSplitter>
92
#include <QTemporaryFile>
93 94 95 96
#include <QTreeView>
#include <QPrinter>
#include <QPrintDialog>
#include <QMimeDatabase>
Laurent Montel's avatar
Laurent Montel committed
97
#include <QWheelEvent>
Laurent Montel's avatar
Laurent Montel committed
98
#include <QPointer>
Laurent Montel's avatar
Laurent Montel committed
99
#include <WebEngineViewer/WebEngineExportHtmlPageJob>
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
//libkdepim
#include "Libkdepim/BroadcastStatus"
#include <MessageCore/AttachmentPropertiesDialog>

#include <AkonadiCore/collection.h>
#include <AkonadiCore/itemfetchjob.h>
#include <AkonadiCore/itemfetchscope.h>
#include <Akonadi/KMime/MessageStatus>
#include <Akonadi/KMime/SpecialMailCollections>
#include <AkonadiCore/attributefactory.h>
#include <Akonadi/KMime/MessageParts>

//own includes
#include "widgets/attachmentdialog.h"
#include "viewer/attachmentstrategy.h"
#include "csshelper.h"
#include "settings/messageviewersettings.h"
#include "widgets/htmlstatusbar.h"
#include "viewer/mimeparttree/mimetreemodel.h"
119 120
#include <MimeTreeParser/NodeHelper>
#include <MimeTreeParser/ObjectTreeParser>
121 122
#include "viewer/urlhandlermanager.h"
#include "messageviewer/messageviewerutil.h"
123
#include "utils/messageviewerutil_p.h"
124
#include "widgets/vcardviewer.h"
125

Laurent Montel's avatar
Laurent Montel committed
126
#include <WebEngineViewer/FindBarWebEngineView>
127
#include "viewer/webengine/mailwebengineview.h"
Laurent Montel's avatar
Laurent Montel committed
128 129
#include "htmlwriter/webengineparthtmlwriter.h"
#include <widgets/mailsourcewebengineviewer.h>
Laurent Montel's avatar
Laurent Montel committed
130
#include <WebEngineViewer/WebHitTestResult>
131
#include "header/headerstylemenumanager.h"
132
#include "widgets/submittedformwarningwidget.h"
Laurent Montel's avatar
Laurent Montel committed
133
#include <WebEngineViewer/LocalDataBaseManager>
134

135 136
#include <MimeTreeParser/BodyPart>
#include <MimeTreeParser/HtmlWriter>
137 138 139 140 141 142 143 144 145 146 147 148 149 150

#include <MessageCore/StringUtil>

#include <MessageCore/NodeHelper>
#include "MessageCore/MessageCoreSettings"
#include <AkonadiCore/agentinstance.h>
#include <AkonadiCore/agentmanager.h>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/collectionfetchscope.h>

#include <boost/bind.hpp>
#include <KJobWidgets/KJobWidgets>
#include <QApplication>
#include <QStandardPaths>
151
#include <QWebEngineSettings>
152 153
#include <header/headerstyleplugin.h>
#include <viewerplugins/viewerplugininterface.h>
Laurent Montel's avatar
Laurent Montel committed
154
#include <WebEngineViewer/ZoomActionMenu>
155 156 157 158 159 160 161 162 163 164 165 166
#include <kpimtextedit/texttospeechwidget.h>

#include <grantleetheme/grantleethememanager.h>
#include <grantleetheme/grantleetheme.h>

using namespace boost;
using namespace MailTransport;
using namespace MessageViewer;
using namespace MessageCore;

static QAtomicInt _k_attributeInitialized;

167 168 169 170
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
    R *receiver;
    void (C::*memberFun)(Arg);
Laurent Montel's avatar
Laurent Montel committed
171 172
    void operator()(Arg result)
    {
173 174 175 176 177 178 179 180 181 182 183
        (receiver->*memberFun)(result);
    }
};

template<typename Arg, typename R, typename C>
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
{
    InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
    return wrapper;
}

184 185 186
ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
                             KActionCollection *actionCollection)
    : QObject(aParent),
187
      mNodeHelper(new MimeTreeParser::NodeHelper),
Laurent Montel's avatar
Laurent Montel committed
188 189
      mViewer(nullptr),
      mFindBar(nullptr),
Laurent Montel's avatar
Laurent Montel committed
190 191 192
      mAttachmentStrategy(nullptr),
      mUpdateReaderWinTimer(nullptr),
      mResizeTimer(nullptr),
193 194
      mOldGlobalOverrideEncoding(QStringLiteral("---")),   // init with dummy value
      mMsgDisplay(true),
Laurent Montel's avatar
Laurent Montel committed
195
      mCSSHelper(nullptr),
196 197
      mMainWindow(mainWindow),
      mActionCollection(actionCollection),
Laurent Montel's avatar
Laurent Montel committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211
      mCopyAction(nullptr),
      mCopyURLAction(nullptr),
      mUrlOpenAction(nullptr),
      mSelectAllAction(nullptr),
      mScrollUpAction(nullptr),
      mScrollDownAction(nullptr),
      mScrollUpMoreAction(nullptr),
      mScrollDownMoreAction(nullptr),
      mHeaderOnlyAttachmentsAction(nullptr),
      mSelectEncodingAction(nullptr),
      mToggleFixFontAction(nullptr),
      mToggleDisplayModeAction(nullptr),
      mToggleMimePartTreeAction(nullptr),
      mSpeakTextAction(nullptr),
212
      mCanStartDrag(false),
Laurent Montel's avatar
Laurent Montel committed
213
      mHtmlWriter(nullptr),
214 215
      mDecrytMessageOverwrite(false),
      mShowSignatureDetails(false),
216
      mShowAttachmentQuicklist(true),
217
      mForceEmoticons(true),
218
      mRecursionCountForDisplayMessage(0),
Laurent Montel's avatar
Laurent Montel committed
219 220
      mCurrentContent(nullptr),
      mMessagePartNode(nullptr),
221 222
      q(aParent),
      mPreviouslyViewedItem(-1),
Laurent Montel's avatar
Laurent Montel committed
223
      mScamDetectionWarning(nullptr),
Laurent Montel's avatar
Laurent Montel committed
224
      mOpenAttachmentFolderWidget(nullptr),
Laurent Montel's avatar
Laurent Montel committed
225
      mSliderContainer(nullptr),
Laurent Montel's avatar
Laurent Montel committed
226 227 228 229 230
      mShareServiceManager(nullptr),
      mHeaderStylePlugin(nullptr),
      mHeaderStyleMenuManager(nullptr),
      mViewerPluginToolManager(nullptr),
      mZoomActionMenu(nullptr),
231 232
      mCurrentPrinter(nullptr),
      mPhishingDatabase(nullptr)
233
{
Laurent Montel's avatar
Laurent Montel committed
234
    mMimePartTree = nullptr;
235 236 237 238 239 240 241
    if (!mainWindow) {
        mMainWindow = aParent;
    }
    if (_k_attributeInitialized.testAndSetAcquire(0, 1)) {
        Akonadi::AttributeFactory::registerAttribute<MessageViewer::MessageDisplayFormatAttribute>();
        Akonadi::AttributeFactory::registerAttribute<MessageViewer::ScamAttribute>();
    }
242 243 244 245
    mPhishingDatabase = new WebEngineViewer::LocalDataBaseManager(this);
    mPhishingDatabase->initialize();
    connect(mPhishingDatabase , &WebEngineViewer::LocalDataBaseManager::checkUrlFinished,
            this, &ViewerPrivate::slotCheckedUrlFinished);
Laurent Montel's avatar
Laurent Montel committed
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
    mShareServiceManager = new PimCommon::ShareServiceUrlManager(this);

    mDisplayFormatMessageOverwrite = MessageViewer::Viewer::UseGlobalSetting;
    mHtmlLoadExtOverride = false;

    mHtmlLoadExternalGlobalSetting = false;
    mHtmlMailGlobalSetting = false;

    mUpdateReaderWinTimer.setObjectName(QStringLiteral("mUpdateReaderWinTimer"));
    mResizeTimer.setObjectName(QStringLiteral("mResizeTimer"));

    mPrinting = false;

    createWidgets();
    createActions();
    initHtmlWidget();
    readConfig();

    mLevelQuote = MessageViewer::MessageViewerSettings::self()->collapseQuoteLevelSpin() - 1;

    mResizeTimer.setSingleShot(true);
    connect(&mResizeTimer, &QTimer::timeout,
            this, &ViewerPrivate::slotDelayedResize);

    mUpdateReaderWinTimer.setSingleShot(true);
    connect(&mUpdateReaderWinTimer, &QTimer::timeout,
            this, &ViewerPrivate::updateReaderWin);

    connect(mColorBar, &HtmlStatusBar::clicked,
            this, &ViewerPrivate::slotToggleHtmlMode);

    // FIXME: Don't use the full payload here when attachment loading on demand is used, just
    //        like in KMMainWidget::slotMessageActivated().
    Akonadi::ItemFetchScope fs;
    fs.fetchFullPayload();
    fs.fetchAttribute<MailTransport::ErrorAttribute>();
    fs.fetchAttribute<MessageViewer::MessageDisplayFormatAttribute>();
    fs.fetchAttribute<MessageViewer::ScamAttribute>();
    mMonitor.setItemFetchScope(fs);
    connect(&mMonitor, &Akonadi::Monitor::itemChanged,
            this, &ViewerPrivate::slotItemChanged);
    connect(&mMonitor, &Akonadi::Monitor::itemRemoved,
            this, &ViewerPrivate::slotClear);
    connect(&mMonitor, &Akonadi::Monitor::itemMoved,
            this, &ViewerPrivate::slotItemMoved);
}

ViewerPrivate::~ViewerPrivate()
{
    MessageViewer::MessageViewerSettings::self()->save();
Laurent Montel's avatar
Laurent Montel committed
297 298
    delete mHtmlWriter; mHtmlWriter = nullptr;
    delete mViewer; mViewer = nullptr;
299 300
    delete mCSSHelper;
    mNodeHelper->forceCleanTempFiles();
301
    qDeleteAll(mListMailSourceViewer);
302 303 304 305 306 307 308 309 310
    delete mNodeHelper;
}

//-----------------------------------------------------------------------------
KMime::Content *ViewerPrivate::nodeFromUrl(const QUrl &url) const
{
    return mNodeHelper->fromHREF(mMessage, url);
}

311
void ViewerPrivate::openAttachment(KMime::Content *node, const QUrl &url)
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
{
    if (!node) {
        return;
    }

    if (node->contentType(false)) {
        if (node->contentType()->mimeType() == "text/x-moz-deleted") {
            return;
        }
        if (node->contentType()->mimeType() == "message/external-body") {
            if (node->contentType()->hasParameter(QStringLiteral("url"))) {
                const QString url = node->contentType()->parameter(QStringLiteral("url"));
                KRun::runUrl(QUrl(url), QStringLiteral("text/html"), q);
                return;
            }
        }
    }

    const bool isEncapsulatedMessage = node->parent() && node->parent()->bodyIsMessage();
    if (isEncapsulatedMessage) {

        // the viewer/urlhandlermanager expects that the message (mMessage) it is passed is the root when doing index calculation
        // in urls. Simply passing the result of bodyAsMessage() does not cut it as the resulting pointer is a child in its tree.
        KMime::Message::Ptr m = KMime::Message::Ptr(new KMime::Message);
        m->setContent(node->parent()->bodyAsMessage()->encodedContent());
        m->parse();
        atmViewMsg(m);
        return;
    }
    // determine the MIME type of the attachment
    // prefer the value of the Content-Type header
    QMimeDatabase mimeDb;
    auto mimetype = mimeDb.mimeTypeForName(QString::fromLatin1(node->contentType()->mimeType().toLower()));
    if (mimetype.isValid() && mimetype.inherits(KContacts::Addressee::mimeType())) {
        showVCard(node);
        return;
    }

    // special case treatment on mac and windows
351 352 353
    QUrl atmUrl = url;
    if (url.isEmpty()) {
        atmUrl = mNodeHelper->tempFileUrlFromNode(node);
354
    }
355
    if (Util::handleUrlWithQDesktopServices(atmUrl)) {
356 357 358 359
        return;
    }

    if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
360
        mimetype = MimeTreeParser::Util::mimetype(url.isLocalFile() ? url.toLocalFile() : url.fileName());
361 362 363 364
    }
    KService::Ptr offer =
        KMimeTypeTrader::self()->preferredService(mimetype.name(), QStringLiteral("Application"));

365
    const QString filenameText = MimeTreeParser::NodeHelper::fileName(node);
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

    AttachmentDialog dialog(mMainWindow, filenameText, offer ? offer->name() : QString(),
                            QLatin1String("askSave_") + mimetype.name());
    const int choice = dialog.exec();

    if (choice == AttachmentDialog::Save) {
        QUrl currentUrl;
        if (Util::saveContents(mMainWindow, KMime::Content::List() << node, currentUrl)) {
            showOpenAttachmentFolderWidget(currentUrl);
        }
    } else if (choice == AttachmentDialog::Open) { // Open
        if (offer) {
            attachmentOpenWith(node, offer);
        } else {
            attachmentOpen(node);
        }
    } else if (choice == AttachmentDialog::OpenWith) {
        attachmentOpenWith(node);
    } else { // Cancel
        qCDebug(MESSAGEVIEWER_LOG) << "Canceled opening attachment";
    }

}

bool ViewerPrivate::deleteAttachment(KMime::Content *node, bool showWarning)
{
    if (!node) {
        return true;
    }
    KMime::Content *parent = node->parent();
    if (!parent) {
        return true;
    }

    QList<KMime::Content *> extraNodes = mNodeHelper->extraContents(mMessage.data());
    if (extraNodes.contains(node->topLevel())) {
        KMessageBox::error(mMainWindow,
                           i18n("Deleting an attachment from an encrypted or old-style mailman message is not supported."),
                           i18n("Delete Attachment"));
        return true; //cancelled
    }

    if (showWarning && KMessageBox::warningContinueCancel(mMainWindow,
            i18n("Deleting an attachment might invalidate any digital signature on this message."),
            i18n("Delete Attachment"), KStandardGuiItem::del(), KStandardGuiItem::cancel(),
            QStringLiteral("DeleteAttachmentSignatureWarning"))
            != KMessageBox::Continue) {
        return false; //cancelled
    }
    //don't confuse the model
#ifndef QT_NO_TREEVIEW
    mMimePartTree->clearModel();
#endif
    QString filename;
    QString name;
    QByteArray mimetype;
    if (node->contentDisposition(false)) {
        filename = node->contentDisposition()->filename();
    }

    if (node->contentType(false)) {
        name = node->contentType()->name();
        mimetype = node->contentType()->mimeType();
    }

    // text/plain part:
    KMime::Content *deletePart = new KMime::Content(parent);
    deletePart->contentType()->setMimeType("text/x-moz-deleted");
    deletePart->contentType()->setName(QStringLiteral("Deleted: %1").arg(name), "utf8");
    deletePart->contentDisposition()->setDisposition(KMime::Headers::CDattachment);
    deletePart->contentDisposition()->setFilename(QStringLiteral("Deleted: %1").arg(name));

    deletePart->contentType()->setCharset("utf-8");
    deletePart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit);
Laurent Montel's avatar
Laurent Montel committed
440
    QByteArray bodyMessage = QByteArrayLiteral("\nYou deleted an attachment from this message. The original MIME headers for the attachment were:");
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
    bodyMessage += ("\nContent-Type: ") + mimetype;
    bodyMessage += ("\nname=\"") + name.toUtf8() + "\"";
    bodyMessage += ("\nfilename=\"") + filename.toUtf8() + "\"";
    deletePart->setBody(bodyMessage);
    parent->replaceContent(node, deletePart);

    parent->assemble();

    KMime::Message *modifiedMessage = mNodeHelper->messageWithExtraContent(mMessage.data());
#ifndef QT_NO_TREEVIEW
    mMimePartTree->mimePartModel()->setRoot(modifiedMessage);
#endif
    mMessageItem.setPayloadFromData(modifiedMessage->encodedContent());
    Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mMessageItem);
    job->disableRevisionCheck();
    connect(job, &KJob::result, this, &ViewerPrivate::itemModifiedResult);
    return true;
}

void ViewerPrivate::itemModifiedResult(KJob *job)
{
    if (job->error()) {
        qCDebug(MESSAGEVIEWER_LOG) << "Item update failed:" << job->errorString();
    } else {
465
        setMessageItem(mMessageItem, MimeTreeParser::Force);
466 467 468 469 470 471 472 473 474 475 476 477 478 479
    }
}

void ViewerPrivate::editAttachment(KMime::Content *node, bool showWarning)
{
    MessageViewer::AttachmentEditJob *job = new MessageViewer::AttachmentEditJob(this);
    connect(job, &AttachmentEditJob::refreshMessage, this, &ViewerPrivate::slotRefreshMessage);
    job->setMainWindow(mMainWindow);
    job->setMessageItem(mMessageItem);
    job->setMessage(mMessage);
    job->addAttachment(node, showWarning);
    job->canDeleteJob();
}

Laurent Montel's avatar
Laurent Montel committed
480
void ViewerPrivate::scrollToAnchor(const QString &anchor)
481
{
Laurent Montel's avatar
Laurent Montel committed
482
    mViewer->scrollToAnchor(anchor);
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
}

void ViewerPrivate::createOpenWithMenu(QMenu *topMenu, const QString &contentTypeStr, bool fromCurrentContent)
{
    const KService::List offers = KFileItemActions::associatedApplications(QStringList() << contentTypeStr, QString());
    if (!offers.isEmpty()) {
        QMenu *menu = topMenu;
        QActionGroup *actionGroup = new QActionGroup(menu);

        if (fromCurrentContent) {
            connect(actionGroup, &QActionGroup::triggered, this, &ViewerPrivate::slotOpenWithActionCurrentContent);
        } else {
            connect(actionGroup, &QActionGroup::triggered, this, &ViewerPrivate::slotOpenWithAction);
        }

        if (offers.count() > 1) { // submenu 'open with'
            menu = new QMenu(i18nc("@title:menu", "&Open With"), topMenu);
            menu->menuAction()->setObjectName(QStringLiteral("openWith_submenu")); // for the unittest
            topMenu->addMenu(menu);
        }
Laurent Montel's avatar
Laurent Montel committed
503
        //qCDebug(MESSAGEVIEWER_LOG) << offers.count() << "offers" << topMenu << menu;
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577

        KService::List::ConstIterator it = offers.constBegin();
        KService::List::ConstIterator end = offers.constEnd();
        for (; it != end; ++it) {
            QAction *act = MessageViewer::Util::createAppAction(*it,
                           // no submenu -> prefix single offer
                           menu == topMenu, actionGroup, menu);
            menu->addAction(act);
        }

        QString openWithActionName;
        if (menu != topMenu) { // submenu
            menu->addSeparator();
            openWithActionName = i18nc("@action:inmenu Open With", "&Other...");
        } else {
            openWithActionName = i18nc("@title:menu", "&Open With...");
        }
        QAction *openWithAct = new QAction(menu);
        openWithAct->setText(openWithActionName);
        if (fromCurrentContent) {
            connect(openWithAct, &QAction::triggered, this, &ViewerPrivate::slotOpenWithDialogCurrentContent);
        } else {
            connect(openWithAct, &QAction::triggered, this, &ViewerPrivate::slotOpenWithDialog);
        }

        menu->addAction(openWithAct);
    } else { // no app offers -> Open With...
        QAction *act = new QAction(topMenu);
        act->setText(i18nc("@title:menu", "&Open With..."));
        if (fromCurrentContent) {
            connect(act, &QAction::triggered, this, &ViewerPrivate::slotOpenWithDialogCurrentContent);
        } else {
            connect(act, &QAction::triggered, this, &ViewerPrivate::slotOpenWithDialog);
        }
        topMenu->addAction(act);
    }
}

void ViewerPrivate::slotOpenWithDialogCurrentContent()
{
    if (!mCurrentContent) {
        return;
    }
    attachmentOpenWith(mCurrentContent);
}

void ViewerPrivate::slotOpenWithDialog()
{
    auto contents = selectedContents();
    if (contents.count() == 1) {
        attachmentOpenWith(contents.first());
    }
}

void ViewerPrivate::slotOpenWithActionCurrentContent(QAction *act)
{
    if (!mCurrentContent) {
        return;
    }
    KService::Ptr app = act->data().value<KService::Ptr>();
    attachmentOpenWith(mCurrentContent, app);
}

void ViewerPrivate::slotOpenWithAction(QAction *act)
{
    KService::Ptr app = act->data().value<KService::Ptr>();
    auto contents = selectedContents();
    if (contents.count() == 1) {
        attachmentOpenWith(contents.first(), app);
    }
}

void ViewerPrivate::showAttachmentPopup(KMime::Content *node, const QString &name, const QPoint &globalPos)
{
Laurent Montel's avatar
Laurent Montel committed
578 579
    Q_UNUSED(name);
    prepareHandleAttachment(node);
580 581 582 583 584 585 586 587 588 589 590
    QMenu *menu = new QMenu();
    bool deletedAttachment = false;
    if (node->contentType(false)) {
        deletedAttachment = (node->contentType()->mimeType() == "text/x-moz-deleted");
    }
    const QString contentTypeStr = QLatin1String(node->contentType()->mimeType());

    QSignalMapper *attachmentMapper = new QSignalMapper(menu);
    connect(attachmentMapper, SIGNAL(mapped(int)),
            this, SLOT(slotHandleAttachment(int)));

591
    QAction *action = menu->addAction(QIcon::fromTheme(QStringLiteral("document-open")), i18nc("to open", "Open"));
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
    action->setEnabled(!deletedAttachment);
    connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::Open);
    if (!deletedAttachment) {
        createOpenWithMenu(menu, contentTypeStr, true);
    }

    QMimeDatabase mimeDb;
    auto mimetype = mimeDb.mimeTypeForName(contentTypeStr);
    if (mimetype.isValid()) {
        const QStringList parentMimeType = mimetype.parentMimeTypes();
        if ((contentTypeStr == QLatin1String("text/plain")) ||
                (contentTypeStr == QLatin1String("image/png")) ||
                (contentTypeStr == QLatin1String("image/jpeg")) ||
                parentMimeType.contains(QStringLiteral("text/plain")) ||
                parentMimeType.contains(QStringLiteral("image/png")) ||
                parentMimeType.contains(QStringLiteral("image/jpeg"))
           ) {
            action = menu->addAction(i18nc("to view something", "View"));
            action->setEnabled(!deletedAttachment);
            connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
            attachmentMapper->setMapping(action, Viewer::View);
        }
    }

617
#if 0 //Reimplement in the future
618 619 620 621 622 623 624
    const bool attachmentInHeader = mViewer->isAttachmentInjectionPoint(globalPos);
    const bool hasScrollbar = mViewer->hasVerticalScrollBar();
    if (attachmentInHeader && hasScrollbar) {
        action = menu->addAction(i18n("Scroll To"));
        connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
        attachmentMapper->setMapping(action, Viewer::ScrollTo);
    }
625
#endif
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651

    action = menu->addAction(QIcon::fromTheme(QStringLiteral("document-save-as")), i18n("Save As..."));
    action->setEnabled(!deletedAttachment);
    connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::Save);

    action = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy"));
    action->setEnabled(!deletedAttachment);
    connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::Copy);

    const bool isEncapsulatedMessage = node->parent() && node->parent()->bodyIsMessage();
    const bool canChange = mMessageItem.isValid() && mMessageItem.parentCollection().isValid() &&
                           (mMessageItem.parentCollection().rights() != Akonadi::Collection::ReadOnly) &&
                           !isEncapsulatedMessage;

    if (MessageViewer::MessageViewerSettings::self()->allowAttachmentEditing()) {
        action = menu->addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("Edit Attachment"));
        connect(action, SIGNAL(triggered()), attachmentMapper, SLOT(map()));
        attachmentMapper->setMapping(action, Viewer::Edit);
        action->setEnabled(canChange);
    }
    action = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Delete Attachment"));
    connect(action, SIGNAL(triggered()), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::Delete);
    action->setEnabled(canChange && !deletedAttachment);
652 653 654 655 656 657
#if 0
    menu->addSeparator();

    action = menu->addAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")), i18n("Reply To Author"));
    connect(action, SIGNAL(triggered()), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::ReplyMessageToAuthor);
Laurent Montel's avatar
Laurent Montel committed
658 659 660 661 662 663

    menu->addSeparator();

    action = menu->addAction(QIcon::fromTheme(QStringLiteral("mail-reply-all")), i18n("Reply To All"));
    connect(action, SIGNAL(triggered()), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::ReplyMessageToAll);
664 665
#endif
    menu->addSeparator();
666 667 668 669 670 671 672
    action = menu->addAction(i18n("Properties"));
    connect(action, SIGNAL(triggered(bool)), attachmentMapper, SLOT(map()));
    attachmentMapper->setMapping(action, Viewer::Properties);
    menu->exec(globalPos);
    delete menu;
}

Laurent Montel's avatar
Laurent Montel committed
673
void ViewerPrivate::prepareHandleAttachment(KMime::Content *node)
674 675 676 677 678 679 680 681 682 683 684 685
{
    mCurrentContent = node;
}

QString ViewerPrivate::createAtmFileLink(const QString &atmFileName) const
{
    QFileInfo atmFileInfo(atmFileName);

    // tempfile name is /TMP/attachmentsRANDOM/atmFileInfo.fileName()"
    const QString tmpPath = QDir::tempPath() + QLatin1Char('/') +  QLatin1String("attachments");
    QDir().mkpath(tmpPath);
    QTemporaryDir *linkDir = new QTemporaryDir(tmpPath);
686
    QString linkPath = linkDir->path() + QLatin1Char('/') + atmFileInfo.fileName();
687 688 689 690 691 692
    QFile *linkFile = new QFile(linkPath);
    linkFile->open(QIODevice::ReadWrite);
    const QString linkName = linkFile->fileName();
    delete linkFile;
    delete linkDir;

693
    if (::link(QFile::encodeName(atmFileName).constData(), QFile::encodeName(linkName).constData()) == 0) {
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
        return linkName; // success
    }
    return QString();
}

KService::Ptr ViewerPrivate::getServiceOffer(KMime::Content *content)
{
    const QString fileName = mNodeHelper->writeNodeToTempFile(content);

    const QString contentTypeStr = QLatin1String(content->contentType()->mimeType());

    // determine the MIME type of the attachment
    // prefer the value of the Content-Type header
    QMimeDatabase mimeDb;
    auto mimetype = mimeDb.mimeTypeForName(contentTypeStr);

    if (mimetype.isValid() && mimetype.inherits(KContacts::Addressee::mimeType())) {
        attachmentView(content);
Laurent Montel's avatar
Laurent Montel committed
712
        return KService::Ptr(nullptr);
713 714 715 716
    }

    if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
        /*TODO(Andris) port when on-demand loading is done   && msgPart.isComplete() */
717
        mimetype = MimeTreeParser::Util::mimetype(fileName);
718 719 720 721 722 723 724 725 726 727 728 729 730
    }
    return KMimeTypeTrader::self()->preferredService(mimetype.name(), QStringLiteral("Application"));
}

KMime::Content::List ViewerPrivate::selectedContents()
{
    return mMimePartTree->selectedContents();
}

void ViewerPrivate::attachmentOpenWith(KMime::Content *node, const KService::Ptr &offer)
{
    QString name = mNodeHelper->writeNodeToTempFile(node);

731 732 733 734 735 736 737 738 739 740 741
    // Make sure that it will not deleted when we switch from message.
    QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/messageviewer_XXXXXX"));
    tempFile->open();
    const QString tmpFileName = tempFile->fileName();
    delete tempFile;

    QFile f(name);
    if (!f.copy(tmpFileName)) {
        qCDebug(MESSAGEVIEWER_LOG) << " File was not able to copy: filename: " << name << " to " << tmpFileName;
    } else {
        name = tmpFileName;
742
    }
743
    f.close();
744

745 746 747 748
    QList<QUrl> lst;
    const QFileDevice::Permissions perms = QFile::permissions(name);
    QFile::setPermissions(name, perms | QFileDevice::ReadUser | QFileDevice::WriteUser);
    const QUrl url = QUrl::fromLocalFile(name);
749 750
    lst.append(url);
    if (offer) {
Laurent Montel's avatar
Laurent Montel committed
751
        if ((!KRun::runService(*offer, lst, nullptr, true))) {
752 753 754
            QFile::remove(url.toLocalFile());
        }
    } else {
755
        if ((! KRun::displayOpenWithDialog(lst, mMainWindow, true))) {
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
            QFile::remove(url.toLocalFile());
        }
    }
}

void ViewerPrivate::attachmentOpen(KMime::Content *node)
{
    KService::Ptr offer = getServiceOffer(node);
    if (!offer) {
        qCDebug(MESSAGEVIEWER_LOG) << "got no offer";
        return;
    }
    attachmentOpenWith(node, offer);
}

771 772
bool ViewerPrivate::showEmoticons() const
{
773
    return mForceEmoticons;
774 775
}

776
MimeTreeParser::HtmlWriter *ViewerPrivate::htmlWriter() const
777 778 779 780 781 782 783 784 785
{
    return mHtmlWriter;
}

CSSHelper *ViewerPrivate::cssHelper() const
{
    return mCSSHelper;
}

786
MimeTreeParser::NodeHelper *ViewerPrivate::nodeHelper() const
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
{
    return mNodeHelper;
}

Viewer *ViewerPrivate::viewer() const
{
    return q;
}

Akonadi::Item ViewerPrivate::messageItem() const
{
    return mMessageItem;
}

KMime::Message::Ptr ViewerPrivate::message() const
{
    return mMessage;
}

bool ViewerPrivate::decryptMessage() const
{
    if (!MessageViewer::MessageViewerSettings::self()->alwaysDecrypt()) {
        return mDecrytMessageOverwrite;
    } else {
        return true;
    }
}

void ViewerPrivate::displaySplashPage(const QString &message)
{
    displaySplashPage(QStringLiteral("status.html"), {
        { QStringLiteral("icon"), QStringLiteral("kmail") },
        { QStringLiteral("name"), i18n("KMail") },
        { QStringLiteral("subtitle"), i18n("The KDE Mail Client") },
        { QStringLiteral("message"), message }
    });
}

Laurent Montel's avatar
Laurent Montel committed
825
void ViewerPrivate::displaySplashPage(const QString &templateName, const QVariantHash &data, const QByteArray &domain)
826 827 828 829 830 831
{
    mMsgDisplay = false;
    adjustLayout();

    GrantleeTheme::ThemeManager manager(QStringLiteral("splashPage"),
                                        QStringLiteral("splash.theme"),
Laurent Montel's avatar
Laurent Montel committed
832
                                        nullptr,
833 834 835
                                        QStringLiteral("messageviewer/about/"));
    GrantleeTheme::Theme theme = manager.theme(QStringLiteral("default"));
    if (theme.isValid()) {
Laurent Montel's avatar
Laurent Montel committed
836
        mViewer->setHtml(theme.render(templateName, data, domain),
837 838 839 840 841 842 843 844 845
                         QUrl::fromLocalFile(theme.absolutePath() + QLatin1Char('/')));
    } else {
        qCDebug(MESSAGEVIEWER_LOG) << "Theme error: failed to find splash theme";
    }
    mViewer->show();
}

void ViewerPrivate::enableMessageDisplay()
{
846 847 848
    if (mMsgDisplay) {
        return;
    }
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
    mMsgDisplay = true;
    adjustLayout();
}

void ViewerPrivate::displayMessage()
{
    showHideMimeTree();

    mNodeHelper->setOverrideCodec(mMessage.data(), overrideCodec());

    if (mMessageItem.hasAttribute<MessageViewer::MessageDisplayFormatAttribute>()) {
        const MessageViewer::MessageDisplayFormatAttribute *const attr = mMessageItem.attribute<MessageViewer::MessageDisplayFormatAttribute>();
        setHtmlLoadExtOverride(attr->remoteContent());
        setDisplayFormatMessageOverwrite(attr->messageFormat());
    }

    htmlWriter()->begin(QString());
    htmlWriter()->queue(mCSSHelper->htmlHead(mUseFixedFont));

    if (!mMainWindow) {
        q->setWindowTitle(mMessage->subject()->asUnicodeString());
    }

    // Don't update here, parseMsg() can overwrite the HTML mode, which would lead to flicker.
    // It is updated right after parseMsg() instead.
874
    mColorBar->setMode(MimeTreeParser::Util::Normal, HtmlStatusBar::NoUpdate);
875 876 877 878 879

    if (mMessageItem.hasAttribute<ErrorAttribute>()) {
        //TODO: Insert link to clear error so that message might be resent
        const ErrorAttribute *const attr = mMessageItem.attribute<ErrorAttribute>();
        Q_ASSERT(attr);
Laurent Montel's avatar
Laurent Montel committed
880 881 882 883 884
        if (!mForegroundError.isValid()) {
            const KColorScheme scheme = KColorScheme(QPalette::Active, KColorScheme::View);
            mForegroundError = scheme.foreground(KColorScheme::NegativeText).color();
            mBackgroundError = scheme.background(KColorScheme::NegativeBackground).color();
        }
885

Laurent Montel's avatar
Laurent Montel committed
886
        htmlWriter()->queue(QStringLiteral("<div style=\"background:%1;color:%2;border:1px solid %3\">%4</div>").arg(mBackgroundError.name(),
Laurent Montel's avatar
Astyle  
Laurent Montel committed
887 888
                            mForegroundError.name(),
                            mForegroundError.name(), attr->message().toHtmlEscaped()));
889 890 891 892 893 894 895 896 897 898
        htmlWriter()->queue(QStringLiteral("<p></p>"));
    }

    parseContent(mMessage.data());
#ifndef QT_NO_TREEVIEW
    mMimePartTree->setRoot(mNodeHelper->messageWithExtraContent(mMessage.data()));
#endif
    mColorBar->update();

    htmlWriter()->queue(QStringLiteral("</body></html>"));
899
    connect(mViewer, &MailWebEngineView::loadStarted, this, &ViewerPrivate::slotLoadStarted, Qt::UniqueConnection);
Laurent Montel's avatar
Laurent Montel committed
900
    connect(mViewer, &MailWebEngineView::loadFinished, this, &ViewerPrivate::executeCustomScriptsAfterLoading, Qt::UniqueConnection);
901
    connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotMessageRendered, Qt::UniqueConnection);
902 903 904 905 906

    const QString html = attachmentInjectionHtml();
    const QString js = html.isEmpty() ? QString() : MessageViewer::MailWebEngineScript::injectAttachments(html, QStringLiteral("attachmentInjectionPoint"));
    mViewer->addScript(js, QStringLiteral("attachment_injection"), QWebEngineScript::DocumentReady);

907 908 909
    htmlWriter()->flush();
}

910 911 912 913
void ViewerPrivate::slotLoadStarted()
{
}

914 915 916 917 918 919 920
void ViewerPrivate::collectionFetchedForStoringDecryptedMessage(KJob *job)
{
    if (job->error()) {
        return;
    }

    Akonadi::Collection col;
Laurent Montel's avatar
Laurent Montel committed
921 922
    const Akonadi::Collection::List lstCol = static_cast<Akonadi::CollectionFetchJob *>(job)->collections();
    for (const Akonadi::Collection &c : lstCol) {
923 924 925 926 927 928 929 930 931
        if (c == mMessageItem.parentCollection()) {
            col = c;
            break;
        }
    }

    if (!col.isValid()) {
        return;
    }
932
    const Akonadi::AgentInstance::List instances = Akonadi::AgentManager::self()->instances();
933 934
    const QString itemResource = col.resource();
    Akonadi::AgentInstance resourceInstance;
935
    for (const Akonadi::AgentInstance &instance : instances) {
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
        if (instance.identifier() == itemResource) {
            resourceInstance = instance;
            break;
        }
    }
    bool isInOutbox = true;
    Akonadi::Collection outboxCollection = Akonadi::SpecialMailCollections::self()->collection(
            Akonadi::SpecialMailCollections::Outbox, resourceInstance);
    if (resourceInstance.isValid() && outboxCollection != col) {
        isInOutbox = false;
    }

    if (!isInOutbox) {
        KMime::Message::Ptr unencryptedMessage = mNodeHelper->unencryptedMessage(mMessage);
        if (unencryptedMessage) {
            mMessageItem.setPayload<KMime::Message::Ptr>(unencryptedMessage);
            Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mMessageItem);
            connect(job, &KJob::result, this, &ViewerPrivate::itemModifiedResult);
        }
    }
}

958
void ViewerPrivate::postProcessMessage(MimeTreeParser::ObjectTreeParser *otp, MimeTreeParser::KMMsgEncryptionState encryptionState)
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
{
    if (MessageViewer::MessageViewerSettings::self()->storeDisplayedMessagesUnencrypted()) {

        // Hack to make sure the S/MIME CryptPlugs follows the strict requirement
        // of german government:
        // --> All received encrypted messages *must* be stored in unencrypted form
        //     after they have been decrypted once the user has read them.
        //     ( "Aufhebung der Verschluesselung nach dem Lesen" )
        //
        // note: Since there is no configuration option for this, we do that for
        //       all kinds of encryption now - *not* just for S/MIME.
        //       This could be changed in the objectTreeToDecryptedMsg() function
        //       by deciding when (or when not, resp.) to set the 'dataNode' to
        //       something different than 'curNode'.

974 975
        const bool messageAtLeastPartiallyEncrypted = (MimeTreeParser::KMMsgFullyEncrypted == encryptionState) ||
                (MimeTreeParser::KMMsgPartiallyEncrypted == encryptionState);
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
        // only proceed if we were called the normal way - not by
        // double click on the message (==not running in a separate window)
        if (decryptMessage() && // only proceed if the message has actually been decrypted
                !otp->hasPendingAsyncJobs() && // only proceed if no pending async jobs are running:
                messageAtLeastPartiallyEncrypted) {
            //check if the message is in the outbox folder
            //FIXME: using root() is too much, but using mMessageItem.parentCollection() returns no collections in job->collections()
            //FIXME: this is done async, which means it is possible that the user selects another message while
            //       this job is running. In that case, collectionFetchedForStoringDecryptedMessage() will work
            //       on the wrong item!
            Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(),
                    Akonadi::CollectionFetchJob::Recursive);
            connect(job, &KJob::result,
                    this, &ViewerPrivate::collectionFetchedForStoringDecryptedMessage);
        }
    }
}

void ViewerPrivate::parseContent(KMime::Content *content)
{
Laurent Montel's avatar
Laurent Montel committed
996
    assert(content != nullptr);
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018

    // Check if any part of this message is a v-card
    // v-cards can be either text/x-vcard or text/directory, so we need to check
    // both.
    KMime::Content *vCardContent = findContentByType(content, "text/x-vcard");
    if (!vCardContent) {
        vCardContent = findContentByType(content, "text/directory");
    }
    bool hasVCard = false;
    if (vCardContent) {
        // ### FIXME: We should only do this if the vCard belongs to the sender,
        // ### i.e. if the sender's email address is contained in the vCard.
        const QByteArray vCard = vCardContent->decodedContent();
        KContacts::VCardConverter t;
        if (!t.parseVCards(vCard).isEmpty()) {
            hasVCard = true;
            mNodeHelper->writeNodeToTempFile(vCardContent);
        }
    }

    KMime::Message *message = dynamic_cast<KMime::Message *>(content);
    if (message) {
Laurent Montel's avatar
Laurent Montel committed
1019
        htmlWriter()->queue(writeMsgHeader(message, hasVCard ? vCardContent : nullptr, true));
1020 1021 1022 1023 1024 1025
    }

    // Pass control to the OTP now, which does the real work
    mNodeHelper->removeTempFiles();
    mNodeHelper->setNodeUnprocessed(mMessage.data(), true);
    MailViewerSource otpSource(this);
1026
    MimeTreeParser::ObjectTreeParser otp(&otpSource, mNodeHelper, mMessage.data() != content /* show only single node */);
1027 1028 1029 1030 1031 1032 1033 1034
    otp.setAllowAsync(!mPrinting);
    otp.parseObjectTree(content);

    // TODO: Setting the signature state to nodehelper is not enough, it should actually
    // be added to the store, so that the message list correctly displays the signature state
    // of messages that were parsed at least once
    // store encrypted/signed status information in the KMMessage
    //  - this can only be done *after* calling parseObjectTree()
1035 1036
    MimeTreeParser::KMMsgEncryptionState encryptionState = mNodeHelper->overallEncryptionState(content);
    MimeTreeParser::KMMsgSignatureState signatureState  = mNodeHelper->overallSignatureState(content);
1037 1038 1039
    mNodeHelper->setEncryptionState(content, encryptionState);
    // Don't reset the signature state to "not signed" (e.g. if one canceled the
    // decryption of a signed messages which has already been decrypted before).
1040 1041
    if (signatureState != MimeTreeParser::KMMsgNotSigned ||
            mNodeHelper->signatureState(content) == MimeTreeParser::KMMsgSignatureStateUnknown) {
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
        mNodeHelper->setSignatureState(content, signatureState);
    }

    postProcessMessage(&otp, encryptionState);

    showHideMimeTree();
}

QString ViewerPrivate::writeMsgHeader(KMime::Message *aMsg, KMime::Content *vCardNode,
                                      bool topLevel)
{
    if (!headerStylePlugin()) {
        qCCritical(MESSAGEVIEWER_LOG) << "trying to writeMsgHeader() without a header style set!";
1055
        return {};
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
    }
    QString href;
    if (vCardNode) {
        href = mNodeHelper->asHREF(vCardNode, QStringLiteral("body"));
    }
    headerStylePlugin()->headerStyle()->setHeaderStrategy(headerStylePlugin()->headerStrategy());
    headerStylePlugin()->headerStyle()->setVCardName(href);
    headerStylePlugin()->headerStyle()->setPrinting(mPrinting);
    headerStylePlugin()->headerStyle()->setTopLevel(topLevel);
    headerStylePlugin()->headerStyle()->setAllowAsync(true);
    headerStylePlugin()->headerStyle()->setSourceObject(this);
    headerStylePlugin()->headerStyle()->setNodeHelper(mNodeHelper);
    headerStylePlugin()->headerStyle()->setMessagePath(mMessagePath);
    if (mMessageItem.isValid()) {
        Akonadi::MessageStatus status;
        status.setStatusFromFlags(mMessageItem.flags());

        headerStylePlugin()->headerStyle()->setMessageStatus(status);
Laurent Montel's avatar
Laurent Montel committed
1074
        headerStylePlugin()->headerStyle()->setCollectionName(mMessageItem.parentCollection().displayName());
Laurent Montel's avatar
Laurent Montel committed
1075 1076
    } else {
        headerStylePlugin()->headerStyle()->setCollectionName(QString());
1077
        headerStylePlugin()->headerStyle()->setReadOnlyMessage(true);
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
    }

    return headerStylePlugin()->headerStyle()->format(aMsg);
}

void ViewerPrivate::showVCard(KMime::Content *msgPart)
{
    const QByteArray vCard = msgPart->decodedContent();

    VCardViewer *vcv = new VCardViewer(mMainWindow, vCard);
    vcv->setAttribute(Qt::WA_DeleteOnClose);
    vcv->show();
}

void ViewerPrivate::initHtmlWidget()
{
    if (!htmlWriter()) {
Laurent Montel's avatar
Laurent Montel committed
1095
        mPartHtmlWriter = new WebEnginePartHtmlWriter(mViewer, nullptr);
1096 1097 1098 1099 1100 1101 1102
#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
        mHtmlWriter = new TeeHtmlWriter(new FileHtmlWriter(QString()),
                                        mPartHtmlWriter);
#else
        mHtmlWriter = mPartHtmlWriter;
#endif
    }
Laurent Montel's avatar
Laurent Montel committed
1103
    connect(mViewer->page(), &QWebEnginePage::linkHovered,
1104
            this, &ViewerPrivate::slotUrlOn);
Laurent Montel's avatar
Laurent Montel committed
1105
    connect(mViewer, &MailWebEngineView::openUrl,
1106 1107 1108
            this, &ViewerPrivate::slotUrlOpen, Qt::QueuedConnection);
    connect(mViewer, &MailWebEngineView::popupMenu,
            this, &ViewerPrivate::slotUrlPopup);
1109 1110
    connect(mViewer, &MailWebEngineView::wheelZoomChanged,
            this, &ViewerPrivate::slotWheelZoomChanged);
1111
    connect(mViewer, &MailWebEngineView::messageMayBeAScam, this, &ViewerPrivate::slotMessageMayBeAScam);
Laurent Montel's avatar
Laurent Montel committed
1112
    connect(mViewer, &MailWebEngineView::formSubmittedForbidden, this, &ViewerPrivate::slotFormSubmittedForbidden);
1113
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::showDetails, mViewer, &MailWebEngineView::slotShowDetails);
1114 1115 1116
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::moveMessageToTrash, this, &ViewerPrivate::moveMessageToTrash);
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::messageIsNotAScam, this, &ViewerPrivate::slotMessageIsNotAScam);
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::addToWhiteList, this, &ViewerPrivate::slotAddToWhiteList);
1117
    connect(mViewer, &MailWebEngineView::pageIsScrolledToBottom, this, &ViewerPrivate::pageIsScrolledToBottom);
1118 1119
}

1120 1121
void ViewerPrivate::slotWheelZoomChanged(int numSteps)
{
Laurent Montel's avatar
Laurent Montel committed
1122 1123 1124 1125 1126 1127
    if (mZoomActionMenu) {
        const qreal factor = mZoomActionMenu->zoomFactor() + numSteps * 10;
        if (factor >= 10 && factor <= 300) {
            mZoomActionMenu->setZoomFactor(factor);
            mZoomActionMenu->setWebViewerZoomFactor(factor / 100.0);
        }
1128 1129 1130
    }
}

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
void ViewerPrivate::readConfig()
{
    delete mCSSHelper;
    mCSSHelper = new CSSHelper(mViewer);

    mUseFixedFont = MessageViewer::MessageViewerSettings::self()->useFixedFont();
    if (mToggleFixFontAction) {
        mToggleFixFontAction->setChecked(mUseFixedFont);
    }

    mHtmlMailGlobalSetting = MessageViewer::MessageViewerSettings::self()->htmlMail();
    mHtmlLoadExternalGlobalSetting = MessageViewer::MessageViewerSettings::self()->htmlLoadExternal();

    readGravatarConfig();
    if (mHeaderStyleMenuManager) {
        mHeaderStyleMenuManager->readConfig();
    }

1149
    setAttachmentStrategy(MimeTreeParser::AttachmentStrategy::create(MessageViewer::MessageViewerSettings::self()->attachmentStrategy()));
1150 1151 1152 1153 1154 1155 1156 1157
    KToggleAction *raction = actionForAttachmentStrategy(attachmentStrategy());
    if (raction) {
        raction->setChecked(true);
    }

    adjustLayout();

    readGlobalOverrideCodec();
1158 1159
    mViewer->settings()->setFontSize(QWebEngineSettings::MinimumFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
    mViewer->settings()->setFontSize(QWebEngineSettings::MinimumLogicalFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
    if (mMessage) {
        update();
    }
    mColorBar->update();
}

void ViewerPrivate::readGravatarConfig()
{
    Gravatar::GravatarCache::self()->setMaximumSize(Gravatar::GravatarSettings::self()->gravatarCacheSize());
    if (!Gravatar::GravatarSettings::self()->gravatarSupportEnabled()) {
        Gravatar::GravatarCache::self()->clear();
    }
}

void ViewerPrivate::slotGeneralFontChanged()
{
    delete mCSSHelper;
    mCSSHelper = new CSSHelper(mViewer);
    if (mMessage) {
        update();
    }
}

void ViewerPrivate::writeConfig(bool sync)
{
    MessageViewer::MessageViewerSettings::self()->setUseFixedFont(mUseFixedFont);
    if (attachmentStrategy()) {
        MessageViewer::MessageViewerSettings::self()->setAttachmentStrategy(QLatin1String(attachmentStrategy()->name()));
    }
    saveSplitterSizes();
    if (sync) {
        Q_EMIT requestConfigSync();
    }
}

1195
const MimeTreeParser::AttachmentStrategy *ViewerPrivate::attachmentStrategy() const
1196 1197 1198 1199
{
    return mAttachmentStrategy;
}

1200
void ViewerPrivate::setAttachmentStrategy(const MimeTreeParser::AttachmentStrategy *strategy)
1201 1202 1203 1204
{
    if (mAttachmentStrategy == strategy) {
        return;
    }
1205 1206
    mAttachmentStrategy = strategy ? strategy : MimeTreeParser::AttachmentStrategy::smart();
    update(MimeTreeParser::Force);
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
}

QString ViewerPrivate::overrideEncoding() const
{
    return mOverrideEncoding;
}

void ViewerPrivate::setOverrideEncoding(const QString &encoding)
{
    if (encoding == mOverrideEncoding) {
        return;
    }

    mOverrideEncoding = encoding;
    if (mSelectEncodingAction) {
        if (encoding.isEmpty()) {
            mSelectEncodingAction->setCurrentItem(0);
        } else {
            const QStringList encodings = mSelectEncodingAction->items();
            int i = 0;
            for (QStringList::const_iterator it = encodings.constBegin(), end = encodings.constEnd(); it != end; ++it, ++i) {
1228
                if (MimeTreeParser::NodeHelper::encodingForName(*it) == encoding) {
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
                    mSelectEncodingAction->setCurrentItem(i);
                    break;
                }
            }
            if (i == encodings.size()) {
                // the value of encoding is unknown => use Auto
                qCWarning(MESSAGEVIEWER_LOG) << "Unknown override character encoding" << encoding
                                             << ". Using Auto instead.";
                mSelectEncodingAction->setCurrentItem(0);
                mOverrideEncoding.clear();
            }
        }
    }
1242
    update(MimeTreeParser::Force);
1243 1244 1245 1246 1247 1248 1249
}

void ViewerPrivate::setPrinting(bool enable)
{
    mPrinting = enable;
}

1250 1251 1252 1253 1254
bool ViewerPrivate::printingMode() const
{
    return mPrinting;
}

1255 1256
void ViewerPrivate::printMessage(const Akonadi::Item &message)
{
Laurent Montel's avatar
Laurent Montel committed
1257 1258
    disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMessage);
    connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMessage);
1259
    setMessageItem(message, MimeTreeParser::Force);
1260 1261 1262 1263
}

void ViewerPrivate::printPreviewMessage(const Akonadi::Item &message)
{
1264 1265
    disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
    connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
1266
    setMessageItem(message, MimeTreeParser::Force);
1267 1268 1269 1270 1271 1272 1273 1274 1275
}

void ViewerPrivate::resetStateForNewMessage()
{
    mClickedUrl.clear();
    mImageUrl.clear();
    enableMessageDisplay(); // just to make sure it's on
    mMessage.reset();
    mNodeHelper->clear();
Laurent Montel's avatar
Laurent Montel committed
1276
    mMessagePartNode = nullptr;
1277 1278 1279
#ifndef QT_NO_TREEVIEW
    mMimePartTree->clearModel();
#endif
Laurent Montel's avatar
Laurent Montel committed
1280
    mViewer->clearRelativePosition();
1281
    mViewer->hideAccessKeys();
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
    setShowSignatureDetails(false);
    mFindBar->closeBar();
    mViewerPluginToolManager->closeAllTools();
    mScamDetectionWarning->setVisible(false);
    mOpenAttachmentFolderWidget->setVisible(false);

    if (mPrinting) {
        if (MessageViewer::MessageViewerSettings::self()->respectExpandCollapseSettings()) {
            if (MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark()) {
                mLevelQuote = MessageViewer::MessageViewerSettings::self()->collapseQuoteLevelSpin() - 1;
            } else {
                mLevelQuote = -1;
            }
        } else {
            mLevelQuote = -1;
        }
1298 1299
    } else {
        mDisplayFormatMessageOverwrite = (mDisplayFormatMessageOverwrite == MessageViewer::Viewer::UseGlobalSetting) ? MessageViewer::Viewer::UseGlobalSetting : MessageViewer::Viewer::Unknown;
1300 1301 1302 1303
    }
}

void ViewerPrivate::setMessageInternal(const KMime::Message::Ptr &message,
1304
                                       MimeTreeParser::UpdateMode updateMode)
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
{
    mViewerPluginToolManager->updateActions(mMessageItem);
    mMessage = message;
    if (message) {
        mNodeHelper->setOverrideCodec(mMessage.data(), overrideCodec());
    }

#ifndef QT_NO_TREEVIEW
    mMimePartTree->setRoot(mNodeHelper->messageWithExtraContent(message.data()));
    update(updateMode);
#endif

}

1319
void ViewerPrivate::setMessageItem(const Akonadi::Item &item, MimeTreeParser::UpdateMode updateMode)
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
{
    resetStateForNewMessage();
    foreach (const Akonadi::Item::Id monitoredId, mMonitor.itemsMonitoredEx()) {
        mMonitor.setItemMonitored(Akonadi::Item(monitoredId), false);
    }
    Q_ASSERT(mMonitor.itemsMonitoredEx().isEmpty());

    mMessageItem = item;
    if (mMessageItem.isValid()) {
        mMonitor.setItemMonitored(mMessageItem, true);
    }

    if (!mMessageItem.hasPayload<KMime::Message::Ptr>()) {
        if (mMessageItem.isValid()) {
            qCWarning(MESSAGEVIEWER_LOG) << "Payload is not a MessagePtr!";
        }
        return;
    }

    setMessageInternal(mMessageItem.payload<KMime::Message::Ptr>(), updateMode);
}

1342
void ViewerPrivate::setMessage(const KMime::Message::Ptr &aMsg, MimeTreeParser::UpdateMode updateMode)
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
{
    resetStateForNewMessage();

    Akonadi::Item item;
    item.setMimeType(KMime::Message::mimeType());
    item.setPayload(aMsg);
    mMessageItem = item;

    setMessageInternal(aMsg, updateMode);
}

void ViewerPrivate::setMessagePart(KMime::Content *node)
{
    // Cancel scheduled updates of the reader window, as that would stop the
    // timer of the HTML writer, which would make viewing attachment not work
    // anymore as not all HTML is written to the HTML part.
    // We're updating the reader window here ourselves anyway.
    mUpdateReaderWinTimer.stop();

    if (node) {
        mMessagePartNode = node;
        if (node->bodyIsMessage()) {
            mMainWindow->setWindowTitle(node->bodyAsMessage()->subject()->asUnicodeString());
        } else {
1367
            QString windowTitle = MimeTreeParser::NodeHelper::fileName(node);
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
            if (windowTitle.isEmpty()) {
                windowTitle = node->contentDescription()->asUnicodeString();
            }
            if (!windowTitle.isEmpty()) {
                mMainWindow->setWindowTitle(i18n("View Attachment: %1", windowTitle));
            }
        }

        htmlWriter()->begin(QString());
        htmlWriter()->queue(mCSSHelper->htmlHead(mUseFixedFont));

        parseContent(node);

        htmlWriter()->queue(QStringLiteral("</body></html>"));
        htmlWriter()->flush();
    }
}

void ViewerPrivate::showHideMimeTree()
{
#ifndef QT_NO_TREEVIEW
    if (mimePartTreeIsEmpty()) {
        mMimePartTree->hide();
        return;
    }
    bool showMimeTree = false;
    if (MessageViewer::MessageViewerSettings::self()->mimeTreeMode() == MessageViewer::MessageViewerSettings::EnumMimeTreeMode::Always) {
        mMimePartTree->show();
        showMimeTree = true;
    } else {
        // don't rely on QSplitter maintaining sizes for hidden widgets:
        saveSplitterSizes();
        mMimePartTree->hide();
        showMimeTree = false;
    }
    if (mToggleMimePartTreeAction && (mToggleMimePartTreeAction->isChecked() != showMimeTree)) {
        mToggleMimePartTreeAction->setChecked(showMimeTree);
    }
#endif
}

void ViewerPrivate::atmViewMsg(const KMime::Message::Ptr &message)
{
    Q_ASSERT(message);
    Q_EMIT showMessage(message, overrideEncoding());
}

void ViewerPrivate::adjustLayout()
{
#ifndef QT_NO_TREEVIEW
    const int mimeH = MessageViewer::MessageViewerSettings::self()->mimePaneHeight();
    const int messageH = MessageViewer::MessageViewerSettings::self()->messagePaneHeight();
    QList<int> splitterSizes;
    splitterSizes << messageH << mimeH;

    mSplitter->addWidget(mMimePartTree);
    mSplitter->setSizes(splitterSizes);

    if (MessageViewer::MessageViewerSettings::self()->mimeTreeMode() == MessageViewer::MessageViewerSettings::EnumMimeTreeMode::Always &&
            mMsgDisplay) {
        mMimePartTree->show();
    } else {
        mMimePartTree->hide();
    }
#endif

    if (MessageViewer::MessageViewerSettings::self()->showColorBar() && mMsgDisplay) {
        mColorBar->show();
    } else {
        mColorBar->hide();
    }
}

void ViewerPrivate::saveSplitterSizes() const
{
#ifndef QT_NO_TREEVIEW
    if (!mSplitter || !mMimePartTree) {
        return;
    }
    if (mMimePartTree->isHidden()) {
        return;    // don't rely on QSplitter maintaining sizes for hidden widgets.
    }
    MessageViewer::MessageViewerSettings::self()->setMimePaneHeight(mSplitter->sizes().at(1));
    MessageViewer::MessageViewerSettings::self()->setMessagePaneHeight(mSplitter->sizes().at(0));
#endif
}

void ViewerPrivate::createWidgets()
{
    //TODO: Make a MDN bar similar to Mozillas password bar and show MDNs here as soon as a
    //      MDN enabled message is shown.
    QVBoxLayout *vlay = new QVBoxLayout(q);
    vlay->setMargin(0);
    mSplitter = new QSplitter(Qt::Vertical, q);
    connect(mSplitter, &QSplitter::splitterMoved, this, &ViewerPrivate::saveSplitterSizes);
    mSplitter->setObjectName(QStringLiteral("mSplitter"));
    mSplitter->setChildrenCollapsible(false);
    vlay->addWidget(mSplitter);
#ifndef QT_NO_TREEVIEW
    mMimePartTree = new MimePartTreeView(mSplitter);
    connect(mMimePartTree, &QAbstractItemView::activated, this, &ViewerPrivate::slotMimePartSelected);
    connect(mMimePartTree, &QWidget::customContextMenuRequested, this, &ViewerPrivate::slotMimeTreeContextMenuRequested);
#endif

    mBox = new QWidget(mSplitter);
    QHBoxLayout *mBoxHBoxLayout = new QHBoxLayout(mBox);
    mBoxHBoxLayout->setMargin(0);

    mColorBar = new HtmlStatusBar(mBox);
    mBoxHBoxLayout->addWidget(mColorBar);
    QWidget *readerBox = new QWidget(mBox);
    QVBoxLayout *readerBoxVBoxLayout = new QVBoxLayout(readerBox);
    readerBoxVBoxLayout->setMargin(0);
    mBoxHBoxLayout->addWidget(readerBox);

    mColorBar->setObjectName(QStringLiteral("mColorBar"));
    mColorBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);

1486 1487 1488 1489
    mSubmittedFormWarning = new SubmittedFormWarningWidget(readerBox);
    mSubmittedFormWarning->setObjectName(QStringLiteral("submittedformwarning"));
    readerBoxVBoxLayout->addWidget(mSubmittedFormWarning);

1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
    mScamDetectionWarning = new ScamDetectionWarningWidget(readerBox);
    mScamDetectionWarning->setObjectName(QStringLiteral("scandetectionwarning"));
    readerBoxVBoxLayout->addWidget(mScamDetectionWarning);

    mOpenAttachmentFolderWidget = new OpenAttachmentFolderWidget(readerBox);
    mOpenAttachmentFolderWidget->setObjectName(QStringLiteral("openattachementfolderwidget"));
    readerBoxVBoxLayout->addWidget(mOpenAttachmentFolderWidget);

    mTextToSpeechWidget = new KPIMTextEdit::TextToSpeechWidget(readerBox);
    mTextToSpeechWidget->setObjectName(QStringLiteral("texttospeechwidget"));
    readerBoxVBoxLayout->addWidget(mTextToSpeechWidget);

1502
    mViewer = new MailWebEngineView(mActionCollection, readerBox);
1503
    mViewer->setViewer(this);
1504 1505 1506 1507 1508
    readerBoxVBoxLayout->addWidget(mViewer);
    mViewer->setObjectName(QStringLiteral("mViewer"));

    mViewerPluginToolManager = new MessageViewer::ViewerPluginToolManager(readerBox, this);
    mViewerPluginToolManager->setActionCollection(mActionCollection);
Laurent Montel's avatar
Laurent Montel committed
1509 1510 1511 1512 1513
    mViewerPluginToolManager->setPluginName(QStringLiteral("messageviewer"));
    mViewerPluginToolManager->setServiceTypeName(QStringLiteral("MessageViewer/ViewerPlugin"));
    if (!mViewerPluginToolManager->initializePluginList()) {
        qCDebug(MESSAGEVIEWER_LOG) << " Impossible to initialize plugins";
    }
1514 1515 1516 1517 1518 1519
    mViewerPluginToolManager->createView();
    connect(mViewerPluginToolManager, &MessageViewer::ViewerPluginToolManager::activatePlugin, this, &ViewerPrivate::slotActivatePlugin);

    mSliderContainer = new KPIMTextEdit::SlideContainer(readerBox);
    mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
    readerBoxVBoxLayout->addWidget(mSliderContainer);
Laurent Montel's avatar
Laurent Montel committed
1520 1521
    mFindBar = new WebEngineViewer::FindBarWebEngineView(mViewer, q);
    connect(mFindBar, &WebEngineViewer::FindBarWebEngineView::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
    mSliderContainer->setContent(mFindBar);

#ifndef QT_NO_TREEVIEW
    mSplitter->setStretchFactor(mSplitter->indexOf(mMimePartTree), 0);
#endif
}

void ViewerPrivate::slotStyleChanged(MessageViewer::HeaderStylePlugin *plugin)
{
    mHeaderStylePlugin = plugin;
1532
    update(MimeTreeParser::Force);