viewer_p.cpp 110 KB
Newer Older
1
/*
2
3
4
5
6
  SPDX-FileCopyrightText: 1997 Markus Wuebben <markus.wuebben@kde.org>
  SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
  SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net>
  SPDX-FileCopyrightText: 2010 Torgny Nyblom <nyblom@kde.org>
  SPDX-FileCopyrightText: 2011-2020 Laurent Montel <montel@kde.org>
7

8
  SPDX-License-Identifier: GPL-2.0-or-later
9
10
11
*/
#include "viewer_p.h"
#include "viewer.h"
Laurent Montel's avatar
Laurent Montel committed
12
#include "viewerpurposemenuwidget.h"
13

14
#include "messageviewer_debug.h"
Sandro Knauß's avatar
Sandro Knauß committed
15
#include "utils/mimetype.h"
16
#include "viewer/renderer/messageviewerrenderer.h"
17
18
19
#include "viewer/objecttreeemptysource.h"
#include "viewer/objecttreeviewersource.h"
#include "messagedisplayformatattribute.h"
20
#include "utils/iconnamecache.h"
21
22
23
#include "scamdetection/scamdetectionwarningwidget.h"
#include "scamdetection/scamattribute.h"
#include "viewer/mimeparttree/mimeparttreeview.h"
24

25
26
#include "messageviewer/headerstyle.h"
#include "messageviewer/headerstrategy.h"
Laurent Montel's avatar
Laurent Montel committed
27
#include "widgets/developertooldialog.h"
Laurent Montel's avatar
Laurent Montel committed
28
#include <KPIMTextEdit/SlideContainer>
Laurent Montel's avatar
Laurent Montel committed
29

30
#include "job/modifymessagedisplayformatjob.h"
Laurent Montel's avatar
Laurent Montel committed
31

32
#include "viewerplugins/viewerplugintoolmanager.h"
Laurent Montel's avatar
Laurent Montel committed
33
#include <KContacts/VCardConverter>
34
#include "htmlwriter/webengineembedpart.h"
35
36
37
38
39
40
41
42
#include <unistd.h> // link()
//KDE includes
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QAction>
#include <KActionCollection>
#include <KActionMenu>
#include <KCharsets>
Laurent Montel's avatar
Laurent Montel committed
43
#include <QPrintPreviewDialog>
Laurent Montel's avatar
Laurent Montel committed
44

45
46
47
#include <QMenu>
#include <KMessageBox>
#include <KMimeTypeChooser>
Nicolas Fella's avatar
Nicolas Fella committed
48
#include <KApplicationTrader>
Laurent Montel's avatar
Laurent Montel committed
49
50
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
Laurent Montel's avatar
Laurent Montel committed
51
#include <KIO/ApplicationLauncherJob>
52
#include <KSelectAction>
53
#include <KSharedConfig>
54
55
56
57
#include <KStandardGuiItem>
#include <QTemporaryDir>
#include <KToggleAction>
#include <QIcon>
58
#include <KFileItemActions>
59
60
61
62
63
#include <KLocalizedString>
#include <QMimeData>
#include <KEmailAddress>
#include <AkonadiCore/ItemModifyJob>
#include <AkonadiCore/ItemCreateJob>
64
#include <messageflags.h>
65
#include <Akonadi/KMime/SpecialMailCollections>
66
#include <MailTransportAkonadi/ErrorAttribute>
67
68
69
70
71
72
73
74
75

//Qt includes
#include <QClipboard>
#include <QItemSelectionModel>
#include <QSplitter>
#include <QTreeView>
#include <QPrinter>
#include <QPrintDialog>
#include <QMimeDatabase>
Laurent Montel's avatar
Laurent Montel committed
76
#include <QWheelEvent>
Laurent Montel's avatar
Laurent Montel committed
77
#include <QPointer>
Laurent Montel's avatar
Laurent Montel committed
78
#include <WebEngineViewer/WebEngineExportHtmlPageJob>
79
//libkdepim
80
#include <PimCommon/BroadcastStatus>
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <MessageCore/AttachmentPropertiesDialog>

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

//own includes
#include "widgets/attachmentdialog.h"
#include "csshelper.h"
#include "settings/messageviewersettings.h"
#include "widgets/htmlstatusbar.h"
95
#include "viewer/attachmentstrategy.h"
96
97
98
#include "viewer/mimeparttree/mimetreemodel.h"
#include "viewer/urlhandlermanager.h"
#include "messageviewer/messageviewerutil.h"
99
#include "utils/messageviewerutil_p.h"
100
#include "widgets/vcardviewer.h"
101
#include "widgets/shownextmessagewidget.h"
102

Laurent Montel's avatar
Laurent Montel committed
103
#include <WebEngineViewer/FindBarWebEngineView>
104
#include "viewer/webengine/mailwebengineview.h"
Laurent Montel's avatar
Laurent Montel committed
105
106
#include "htmlwriter/webengineparthtmlwriter.h"
#include <widgets/mailsourcewebengineviewer.h>
Laurent Montel's avatar
Laurent Montel committed
107
#include <WebEngineViewer/WebHitTestResult>
108
#include "header/headerstylemenumanager.h"
109
#include "widgets/submittedformwarningwidget.h"
Laurent Montel's avatar
Laurent Montel committed
110
#include <WebEngineViewer/LocalDataBaseManager>
111
#include <WebEngineViewer/WebEngineExportPdfPageJob>
112

113
#include <MimeTreeParser/BodyPart>
114
#include "interfaces/htmlwriter.h"
115
116
#include <MimeTreeParser/NodeHelper>
#include <MimeTreeParser/ObjectTreeParser>
117
118
119
120

#include <MessageCore/StringUtil>

#include <MessageCore/NodeHelper>
121
122
#include <MessageCore/MessageCoreSettings>

123
124
125
126
127
128
129
130
131
#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>
132
#include <QWebEngineSettings>
133
134
#include <header/headerstyleplugin.h>
#include <viewerplugins/viewerplugininterface.h>
Laurent Montel's avatar
Laurent Montel committed
135
#include <WebEngineViewer/ZoomActionMenu>
Laurent Montel's avatar
Laurent Montel committed
136
#include <KPIMTextEdit/TextToSpeechWidget>
137
#include "widgets/mailtrackingwarningwidget.h"
138

139
#include <GrantleeTheme/GrantleeThemeManager>
Laurent Montel's avatar
Laurent Montel committed
140
#include <GrantleeTheme/GrantleeTheme>
141

142
#include "dkim-verify/dkimwidgetinfo.h"
143
#include "dkim-verify/dkimmanager.h"
Laurent Montel's avatar
Laurent Montel committed
144
#include "dkim-verify/dkimresultattribute.h"
Laurent Montel's avatar
Laurent Montel committed
145
#include "dkim-verify/dkimviewermenu.h"
Laurent Montel's avatar
Laurent Montel committed
146
#include "dkim-verify/dkimmanagerulesdialog.h"
147

148
149
150
151
152
153
154
using namespace boost;
using namespace MailTransport;
using namespace MessageViewer;
using namespace MessageCore;

static QAtomicInt _k_attributeInitialized;

155
156
157
158
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
    R *receiver;
    void (C::*memberFun)(Arg);
Laurent Montel's avatar
Laurent Montel committed
159
160
    void operator()(Arg result)
    {
161
162
163
164
165
166
167
168
169
170
171
        (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;
}

Laurent Montel's avatar
Laurent Montel committed
172
ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow, KActionCollection *actionCollection)
Laurent Montel's avatar
Laurent Montel committed
173
174
175
176
177
178
    : QObject(aParent)
    , mNodeHelper(new MimeTreeParser::NodeHelper)
    , mOldGlobalOverrideEncoding(QStringLiteral("---"))
    , mMainWindow(mainWindow)
    , mActionCollection(actionCollection)
    , q(aParent)
Laurent Montel's avatar
Laurent Montel committed
179
180
    , mSession(new Akonadi::Session("MessageViewer-"
                                    + QByteArray::number(reinterpret_cast<quintptr>(this)), this))
Laurent Montel's avatar
Laurent Montel committed
181
    , mPreviouslyViewedItemId(-1)
182
183
184
185
{
    if (!mainWindow) {
        mMainWindow = aParent;
    }
186
187
    mMessageViewerRenderer = new MessageViewerRenderer;

188
    mDkimWidgetInfo = new MessageViewer::DKIMWidgetInfo(mMainWindow);
189
190
191
192
    if (_k_attributeInitialized.testAndSetAcquire(0, 1)) {
        Akonadi::AttributeFactory::registerAttribute<MessageViewer::MessageDisplayFormatAttribute>();
        Akonadi::AttributeFactory::registerAttribute<MessageViewer::ScamAttribute>();
    }
193
194
    mPhishingDatabase = new WebEngineViewer::LocalDataBaseManager(this);
    mPhishingDatabase->initialize();
Laurent Montel's avatar
Laurent Montel committed
195
    connect(mPhishingDatabase, &WebEngineViewer::LocalDataBaseManager::checkUrlFinished,
196
            this, &ViewerPrivate::slotCheckedUrlFinished);
Laurent Montel's avatar
Laurent Montel committed
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    mShareServiceManager = new PimCommon::ShareServiceUrlManager(this);

    mDisplayFormatMessageOverwrite = MessageViewer::Viewer::UseGlobalSetting;

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

    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);

220
221
222
    connect(mNodeHelper, &MimeTreeParser::NodeHelper::update,
            this, &ViewerPrivate::update);

223
224
225
226
227
    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().
228
    mMonitor.setObjectName(QStringLiteral("MessageViewerMonitor"));
229
    mMonitor.setSession(mSession);
230
231
232
233
234
    Akonadi::ItemFetchScope fs;
    fs.fetchFullPayload();
    fs.fetchAttribute<MailTransport::ErrorAttribute>();
    fs.fetchAttribute<MessageViewer::MessageDisplayFormatAttribute>();
    fs.fetchAttribute<MessageViewer::ScamAttribute>();
Laurent Montel's avatar
Laurent Montel committed
235
    fs.fetchAttribute<MessageViewer::DKIMResultAttribute>();
236
237
238
239
240
241
242
243
244
245
246
    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()
{
247
    delete mDeveloperToolDialog;
Laurent Montel's avatar
Laurent Montel committed
248
    delete mMessageViewerRenderer;
249
    MessageViewer::MessageViewerSettings::self()->save();
Laurent Montel's avatar
Laurent Montel committed
250
251
252
253
    delete mHtmlWriter;
    mHtmlWriter = nullptr;
    delete mViewer;
    mViewer = nullptr;
254
    mNodeHelper->forceCleanTempFiles();
255
    qDeleteAll(mListMailSourceViewer);
Laurent Montel's avatar
Laurent Montel committed
256
    mMessage.clear();
257
258
259
260
261
262
263
264
265
    delete mNodeHelper;
}

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

266
void ViewerPrivate::openAttachment(KMime::Content *node, const QUrl &url)
267
268
269
270
271
{
    if (!node) {
        return;
    }

272
273
    if (auto ct = node->contentType(false)) {
        if (ct->mimeType() == "text/x-moz-deleted") {
274
275
            return;
        }
276
        if (ct->mimeType() == "message/external-body") {
Laurent Montel's avatar
Laurent Montel committed
277
            if (ct->hasParameter(QStringLiteral("url"))) {
Laurent Montel's avatar
Laurent Montel committed
278
279
280
281
                KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url, QStringLiteral("text/html"));
                job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, q));
                job->setRunExecutables(true);
                job->start();
282
283
284
285
286
287
288
289
290
                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.
Laurent Montel's avatar
Minor    
Laurent Montel committed
291
        KMime::Message::Ptr m(new KMime::Message);
292
293
        m->setContent(node->parent()->bodyAsMessage()->encodedContent());
        m->parse();
Laurent Montel's avatar
Laurent Montel committed
294
        attachmentViewMessage(m);
295
296
297
298
299
        return;
    }
    // determine the MIME type of the attachment
    // prefer the value of the Content-Type header
    QMimeDatabase mimeDb;
Laurent Montel's avatar
Laurent Montel committed
300
301
    auto mimetype
        = mimeDb.mimeTypeForName(QString::fromLatin1(node->contentType()->mimeType().toLower()));
302
303
304
305
306
307
    if (mimetype.isValid() && mimetype.inherits(KContacts::Addressee::mimeType())) {
        showVCard(node);
        return;
    }

    // special case treatment on mac and windows
308
309
310
    QUrl atmUrl = url;
    if (url.isEmpty()) {
        atmUrl = mNodeHelper->tempFileUrlFromNode(node);
311
    }
312
    if (Util::handleUrlWithQDesktopServices(atmUrl)) {
313
314
315
316
        return;
    }

    if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
Laurent Montel's avatar
Laurent Montel committed
317
318
        mimetype = MimeTreeParser::Util::mimetype(
            url.isLocalFile() ? url.toLocalFile() : url.fileName());
319
    }
Laurent Montel's avatar
Laurent Montel committed
320
    KService::Ptr offer
Nicolas Fella's avatar
Nicolas Fella committed
321
        = KApplicationTrader::preferredService(mimetype.name());
322

323
    const QString filenameText = MimeTreeParser::NodeHelper::fileName(node);
324

Laurent Montel's avatar
Laurent Montel committed
325
    QPointer<AttachmentDialog> dialog = new AttachmentDialog(mMainWindow, filenameText,
326
                                                             offer,
Laurent Montel's avatar
Laurent Montel committed
327
328
                                                             QLatin1String(
                                                                 "askSave_") + mimetype.name());
Laurent Montel's avatar
Laurent Montel committed
329
330
    const int choice = dialog->exec();
    delete dialog;
331
    if (choice == AttachmentDialog::Save) {
332
        QList<QUrl> urlList;
Laurent Montel's avatar
Laurent Montel committed
333
        if (Util::saveContents(mMainWindow, KMime::Content::List() << node, urlList)) {
334
            showSavedFileFolderWidget(urlList, MessageViewer::OpenSavedFileFolderWidget::FileType::Attachment);
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
        }
    } 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;
    }

Laurent Montel's avatar
Laurent Montel committed
359
    const QVector<KMime::Content *> extraNodes = mNodeHelper->extraContents(mMessage.data());
360
361
    if (extraNodes.contains(node->topLevel())) {
        KMessageBox::error(mMainWindow,
Laurent Montel's avatar
Laurent Montel committed
362
363
                           i18n(
                               "Deleting an attachment from an encrypted or old-style mailman message is not supported."),
364
365
366
367
368
                           i18n("Delete Attachment"));
        return true; //cancelled
    }

    if (showWarning && KMessageBox::warningContinueCancel(mMainWindow,
Laurent Montel's avatar
Laurent Montel committed
369
370
371
372
373
374
375
376
                                                          i18n(
                                                              "Deleting an attachment might invalidate any digital signature on this message."),
                                                          i18n("Delete Attachment"),
                                                          KStandardGuiItem::del(),
                                                          KStandardGuiItem::cancel(),
                                                          QStringLiteral(
                                                              "DeleteAttachmentSignatureWarning"))
        != KMessageBox::Continue) {
377
378
379
380
381
382
383
        return false; //cancelled
    }
    //don't confuse the model
    mMimePartTree->clearModel();
    QString filename;
    QString name;
    QByteArray mimetype;
Laurent Montel's avatar
Laurent Montel committed
384
385
    if (auto cd = node->contentDisposition(false)) {
        filename = cd->filename();
386
387
    }

388
389
390
    if (auto ct = node->contentType(false)) {
        name = ct->name();
        mimetype = ct->mimeType();
391
392
393
394
    }

    // text/plain part:
    KMime::Content *deletePart = new KMime::Content(parent);
Laurent Montel's avatar
Laurent Montel committed
395
396
397
    auto deleteCt = deletePart->contentType(true);
    deleteCt->setMimeType("text/x-moz-deleted");
    deleteCt->setName(QStringLiteral("Deleted: %1").arg(name), "utf8");
Laurent Montel's avatar
Laurent Montel committed
398
399
    deletePart->contentDisposition(true)->setDisposition(KMime::Headers::CDattachment);
    deletePart->contentDisposition(false)->setFilename(QStringLiteral("Deleted: %1").arg(name));
400

Laurent Montel's avatar
Laurent Montel committed
401
    deleteCt->setCharset("utf-8");
402
    deletePart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit);
Laurent Montel's avatar
Laurent Montel committed
403
404
    QByteArray bodyMessage = QByteArrayLiteral(
        "\nYou deleted an attachment from this message. The original MIME headers for the attachment were:");
405
406
407
408
409
410
411
412
413
414
415
    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());
    mMimePartTree->mimePartModel()->setRoot(modifiedMessage);
    mMessageItem.setPayloadFromData(modifiedMessage->encodedContent());
416
    Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mMessageItem, mSession);
417
418
419
420
421
422
423
424
425
426
    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 {
427
        setMessageItem(mMessageItem, MimeTreeParser::Force);
428
429
430
    }
}

Laurent Montel's avatar
Laurent Montel committed
431
void ViewerPrivate::scrollToAnchor(const QString &anchor)
432
{
Laurent Montel's avatar
Laurent Montel committed
433
    mViewer->scrollToAnchor(anchor);
434
435
}

Laurent Montel's avatar
Laurent Montel committed
436
void ViewerPrivate::createOpenWithMenu(QMenu *topMenu, const QString &contentTypeStr, bool fromCurrentContent)
437
{
Laurent Montel's avatar
Laurent Montel committed
438
439
    const KService::List offers = KFileItemActions::associatedApplications(
        QStringList() << contentTypeStr, QString());
440
441
442
443
444
    if (!offers.isEmpty()) {
        QMenu *menu = topMenu;
        QActionGroup *actionGroup = new QActionGroup(menu);

        if (fromCurrentContent) {
Laurent Montel's avatar
Laurent Montel committed
445
446
            connect(actionGroup, &QActionGroup::triggered, this,
                    &ViewerPrivate::slotOpenWithActionCurrentContent);
447
        } else {
Laurent Montel's avatar
Laurent Montel committed
448
449
            connect(actionGroup, &QActionGroup::triggered, this,
                    &ViewerPrivate::slotOpenWithAction);
450
451
452
453
454
455
456
        }

        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
457
        //qCDebug(MESSAGEVIEWER_LOG) << offers.count() << "offers" << topMenu << menu;
458

Laurent Montel's avatar
Laurent Montel committed
459
460
        for (const KService::Ptr &ser : offers) {
            QAction *act = MessageViewer::Util::createAppAction(ser,
Laurent Montel's avatar
Laurent Montel committed
461
462
                                                                // no submenu -> prefix single offer
                                                                menu == topMenu, actionGroup, menu);
463
464
465
466
467
468
469
470
471
472
473
474
475
            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) {
Laurent Montel's avatar
Laurent Montel committed
476
477
            connect(openWithAct, &QAction::triggered, this,
                    &ViewerPrivate::slotOpenWithDialogCurrentContent);
478
479
480
481
482
483
484
485
486
        } 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) {
Laurent Montel's avatar
Laurent Montel committed
487
488
            connect(act, &QAction::triggered, this,
                    &ViewerPrivate::slotOpenWithDialogCurrentContent);
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
        } else {
            connect(act, &QAction::triggered, this, &ViewerPrivate::slotOpenWithDialog);
        }
        topMenu->addAction(act);
    }
}

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

void ViewerPrivate::slotOpenWithDialog()
{
Laurent Montel's avatar
Laurent Montel committed
506
    const auto contents = selectedContents();
507
508
509
510
511
512
513
514
515
516
    if (contents.count() == 1) {
        attachmentOpenWith(contents.first());
    }
}

void ViewerPrivate::slotOpenWithActionCurrentContent(QAction *act)
{
    if (!mCurrentContent) {
        return;
    }
Laurent Montel's avatar
Laurent Montel committed
517
    const KService::Ptr app = act->data().value<KService::Ptr>();
518
519
520
521
522
    attachmentOpenWith(mCurrentContent, app);
}

void ViewerPrivate::slotOpenWithAction(QAction *act)
{
Laurent Montel's avatar
Laurent Montel committed
523
524
    const KService::Ptr app = act->data().value<KService::Ptr>();
    const auto contents = selectedContents();
525
526
527
528
529
    if (contents.count() == 1) {
        attachmentOpenWith(contents.first(), app);
    }
}

Laurent Montel's avatar
Laurent Montel committed
530
void ViewerPrivate::showAttachmentPopup(KMime::Content *node, const QString &name, const QPoint &globalPos)
531
{
Laurent Montel's avatar
Laurent Montel committed
532
    Q_UNUSED(name)
Laurent Montel's avatar
Laurent Montel committed
533
    prepareHandleAttachment(node);
534
    bool deletedAttachment = false;
Laurent Montel's avatar
Laurent Montel committed
535
536
537
    QString contentTypeStr;
    if (auto contentType = node->contentType(false)) {
        contentTypeStr = QLatin1String(contentType->mimeType());
538
    }
Laurent Montel's avatar
Laurent Montel committed
539
    deletedAttachment = (contentTypeStr == QStringLiteral("text/x-moz-deleted"));
540
541
542
543
544
545
    //Not necessary to show popup menu when attachment was removed
    if (deletedAttachment) {
        return;
    }

    QMenu menu;
546

Laurent Montel's avatar
Laurent Montel committed
547
    QAction *action
Laurent Montel's avatar
Laurent Montel committed
548
        = menu.addAction(QIcon::fromTheme(QStringLiteral("document-open")), i18nc("to open",
Laurent Montel's avatar
Laurent Montel committed
549
                                                                                  "Open"));
550
    action->setEnabled(!deletedAttachment);
Laurent Montel's avatar
Laurent Montel committed
551
552
553
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::Open);
    });
554
    if (!deletedAttachment) {
Laurent Montel's avatar
Laurent Montel committed
555
        createOpenWithMenu(&menu, contentTypeStr, true);
556
557
558
559
560
561
    }

    QMimeDatabase mimeDb;
    auto mimetype = mimeDb.mimeTypeForName(contentTypeStr);
    if (mimetype.isValid()) {
        const QStringList parentMimeType = mimetype.parentMimeTypes();
Laurent Montel's avatar
Laurent Montel committed
562
563
564
        if ((contentTypeStr == QLatin1String("text/plain"))
            || (contentTypeStr == QLatin1String("image/png"))
            || (contentTypeStr == QLatin1String("image/jpeg"))
Laurent Montel's avatar
Laurent Montel committed
565
566
567
            || parentMimeType.contains(QLatin1String("text/plain"))
            || parentMimeType.contains(QLatin1String("image/png"))
            || parentMimeType.contains(QLatin1String("image/jpeg"))
Laurent Montel's avatar
Laurent Montel committed
568
            ) {
Laurent Montel's avatar
Laurent Montel committed
569
            action = menu.addAction(i18nc("to view something", "View"));
570
            action->setEnabled(!deletedAttachment);
Laurent Montel's avatar
Laurent Montel committed
571
572
573
            connect(action, &QAction::triggered, this, [this]() {
                slotHandleAttachment(Viewer::View);
            });
574
575
576
        }
    }

Laurent Montel's avatar
Laurent Montel committed
577
578
579
580
    action = menu.addAction(i18n("Scroll To"));
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::ScrollTo);
    });
581

Laurent Montel's avatar
Laurent Montel committed
582
    action = menu.addAction(QIcon::fromTheme(QStringLiteral("document-save-as")), i18n(
Laurent Montel's avatar
Laurent Montel committed
583
                                "Save As..."));
584
    action->setEnabled(!deletedAttachment);
Laurent Montel's avatar
Laurent Montel committed
585
586
587
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::Save);
    });
588

Laurent Montel's avatar
Laurent Montel committed
589
    action = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy"));
590
    action->setEnabled(!deletedAttachment);
Laurent Montel's avatar
Laurent Montel committed
591
592
593
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::Copy);
    });
594
595

    const bool isEncapsulatedMessage = node->parent() && node->parent()->bodyIsMessage();
Laurent Montel's avatar
Laurent Montel committed
596
597
598
599
    const bool canChange = mMessageItem.isValid() && mMessageItem.parentCollection().isValid()
                           && (mMessageItem.parentCollection().rights()
                               != Akonadi::Collection::ReadOnly)
                           && !isEncapsulatedMessage;
600

Laurent Montel's avatar
Laurent Montel committed
601
    action
Laurent Montel's avatar
Laurent Montel committed
602
        = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")),
Laurent Montel's avatar
Laurent Montel committed
603
                         i18n("Delete Attachment"));
Laurent Montel's avatar
Laurent Montel committed
604
605
606
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::Delete);
    });
Laurent Montel's avatar
Laurent Montel committed
607

608
    action->setEnabled(canChange && !deletedAttachment);
609
610
611
#if 0
    menu->addSeparator();

Laurent Montel's avatar
Laurent Montel committed
612
613
614
    action
        = menu->addAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")),
                          i18n("Reply To Author"));
Laurent Montel's avatar
Laurent Montel committed
615
616
617
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::ReplyMessageToAuthor);
    });
Laurent Montel's avatar
Laurent Montel committed
618
619
620

    menu->addSeparator();

Laurent Montel's avatar
Laurent Montel committed
621
622
    action = menu->addAction(QIcon::fromTheme(QStringLiteral("mail-reply-all")), i18n(
                                 "Reply To All"));
Laurent Montel's avatar
Laurent Montel committed
623
624
625
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::ReplyMessageToAll);
    });
626
#endif
Laurent Montel's avatar
Laurent Montel committed
627
628
    menu.addSeparator();
    action = menu.addAction(i18n("Properties"));
Laurent Montel's avatar
Laurent Montel committed
629
630
631
    connect(action, &QAction::triggered, this, [this]() {
        slotHandleAttachment(Viewer::Properties);
    });
Laurent Montel's avatar
Laurent Montel committed
632
    menu.exec(globalPos);
633
634
}

Laurent Montel's avatar
Laurent Montel committed
635
void ViewerPrivate::prepareHandleAttachment(KMime::Content *node)
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
{
    mCurrentContent = node;
}

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
653
        return KService::Ptr(nullptr);
654
655
656
657
    }

    if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
        /*TODO(Andris) port when on-demand loading is done   && msgPart.isComplete() */
658
        mimetype = MimeTreeParser::Util::mimetype(fileName);
659
    }
Nicolas Fella's avatar
Nicolas Fella committed
660
    return KApplicationTrader::preferredService(mimetype.name());
661
662
}

Laurent Montel's avatar
Laurent Montel committed
663
KMime::Content::List ViewerPrivate::selectedContents() const
664
665
666
667
668
669
670
671
{
    return mMimePartTree->selectedContents();
}

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

672
    // Make sure that it will not deleted when we switch from message.
Laurent Montel's avatar
Laurent Montel committed
673
674
    QTemporaryDir *tmpDir
        = new QTemporaryDir(QDir::tempPath() + QLatin1String("/messageviewer_attachment_XXXXXX"));
675
676
677
678
679
680
681
682
683
    if (tmpDir->isValid()) {
        tmpDir->setAutoRemove(false);
        const QString path = tmpDir->path();
        delete tmpDir;
        QFile f(name);
        const QUrl tmpFileName = QUrl::fromLocalFile(name);
        const QString newPath = path + QLatin1Char('/') + tmpFileName.fileName();

        if (!f.copy(newPath)) {
Laurent Montel's avatar
Laurent Montel committed
684
            qCDebug(MESSAGEVIEWER_LOG) << " File was not able to copy: filename: " << name
Laurent Montel's avatar
Laurent Montel committed
685
                                       << " to " << path;
686
687
688
689
        } else {
            name = newPath;
        }
        f.close();
690
    } else {
691
        delete tmpDir;
692
693
    }

694
695
696
697
    QList<QUrl> lst;
    const QFileDevice::Permissions perms = QFile::permissions(name);
    QFile::setPermissions(name, perms | QFileDevice::ReadUser | QFileDevice::WriteUser);
    const QUrl url = QUrl::fromLocalFile(name);
698
    lst.append(url);
Laurent Montel's avatar
Laurent Montel committed
699
700
701
702
703
704
705

    KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(offer);
    job->setUrls({url});
    job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, mMainWindow));
    job->start();
    connect(job, &KJob::result, this, [url, job]() {
        if (job->error()) {
706
707
            QFile::remove(url.toLocalFile());
        }
Laurent Montel's avatar
Laurent Montel committed
708
    });
709
710
711
712
}

void ViewerPrivate::attachmentOpen(KMime::Content *node)
{
Laurent Montel's avatar
Laurent Montel committed
713
    const KService::Ptr offer = getServiceOffer(node);
714
715
716
717
718
719
720
    if (!offer) {
        qCDebug(MESSAGEVIEWER_LOG) << "got no offer";
        return;
    }
    attachmentOpenWith(node, offer);
}

721
722
bool ViewerPrivate::showEmoticons() const
{
723
    return mForceEmoticons;
724
725
}

726
HtmlWriter *ViewerPrivate::htmlWriter() const
727
728
729
730
731
732
{
    return mHtmlWriter;
}

CSSHelper *ViewerPrivate::cssHelper() const
{
733
    return mMessageViewerRenderer->cssHelper();
734
735
}

736
MimeTreeParser::NodeHelper *ViewerPrivate::nodeHelper() const
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
{
    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
{
Laurent Montel's avatar
Laurent Montel committed
758
    if (MessageViewer::MessageViewerSettings::self()->alwaysDecrypt()) {
759
        return true;
Laurent Montel's avatar
Laurent Montel committed
760
761
    } else {
        return mDecrytMessageOverwrite;
762
763
764
765
766
767
768
769
770
771
772
773
774
    }
}

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
775
void ViewerPrivate::displaySplashPage(const QString &templateName, const QVariantHash &data, const QByteArray &domain)
776
{
Laurent Montel's avatar
Laurent Montel committed
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
    if (mViewer) {
        mMsgDisplay = false;
        adjustLayout();

        GrantleeTheme::ThemeManager manager(QStringLiteral("splashPage"),
                                            QStringLiteral("splash.theme"),
                                            nullptr,
                                            QStringLiteral("messageviewer/about/"));
        GrantleeTheme::Theme theme = manager.theme(QStringLiteral("default"));
        if (theme.isValid()) {
            mViewer->setHtml(theme.render(templateName, data, domain),
                             QUrl::fromLocalFile(theme.absolutePath() + QLatin1Char('/')));
        } else {
            qCDebug(MESSAGEVIEWER_LOG) << "Theme error: failed to find splash theme";
        }
        mViewer->show();
793
794
795
796
797
    }
}

void ViewerPrivate::enableMessageDisplay()
{
798
799
800
    if (mMsgDisplay) {
        return;
    }
801
802
803
804
805
806
807
808
809
810
811
    mMsgDisplay = true;
    adjustLayout();
}

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

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

    if (mMessageItem.hasAttribute<MessageViewer::MessageDisplayFormatAttribute>()) {
Laurent Montel's avatar
Laurent Montel committed
812
813
        const MessageViewer::MessageDisplayFormatAttribute *const attr
            = mMessageItem.attribute<MessageViewer::MessageDisplayFormatAttribute>();
814
815
816
817
        setHtmlLoadExtOverride(attr->remoteContent());
        setDisplayFormatMessageOverwrite(attr->messageFormat());
    }

Volker Krause's avatar
Volker Krause committed
818
    htmlWriter()->begin();
Laurent Montel's avatar
Laurent Montel committed
819
    htmlWriter()->write(cssHelper()->htmlHead(mUseFixedFont));
820
821
822
823
824
825
826

    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.
827
    mColorBar->setMode(MimeTreeParser::Util::Normal, HtmlStatusBar::NoUpdate);
828
829
830
831
832

    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
833
        initializeColorFromScheme();
834

Volker Krause's avatar
Volker Krause committed
835
        htmlWriter()->write(QStringLiteral(
Laurent Montel's avatar
Laurent Montel committed
836
837
838
                                "<div style=\"background:%1;color:%2;border:1px solid %2\">%3</div>").arg(
                                mBackgroundError.name(),
                                mForegroundError.name(), attr->message().toHtmlEscaped()));
Volker Krause's avatar
Volker Krause committed
839
        htmlWriter()->write(QStringLiteral("<p></p>"));
840
841
842
843
844
845
    }

    parseContent(mMessage.data());
    mMimePartTree->setRoot(mNodeHelper->messageWithExtraContent(mMessage.data()));
    mColorBar->update();

Laurent Montel's avatar
Laurent Montel committed
846
    htmlWriter()->write(cssHelper()->endBodyHtml());
Laurent Montel's avatar
Laurent Montel committed
847
848
849
850
851
    connect(mViewer, &MailWebEngineView::loadFinished, this,
            &ViewerPrivate::executeCustomScriptsAfterLoading, Qt::UniqueConnection);
    connect(
        mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotMessageRendered,
        Qt::UniqueConnection);
852

Volker Krause's avatar
Volker Krause committed
853
    htmlWriter()->end();
854
855
856
857
}

void ViewerPrivate::parseContent(KMime::Content *content)
{
Laurent Montel's avatar
Laurent Montel committed
858
    assert(content != nullptr);
859
    mNodeHelper->removeTempFiles();
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

    // 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);

    // Pass control to the OTP now, which does the real work
    mNodeHelper->setNodeUnprocessed(mMessage.data(), true);
    MailViewerSource otpSource(this);
885
    MimeTreeParser::ObjectTreeParser otp(&otpSource, mNodeHelper);
Laurent Montel's avatar
Laurent Montel committed
886
    //TODO: needs to end up in renderer: mMessage.data() != content /* show only single node */);
887
    otp.setAllowAsync(!mPrinting);
888
    otp.parseObjectTree(content, mMessage.data() != content /* parse/show only single node */);
889
    htmlWriter()->setCodec(otp.plainTextContentCharset());
890
891
892
893
894
895
    if (message) {
        htmlWriter()->write(writeMessageHeader(message, hasVCard ? vCardContent : nullptr, true));
    }

    otpSource.render(otp.parsedPart(), mMessage.data() != content /* parse/show only single node */);

896
897
898
899
900
    // 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()
Laurent Montel's avatar
Laurent Montel committed
901
902
903
904
    MimeTreeParser::KMMsgEncryptionState encryptionState = mNodeHelper->overallEncryptionState(
        content);
    MimeTreeParser::KMMsgSignatureState signatureState
        = mNodeHelper->overallSignatureState(content);
905
906
907
    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).
Laurent Montel's avatar
Laurent Montel committed
908
909
    if (signatureState != MimeTreeParser::KMMsgNotSigned
        || mNodeHelper->signatureState(content) == MimeTreeParser::KMMsgSignatureStateUnknown) {
910
911
912
913
914
915
        mNodeHelper->setSignatureState(content, signatureState);
    }

    showHideMimeTree();
}

Laurent Montel's avatar
Laurent Montel committed
916
QString ViewerPrivate::writeMessageHeader(KMime::Message *aMsg, KMime::Content *vCardNode, bool topLevel)
917
918
{
    if (!headerStylePlugin()) {
Laurent Montel's avatar
Laurent Montel committed
919
        qCCritical(MESSAGEVIEWER_LOG) << "trying to writeMessageHeader() without a header style set!";
920
        return {};
921
    }
Laurent Montel's avatar
Laurent Montel committed
922
    HeaderStyle *style = headerStylePlugin()->headerStyle();
923
    if (vCardNode) {
Laurent Montel's avatar
Laurent Montel committed
924
        style->setVCardName(mNodeHelper->asHREF(vCardNode, QStringLiteral("body")));
925
926
    } else {
        style->setVCardName(QString());
Laurent Montel's avatar
Laurent Montel committed
927
928
929
930
931
932
933
934
    }
    style->setHeaderStrategy(headerStylePlugin()->headerStrategy());
    style->setPrinting(mPrinting);
    style->setTopLevel(topLevel);
    style->setAllowAsync(true);
    style->setSourceObject(this);
    style->setNodeHelper(mNodeHelper);
    style->setAttachmentHtml(attachmentHtml());
935
936
937
938
    if (mMessageItem.isValid()) {
        Akonadi::MessageStatus status;
        status.setStatusFromFlags(mMessageItem.flags());

Laurent Montel's avatar
Laurent Montel committed
939
        style->setMessageStatus(status);
Laurent Montel's avatar
Laurent Montel committed
940
    } else {
Laurent Montel's avatar
Laurent Montel committed
941
        style->setReadOnlyMessage(true);
942
943
    }

Laurent Montel's avatar
Laurent Montel committed
944
    return style->format(aMsg);
945
946
947
948
949
950
951
952
953
954
955
956
957
958
}

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
959
        mPartHtmlWriter = new WebEnginePartHtmlWriter(mViewer, nullptr);
960
961
        mHtmlWriter = mPartHtmlWriter;
    }
Laurent Montel's avatar
Laurent Montel committed
962
    connect(mViewer->page(), &QWebEnginePage::linkHovered,
963
            this, &ViewerPrivate::slotUrlOn);
Laurent Montel's avatar
Laurent Montel committed
964
    connect(mViewer, &MailWebEngineView::openUrl,
965
966
967
            this, &ViewerPrivate::slotUrlOpen, Qt::QueuedConnection);
    connect(mViewer, &MailWebEngineView::popupMenu,
            this, &ViewerPrivate::slotUrlPopup);
968
969
    connect(mViewer, &MailWebEngineView::wheelZoomChanged,
            this, &ViewerPrivate::slotWheelZoomChanged);
Laurent Montel's avatar
Laurent Montel committed
970
971
    connect(mViewer, &MailWebEngineView::messageMayBeAScam, this,
            &ViewerPrivate::slotMessageMayBeAScam);
972
973
    connect(mViewer, &MailWebEngineView::formSubmittedForbidden, mSubmittedFormWarning, &SubmittedFormWarningWidget::showWarning);
    connect(mViewer, &MailWebEngineView::mailTrackingFound, mMailTrackingWarning, &MailTrackingWarningWidget::addTracker);
Laurent Montel's avatar
Laurent Montel committed
974
975
976
977
978
979
980
981
982
983
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::showDetails, mViewer,
            &MailWebEngineView::slotShowDetails);
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::moveMessageToTrash, this,
            &ViewerPrivate::moveMessageToTrash);
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::messageIsNotAScam, this,
            &ViewerPrivate::slotMessageIsNotAScam);
    connect(mScamDetectionWarning, &ScamDetectionWarningWidget::addToWhiteList, this,
            &ViewerPrivate::slotAddToWhiteList);
    connect(mViewer, &MailWebEngineView::pageIsScrolledToBottom, this,
            &ViewerPrivate::pageIsScrolledToBottom);
984
985
}

Laurent Montel's avatar
Laurent Montel committed
986
void ViewerPrivate::applyZoomValue(qreal factor, bool saveConfig)
987
{
Laurent Montel's avatar
Laurent Montel committed
988
989
    if (mZoomActionMenu) {
        if (factor >= 10 && factor <= 300) {
Laurent Montel's avatar
Laurent Montel committed
990
991
992
993
994
995
996
            if (mZoomActionMenu->zoomFactor() != factor) {
                mZoomActionMenu->setZoomFactor(factor);
                mZoomActionMenu->setWebViewerZoomFactor(factor / 100.0);
                if (saveConfig) {
                    MessageViewer::MessageViewerSettings::self()->setZoomFactor(factor);
                }
            }
Laurent Montel's avatar
Laurent Montel committed
997
        }
998
999
1000
    }
}