From bfc2979670f1e57fa69e8723e6e6a9838c2e0258 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Thu, 2 Nov 2017 13:21:54 +0100 Subject: [PATCH] Display warning on top of composer + fix special case bug found by david --- src/editor/kmcomposerwin.cpp | 17 ++++++++++------- .../autotests/potentialphishingemailjobtest.cpp | 2 ++ .../potentialphishingemailjob.cpp | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/editor/kmcomposerwin.cpp b/src/editor/kmcomposerwin.cpp index cdb2b0f54..fdae7e176 100644 --- a/src/editor/kmcomposerwin.cpp +++ b/src/editor/kmcomposerwin.cpp @@ -380,6 +380,16 @@ KMComposerWin::KMComposerWin(const KMime::Message::Ptr &aMsg, bool lastSignState QVBoxLayout *vbox = new QVBoxLayout(editorAndCryptoStateIndicators); vbox->setMargin(0); + + mPotentialPhishingEmailWarning = new PotentialPhishingEmailWarning(this); + connect(mPotentialPhishingEmailWarning, &PotentialPhishingEmailWarning::sendNow, this, &KMComposerWin::slotCheckSendNowStep2); + vbox->addWidget(mPotentialPhishingEmailWarning); + + mAttachmentMissing = new AttachmentMissingWarning(this); + connect(mAttachmentMissing, &AttachmentMissingWarning::attachMissingFile, this, &KMComposerWin::slotAttachMissingFile); + connect(mAttachmentMissing, &AttachmentMissingWarning::explicitClosedMissingAttachment, this, &KMComposerWin::slotExplicitClosedMissingAttachment); + vbox->addWidget(mAttachmentMissing); + KMComposerEditorNg *composerEditorNg = new KMComposerEditorNg(this, mCryptoStateIndicatorWidget); mRichTextEditorwidget = new KPIMTextEdit::RichTextEditorWidget(composerEditorNg, mCryptoStateIndicatorWidget); @@ -430,14 +440,7 @@ KMComposerWin::KMComposerWin(const KMime::Message::Ptr &aMsg, bool lastSignState mComposerBase->setAttachmentModel(attachmentModel); mComposerBase->setAttachmentController(attachmentController); - mAttachmentMissing = new AttachmentMissingWarning(this); - connect(mAttachmentMissing, &AttachmentMissingWarning::attachMissingFile, this, &KMComposerWin::slotAttachMissingFile); - connect(mAttachmentMissing, &AttachmentMissingWarning::explicitClosedMissingAttachment, this, &KMComposerWin::slotExplicitClosedMissingAttachment); - v->addWidget(mAttachmentMissing); - mPotentialPhishingEmailWarning = new PotentialPhishingEmailWarning(this); - connect(mPotentialPhishingEmailWarning, &PotentialPhishingEmailWarning::sendNow, this, &KMComposerWin::slotCheckSendNowStep2); - v->addWidget(mPotentialPhishingEmailWarning); if (KMailSettings::self()->showForgottenAttachmentWarning()) { mVerifyMissingAttachment = new QTimer(this); diff --git a/src/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp b/src/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp index a125def9a..edfc1949d 100644 --- a/src/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp +++ b/src/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp @@ -67,6 +67,8 @@ void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails_data() QTest::newRow("WithMultiNotSameEmail") << (QStringList() << QStringLiteral("\" bla@kde.org foo@kde.org \" ")) << QStringList() << true; QTest::newRow("EmailWithSimpleQuote") << (QStringList() << QStringLiteral("\"\'foo@kde.org\'\" ")) << QStringList() << false; + + QTest::newRow("BadCompletion") << (QStringList() << QStringLiteral("@kde.org ")) << QStringList() << false; } void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails() diff --git a/src/editor/potentialphishingemail/potentialphishingemailjob.cpp b/src/editor/potentialphishingemail/potentialphishingemailjob.cpp index 5dccbfe37..7d573e08b 100644 --- a/src/editor/potentialphishingemail/potentialphishingemailjob.cpp +++ b/src/editor/potentialphishingemail/potentialphishingemailjob.cpp @@ -64,6 +64,9 @@ bool PotentialPhishingEmailJob::start() QString tname, temail; KEmailAddress::extractEmailAddressAndName(addr, temail, tname); // ignore return value // which is always false + if (tname.startsWith(QLatin1Char('@'))) { //Special case when name is just @foo <...> it mustn't recognize as a valid email + continue; + } if (tname.contains(QLatin1Char('@'))) { //Potential address if (tname.startsWith(QLatin1Char('<')) && tname.endsWith(QLatin1Char('>'))) { tname = tname.mid(1, tname.length() - 2);