Commit 2a348ecc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Show a warning when a attachment is adding when we click on an url

parent 8a6cd433
......@@ -105,6 +105,7 @@ set(kmailprivate_warningwidgets_LIB_SRCS
editor/warningwidgets/externaleditorwarning.cpp
editor/warningwidgets/attachmentmissingwarning.cpp
editor/warningwidgets/incorrectidentityfolderwarning.cpp
editor/warningwidgets/attachmentaddedfromexternalwarning.cpp
)
set(kmailprivate_editor_potentialphishingemail_SRCS
......
......@@ -56,13 +56,18 @@ public:
};
typedef QFlags<VisibleHeaderFlag> VisibleHeaderFlags;
struct AttachmentInfo {
QString comment;
QUrl url;
};
public: // mailserviceimpl
/**
* From MailComposerIface
*/
virtual void send(int how) = 0;
virtual void addAttachmentsAndSend(const QList<QUrl> &urls, const QString &comment, int how) = 0;
virtual void addAttachment(const QUrl &url, const QString &comment) = 0;
virtual void addAttachment(const QList<AttachmentInfo> &url, bool showWarning) = 0;
virtual void addAttachment(const QString &name, KMime::Headers::contentEncoding cte, const QString &charset, const QByteArray &data, const QByteArray &mimeType) = 0;
public: // kmcommand
virtual QString dbusObjectPath() const = 0;
......
......@@ -36,6 +36,7 @@
#include "editor/potentialphishingemail/potentialphishingemailjob.h"
#include "editor/potentialphishingemail/potentialphishingemailwarning.h"
#include "editor/warningwidgets/incorrectidentityfolderwarning.h"
#include "editor/warningwidgets/attachmentaddedfromexternalwarning.h"
#include "job/addressvalidationjob.h"
#include "job/createnewcontactjob.h"
#include "job/saveasfilejob.h"
......@@ -363,6 +364,9 @@ KMComposerWin::KMComposerWin(const KMime::Message::Ptr &aMsg, bool lastSignState
mIncorrectIdentityFolderWarning = new IncorrectIdentityFolderWarning(this);
vbox->addWidget(mIncorrectIdentityFolderWarning);
mAttachmentFromExternalMissing = new AttachmentAddedFromExternalWarning(this);
vbox->addWidget(mAttachmentFromExternalMissing);
vbox->addWidget(mCryptoStateIndicatorWidget);
vbox->addWidget(mRichTextEditorwidget);
......@@ -549,7 +553,9 @@ void KMComposerWin::insertSnippetInfo(const MailCommon::SnippetInfo &info)
connect(job, &MessageComposer::ConvertSnippetVariablesJob::textConverted, this, [this](const QString &str) {
if (!str.isEmpty()) {
const QUrl localUrl = QUrl::fromLocalFile(str);
addAttachment(localUrl, QString());
AttachmentInfo info;
info.url = localUrl;
addAttachment(QList<AttachmentInfo>() << info, false);
}
});
job->start();
......@@ -636,9 +642,19 @@ void KMComposerWin::addAttachmentsAndSend(const QList<QUrl> &urls, const QString
send(how);
}
void KMComposerWin::addAttachment(const QUrl &url, const QString &comment)
void KMComposerWin::addAttachment(const QList<AttachmentInfo> &infos, bool showWarning)
{
mComposerBase->addAttachment(url, comment, false);
QStringList lst;
for (const AttachmentInfo &info : infos) {
if (showWarning) {
lst.append(info.url.toDisplayString());
}
mComposerBase->addAttachment(info.url, info.comment, false);
}
if (showWarning) {
mAttachmentFromExternalMissing->setAttachmentNames(lst);
mAttachmentFromExternalMissing->animatedShow();
}
}
void KMComposerWin::addAttachment(const QString &name, KMime::Headers::contentEncoding cte, const QString &charset, const QByteArray &data, const QByteArray &mimeType)
......@@ -2224,9 +2240,13 @@ bool KMComposerWin::insertFromMimeData(const QMimeData *source, bool forceAttach
if (items.isEmpty() && collections.isEmpty()) {
if (allLocalURLs || forceAttachment) {
QList<AttachmentInfo> infoList;
for (const QUrl &url : urlList) {
addAttachment(url, QString());
AttachmentInfo info;
info.url = url;
infoList.append(info);
}
addAttachment(infoList, false);
} else {
QMenu p;
const int sizeUrl(urlList.size());
......@@ -2237,11 +2257,15 @@ bool KMComposerWin::insertFromMimeData(const QMimeData *source, bool forceAttach
if (selectedAction == addAsTextAction) {
insertUrls(source, urlList);
} else if (selectedAction == addAsAttachmentAction) {
QList<AttachmentInfo> infoList;
for (const QUrl &url : urlList) {
if (url.isValid()) {
addAttachment(url, QString());
AttachmentInfo info;
info.url = url;
infoList.append(info);
}
}
addAttachment(infoList, false);
}
}
return true;
......
......@@ -73,6 +73,7 @@ class KMailPluginEditorInitManagerInterface;
class IncorrectIdentityFolderWarning;
class KMailPluginEditorConvertTextManagerInterface;
class KMailPluginGrammarEditorManagerInterface;
class AttachmentAddedFromExternalWarning;
namespace MailTransport {
class Transport;
}
......@@ -141,7 +142,7 @@ public Q_SLOTS:
Q_SCRIPTABLE void addAttachmentsAndSend(const QList<QUrl> &urls, const QString &comment, int how) override;
Q_SCRIPTABLE void addAttachment(const QUrl &url, const QString &comment) override;
Q_SCRIPTABLE void addAttachment(const QList<AttachmentInfo> &infos, bool showWarning) override;
Q_SCRIPTABLE void addAttachment(const QString &name, KMime::Headers::contentEncoding cte, const QString &charset, const QByteArray &data, const QByteArray &mimeType) override;
......@@ -667,6 +668,8 @@ private:
KMailPluginEditorInitManagerInterface *mPluginEditorInitManagerInterface = nullptr;
KMailPluginEditorConvertTextManagerInterface *mPluginEditorConvertTextManagerInterface = nullptr;
KMailPluginGrammarEditorManagerInterface *mPluginEditorGrammarManagerInterface = nullptr;
AttachmentAddedFromExternalWarning *mAttachmentFromExternalMissing = nullptr;
};
#endif
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "attachmentaddedfromexternalwarning.h"
#include <KLocalizedString>
AttachmentAddedFromExternalWarning::AttachmentAddedFromExternalWarning(QWidget *parent)
: KMessageWidget(parent)
{
setVisible(false);
setCloseButtonVisible(true);
setMessageType(Information);
setWordWrap(true);
}
AttachmentAddedFromExternalWarning::~AttachmentAddedFromExternalWarning()
{
}
void AttachmentAddedFromExternalWarning::setAttachmentNames(const QStringList &lst)
{
setText(i18n("These attachments (%1) were added from external. Remove them if it's an error.", lst.join(QLatin1Char(','))));
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ATTACHMENTADDEDFROMEXTERNALWARNING_H
#define ATTACHMENTADDEDFROMEXTERNALWARNING_H
#include <QWidget>
#include <KMessageWidget>
class AttachmentAddedFromExternalWarning : public KMessageWidget
{
Q_OBJECT
public:
explicit AttachmentAddedFromExternalWarning(QWidget *parent = nullptr);
~AttachmentAddedFromExternalWarning();
void setAttachmentNames(const QStringList &lst);
};
#endif // ATTACHMENTADDEDFROMEXTERNALWARNING_H
......@@ -28,6 +28,8 @@
#include <QTemporaryDir>
#include <QUrl>
#include <editor/composer.h>
DndFromArkJob::DndFromArkJob(QObject *parent)
: QObject(parent)
{
......@@ -63,10 +65,14 @@ bool DndFromArkJob::extract(const QMimeData *source)
message.setArguments({arkPath});
QDBusConnection::sessionBus().call(message);
QDir dir(arkPath);
QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
const QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
QList<KMail::Composer::AttachmentInfo> infoList;
for (int i = 0; i < list.size(); ++i) {
mComposerWin->addAttachment(QUrl::fromLocalFile(list.at(i)), QString());
KMail::Composer::AttachmentInfo info;
info.url = QUrl::fromLocalFile(list.at(i));
infoList.append(info);
}
mComposerWin->addAttachment(infoList, false);
delete linkDir;
deleteLater();
return true;
......
......@@ -68,8 +68,13 @@ void NewMessageJob::slotOpenComposer()
win->setCollectionForNewMessage(mCollection);
//Add the attachment if we have one
if (!mAttachURL.isEmpty() && mAttachURL.isValid()) {
win->addAttachment(mAttachURL, QString());
QList<KMail::Composer::AttachmentInfo> infoList;
KMail::Composer::AttachmentInfo info;
info.url = mAttachURL;
infoList.append(info);
win->addAttachment(infoList, false);
}
//only show window when required
......
......@@ -121,6 +121,7 @@ void OpenComposerJob::slotOpenComposer()
}
QList<QUrl> attachURLs = QUrl::fromStringList(mOpenComposerSettings.mAttachmentPaths);
QList<QUrl>::ConstIterator endAttachment(attachURLs.constEnd());
QList<KMail::Composer::AttachmentInfo> infoList;
for (QList<QUrl>::ConstIterator it = attachURLs.constBegin(); it != endAttachment; ++it) {
QMimeDatabase mimeDb;
if (mimeDb.mimeTypeForUrl(*it).name() == QLatin1String("inode/directory")) {
......@@ -128,7 +129,12 @@ void OpenComposerJob::slotOpenComposer()
continue;
}
}
cWin->addAttachment((*it), QString());
KMail::Composer::AttachmentInfo info;
info.url = (*it);
infoList.append(info);
}
if (!infoList.isEmpty()) {
cWin->addAttachment(infoList, true);
}
if (!mOpenComposerSettings.mCustomHeaders.isEmpty()) {
QMap<QByteArray, QString> extraCustomHeaders;
......
......@@ -1843,7 +1843,12 @@ KMCommand::Result KMShareImageCommand::execute()
KMail::Composer *win = KMail::makeComposer(msg, false, false, KMail::Composer::New, id);
win->setFocusToSubject();
win->addAttachment(mUrl, i18n("Image"));
QList<KMail::Composer::AttachmentInfo> infoList;
KMail::Composer::AttachmentInfo info;
info.url = mUrl;
info.comment = i18n("Image");
infoList.append(info);
win->addAttachment(infoList, false);
win->show();
return OK;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment