7#include "dkimmanagerkey.h"
10#include <KConfigGroup>
11#include <QRegularExpression>
13using namespace MessageViewer;
14DKIMManagerKey::DKIMManagerKey(
QObject *parent)
20DKIMManagerKey::~DKIMManagerKey()
27 static DKIMManagerKey s_self;
31QString DKIMManagerKey::keyValue(
const QString &selector,
const QString &domain)
33 for (
const KeyInfo &keyInfo : std::as_const(mKeys)) {
34 if (keyInfo.selector == selector && keyInfo.domain == domain) {
35 return keyInfo.keyValue;
41void DKIMManagerKey::updateLastUsed(
const QString &selector,
const QString &domain)
43 for (
const KeyInfo &keyInfo : std::as_const(mKeys)) {
44 if (keyInfo.selector == selector && keyInfo.domain == domain) {
45 KeyInfo newKey = keyInfo;
53void DKIMManagerKey::addKey(
const KeyInfo &key)
55 const QList<KeyInfo> keys = mKeys;
56 for (
const KeyInfo &keyInfo : keys) {
57 if (keyInfo.selector == key.selector && keyInfo.domain == key.domain) {
58 mKeys.removeAll(keyInfo);
64void DKIMManagerKey::removeKey(
const QString &key)
66 for (
const KeyInfo &keyInfo : std::as_const(mKeys)) {
67 if (keyInfo.keyValue == key) {
68 mKeys.removeAll(keyInfo);
74QList<KeyInfo> DKIMManagerKey::keys()
const
79QStringList DKIMManagerKey::keyRecorderList(KSharedConfig::Ptr &config)
const
82 const QStringList keyGroups = config->groupList().filter(QRegularExpression(QStringLiteral(
"DKIM Key Record #\\d+")));
86void DKIMManagerKey::loadKeys()
88 KSharedConfig::Ptr config;
89 const QStringList keyGroups = keyRecorderList(config);
92 for (
const QString &groupName : keyGroups) {
93 KConfigGroup group = config->group(groupName);
94 const QString selector = group.
readEntry(QStringLiteral(
"Selector"), QString());
95 const QString domain = group.
readEntry(QStringLiteral(
"Domain"), QString());
96 const QString key = group.
readEntry(QStringLiteral(
"Key"), QString());
102 mKeys.append(KeyInfo{key, selector, domain, storedAt, lastUsed});
106void DKIMManagerKey::saveKeys()
108 KSharedConfig::Ptr config;
109 const QStringList filterGroups = keyRecorderList(config);
111 for (
const QString &group : filterGroups) {
112 config->deleteGroup(group);
114 for (
int i = 0, total = mKeys.count(); i < total; ++i) {
115 const QString groupName = QStringLiteral(
"DKIM Key Record #%1").arg(i);
116 KConfigGroup group = config->
group(groupName);
117 const KeyInfo &info = mKeys.at(i);
118 group.
writeEntry(QStringLiteral(
"Selector"), info.selector);
119 group.
writeEntry(QStringLiteral(
"Domain"), info.domain);
120 group.
writeEntry(QStringLiteral(
"Key"), info.keyValue);
126void DKIMManagerKey::saveKeys(
const QList<MessageViewer::KeyInfo> &lst)
132bool KeyInfo::operator==(
const KeyInfo &other)
const
134 return keyValue == other.keyValue && selector == other.selector && domain == other.domain;
137bool KeyInfo::operator!=(
const KeyInfo &other)
const
139 return !(operator==(other));
144 d <<
" keyvalue " << t.keyValue;
145 d <<
" selector " << t.selector;
146 d <<
" domain " << t.domain;
147 d <<
" storedAtDateTime " << t.storedAtDateTime;
148 d <<
" lastUsedDateTime " << t.lastUsedDateTime;
152#include "moc_dkimmanagerkey.cpp"
KConfigGroup group(const QString &group)
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
The DKIMManagerKey class.
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
QDateTime currentDateTime()
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
QString toString(QStringView format, QCalendar cal) const const