7#include "dkimmanagerrules.h"
10#include <QRegularExpression>
12using namespace MessageViewer;
13DKIMManagerRules::DKIMManagerRules(
QObject *parent)
19DKIMManagerRules::~DKIMManagerRules()
26 static DKIMManagerRules s_self;
30void DKIMManagerRules::addRule(
const DKIMRule &rule)
32 if (!mRules.contains(rule)) {
38bool DKIMManagerRules::isEmpty()
const
40 return mRules.isEmpty();
43QList<DKIMRule> DKIMManagerRules::rules()
const
48QStringList DKIMManagerRules::ruleGroups(
const KSharedConfig::Ptr &config)
const
50 return config->groupList().filter(QRegularExpression(QStringLiteral(
"DKIM Rule #\\d+")));
53int DKIMManagerRules::loadRules(
const QString &fileName)
55 const KSharedConfig::Ptr &config =
57 const QStringList rulesGroups = ruleGroups(config);
62 int numberOfRulesAdded = 0;
63 for (
const QString &groupName : rulesGroups) {
64 KConfigGroup group = config->group(groupName);
65 const QStringList signedDomainIdentifier = group.
readEntry(QStringLiteral(
"SignedDomainIdentifier"), QStringList());
66 const QString from = group.
readEntry(QStringLiteral(
"From"), QString());
67 const QString domain = group.
readEntry(QStringLiteral(
"Domain"), QString());
68 const bool enabled = group.
readEntry(QStringLiteral(
"Enabled"),
true);
69 const int ruleType = group.
readEntry(QStringLiteral(
"RuleType"), 0);
70 const QString listId = group.
readEntry(QStringLiteral(
"List-Id"), QString());
71 const int priority = group.
readEntry(QStringLiteral(
"Priority"), 1000);
73 rule.setEnabled(enabled);
74 rule.setDomain(domain);
76 rule.setListId(listId);
77 rule.setSignedDomainIdentifier(signedDomainIdentifier);
78 rule.setRuleType(
static_cast<DKIMRule::RuleType
>(ruleType));
79 rule.setPriority(priority);
85 return numberOfRulesAdded;
88void DKIMManagerRules::saveRules(
const QList<DKIMRule> &lst)
94void DKIMManagerRules::clear()
100int DKIMManagerRules::importRules(
const QString &fileName)
102 return loadRules(fileName);
105void DKIMManagerRules::exportRules(
const QString &fileName,
const QList<DKIMRule> &lst)
110void DKIMManagerRules::save(
const QString &fileName,
const QList<DKIMRule> &lst)
112 const KSharedConfig::Ptr &config =
114 const QStringList rulesGroups = ruleGroups(config);
116 for (
const QString &group : rulesGroups) {
117 config->deleteGroup(group);
119 QList<DKIMRule> rules = lst;
123 for (
int i = 0, total = rules.count(); i < total; ++i) {
124 const QString groupName = QStringLiteral(
"DKIM Rule #%1").arg(i);
125 KConfigGroup group = config->
group(groupName);
126 const DKIMRule &rule = rules.at(i);
128 group.
writeEntry(QStringLiteral(
"SignedDomainIdentifier"), rule.signedDomainIdentifier());
129 group.
writeEntry(QStringLiteral(
"From"), rule.from());
130 group.
writeEntry(QStringLiteral(
"Domain"), rule.domain());
131 group.
writeEntry(QStringLiteral(
"Enabled"), rule.enabled());
132 group.
writeEntry(QStringLiteral(
"RuleType"),
static_cast<int>(rule.ruleType()));
133 group.
writeEntry(QStringLiteral(
"List-Id"), rule.listId());
134 group.
writeEntry(QStringLiteral(
"Priority"), rule.priority());
138#include "moc_dkimmanagerrules.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 DKIMManagerRules class.
bool isEmpty() const const
bool isEmpty() const const