Commit 90d8f91e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to compare record key

parent f5769392
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.12.81")
set(PIM_VERSION "5.13.41")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -33,7 +33,7 @@ void DKIMCheckPolicyTest::shouldHaveDefaultValues()
MessageViewer::DKIMCheckPolicy pol;
QVERIFY(!pol.verifySignatureWhenOnlyTest());
QVERIFY(!pol.saveDkimResult());
QVERIFY(!pol.saveKey());
QCOMPARE(pol.saveKey(), -1);
QVERIFY(!pol.autogenerateRule());
QVERIFY(!pol.checkIfEmailShouldBeSigned());
QVERIFY(!pol.useDMarc());
......@@ -50,7 +50,7 @@ void DKIMCheckPolicyTest::shouldAssignValues()
pol.setVerifySignatureWhenOnlyTest(mVerifySignatureWhenOnlyTest);
bool mSaveDkimResult = true;
pol.setSaveDkimResult(mSaveDkimResult);
bool mSaveKey = true;
int mSaveKey = 8;
pol.setSaveKey(mSaveKey);
bool mAutogenerateRule = true;
pol.setAutogenerateRule(mAutogenerateRule);
......
......@@ -64,12 +64,12 @@ void DKIMCheckPolicy::setSaveDkimResult(bool saveDkimResult)
mSaveDkimResult = saveDkimResult;
}
bool DKIMCheckPolicy::saveKey() const
int DKIMCheckPolicy::saveKey() const
{
return mSaveKey;
}
void DKIMCheckPolicy::setSaveKey(bool saveKey)
void DKIMCheckPolicy::setSaveKey(int saveKey)
{
mSaveKey = saveKey;
}
......
......@@ -42,8 +42,8 @@ public:
Q_REQUIRED_RESULT bool saveDkimResult() const;
void setSaveDkimResult(bool saveDkimResult);
Q_REQUIRED_RESULT bool saveKey() const;
void setSaveKey(bool saveKey);
Q_REQUIRED_RESULT int saveKey() const;
void setSaveKey(int saveKey);
Q_REQUIRED_RESULT bool autogenerateRule() const;
void setAutogenerateRule(bool autogenerateRule);
......@@ -64,7 +64,7 @@ private:
int mRsaSha1Policy = -1;
bool mVerifySignatureWhenOnlyTest = false;
bool mSaveDkimResult = false;
bool mSaveKey = false;
int mSaveKey = -1;
bool mAutogenerateRule = false;
bool mCheckIfEmailShouldBeSigned = false;
bool mUseDMarc = false;
......
......@@ -27,6 +27,8 @@
#include "dkimcheckauthenticationstatusjob.h"
#include "settings/messageviewersettings.h"
#include <AkonadiCore/AttributeFactory>
#include <KMessageBox>
#include <KLocalizedString>
using namespace MessageViewer;
DKIMManager::DKIMManager(QObject *parent)
: QObject(parent)
......@@ -108,12 +110,33 @@ void DKIMManager::checkDKim(const KMime::Message::Ptr &message)
void DKIMManager::storeKey(const QString &key, const QString &domain, const QString &selector)
{
if (mCheckPolicy.saveKey()) {
const MessageViewer::KeyInfo info {key, selector, domain};
MessageViewer::DKIMManagerKey::self()->addKey(info);
switch(mCheckPolicy.saveKey()) {
case MessageViewer::MessageViewerSettings::EnumSaveKey::NotSaving:
//Nothing
break;
case MessageViewer::MessageViewerSettings::EnumSaveKey::Save:
storeInKeyManager(key, selector, domain, false);
break;
case MessageViewer::MessageViewerSettings::EnumSaveKey::SaveAndCompare:
storeInKeyManager(key, selector, domain, true);
break;
}
}
void DKIMManager::storeInKeyManager(const QString &key, const QString &domain, const QString &selector, bool verify)
{
const MessageViewer::KeyInfo info {key, selector, domain};
if (verify) {
const QString keyStored = MessageViewer::DKIMManagerKey::self()->keyValue(selector, domain);
if (keyStored != key) {
if (KMessageBox::No == KMessageBox::warningYesNo(nullptr, i18n("Stored DKIM key is different from the current one. Do you want to store this one too?"), i18n("Key Changed"))) {
return;
}
}
}
MessageViewer::DKIMManagerKey::self()->addKey(info);
}
void DKIMManager::slotCheckAuthenticationStatusResult(const MessageViewer::DKIMAuthenticationStatusInfo &info, const Akonadi::Item &item)
{
//TODO check info ! if auth is ok not necessary to checkSignature
......
......@@ -54,6 +54,7 @@ private:
void storeResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult);
void storeKey(const QString &key, const QString &domain, const QString &selector);
void slotCheckSignatureResult(const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &checkResult);
void storeInKeyManager(const QString &key, const QString &domain, const QString &selector, bool verify);
void slotCheckAuthenticationStatusResult(const MessageViewer::DKIMAuthenticationStatusInfo &info, const Akonadi::Item &item);
DKIMCheckPolicy mCheckPolicy;
};
......
......@@ -258,8 +258,13 @@ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/sta
<entry name="SaveDkimResult" type="bool">
<default>false</default>
</entry>
<entry name="SaveKey" type="bool">
<default>false</default>
<entry name="SaveKey" type="Enum">
<choices>
<choice name="NotSaving"/>
<choice name="Save"/>
<choice name="SaveAndCompare"/>
</choices>
<default>NotSaving</default>
</entry>
<entry name="CheckIfEmailShouldBeSigned" type="bool">
<default>false</default>
......
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