viewer_p.cpp 111 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
398
    deletePart->contentType(true)->setMimeType("text/x-moz-deleted");
    deletePart->contentType(false)->setName(QStringLiteral("Deleted: %1").arg(name), "utf8");
    deletePart->contentDisposition(true)->setDisposition(KMime::Headers::CDattachment);
    deletePart->contentDisposition(false)->setFilename(QStringLiteral("Deleted: %1").arg(name));
399

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

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

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

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

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

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

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

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

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

    QMenu menu;
545

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

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

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

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

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

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

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

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

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

    menu->addSeparator();

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

Laurent Montel's avatar
Laurent Montel committed
634
void ViewerPrivate::prepareHandleAttachment(KMime::Content *node)
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
{
    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
652
        return KService::Ptr(nullptr);
653
654
655
656
    }

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

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

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

671
    // Make sure that it will not deleted when we switch from message.
Laurent Montel's avatar
Laurent Montel committed
672
673
    QTemporaryDir *tmpDir
        = new QTemporaryDir(QDir::tempPath() + QLatin1String("/messageviewer_attachment_XXXXXX"));
674
675
676
677
678
679
680
681
682
    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
683
            qCDebug(MESSAGEVIEWER_LOG) << " File was not able to copy: filename: " << name
Laurent Montel's avatar
Laurent Montel committed
684
                                       << " to " << path;
685
686
687
688
        } else {
            name = newPath;
        }
        f.close();
689
    } else {
690
        delete tmpDir;
691
692
    }

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

    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()) {
705
706
            QFile::remove(url.toLocalFile());
        }
Laurent Montel's avatar
Laurent Montel committed
707
    });
708
709
710
711
}

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

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

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

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

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

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

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

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

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

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

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

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

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

Volker Krause's avatar
Volker Krause committed
834
        htmlWriter()->write(QStringLiteral(
Laurent Montel's avatar
Laurent Montel committed
835
836
837
                                "<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
838
        htmlWriter()->write(QStringLiteral("<p></p>"));
839
840
841
842
843
844
    }

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

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

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

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

    // 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);
884
    MimeTreeParser::ObjectTreeParser otp(&otpSource, mNodeHelper);
Laurent Montel's avatar
Laurent Montel committed
885
    //TODO: needs to end up in renderer: mMessage.data() != content /* show only single node */);
886
    otp.setAllowAsync(!mPrinting);
887
    otp.parseObjectTree(content, mMessage.data() != content /* parse/show only single node */);
888
    htmlWriter()->setCodec(otp.plainTextContentCharset());
889
890
891
892
893
894
    if (message) {
        htmlWriter()->write(writeMessageHeader(message, hasVCard ? vCardContent : nullptr, true));
    }

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

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

    showHideMimeTree();
}

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
985
void ViewerPrivate::applyZoomValue(qreal factor, bool saveConfig)
986
{
Laurent Montel's avatar
Laurent Montel committed
987
988
    if (mZoomActionMenu) {
        if (factor >= 10 && factor <= 300) {
Laurent Montel's avatar
Laurent Montel committed
989
990
991
992
993
994
995
            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
996
        }
997
998
999
    }
}

1000
void ViewerPrivate::setWebViewZoomFactor(qreal factor)