Commit 44638830 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

now we use ReadServerSieveConfigJob

parent 4d703392
Pipeline #40520 canceled with stage
......@@ -17,6 +17,7 @@
Boston, MA 02110-1301, USA.
*/
#include "readserversieveconfigjob.h"
#include "sieveeditormanagesievewidget.h"
#include "sieveeditorutil.h"
#include <KSieveUi/SieveTreeWidgetItem>
......@@ -71,6 +72,13 @@ bool SieveEditorManageSieveWidget::refreshList()
void SieveEditorManageSieveWidget::updateSieveSettings()
{
mSieveServerSettings = SieveEditorUtil::readServerSieveConfig();
ReadServerSieveConfigJob *job = new ReadServerSieveConfigJob(this);
connect(job, &ReadServerSieveConfigJob::finished, this, &SieveEditorManageSieveWidget::slotReadServerSieveConfigDone);
job->start();
}
void SieveEditorManageSieveWidget::slotReadServerSieveConfigDone(const QVector<SieveEditorUtil::SieveServerConfig> &lstConfig)
{
mSieveServerSettings = lstConfig;
Q_EMIT updateSieveSettingsDone();
}
......@@ -34,6 +34,7 @@ protected:
Q_REQUIRED_RESULT bool refreshList() override;
void updateSieveSettings() override;
private:
void slotReadServerSieveConfigDone(const QVector<SieveEditorUtil::SieveServerConfig> &lstConfig);
QVector<SieveEditorUtil::SieveServerConfig> mSieveServerSettings;
};
......
......@@ -85,64 +85,6 @@ bool SieveEditorUtil::SieveServerConfig::operator ==(const SieveEditorUtil::Siev
return result;
}
QVector<SieveEditorUtil::SieveServerConfig> SieveEditorUtil::readServerSieveConfig()
{
//TODO move to async
QVector<SieveServerConfig> lstConfig;
KSharedConfigPtr cfg = KSharedConfig::openConfig();
QRegularExpression re(QStringLiteral("^ServerSieve (.+)$"));
const QStringList groups = cfg->groupList().filter(re);
KWallet::Wallet *wallet = SieveEditorUtil::selectWalletFolder();
for (const QString &conf : groups) {
SieveServerConfig sieve;
KConfigGroup group = cfg->group(conf);
//Sieve Account Settings
sieve.sieveSettings.port = group.readEntry(QStringLiteral("Port"), 0);
sieve.sieveSettings.serverName = group.readEntry(QStringLiteral("ServerName"));
sieve.sieveSettings.userName = group.readEntry(QStringLiteral("UserName"));
sieve.enabled = group.readEntry(QStringLiteral("Enabled"), true);
const QString walletEntry = sieve.sieveSettings.userName + QLatin1Char('@') + sieve.sieveSettings.serverName;
if (wallet && wallet->hasEntry(walletEntry)) {
QString passwd;
wallet->readPassword(walletEntry, passwd);
sieve.sieveSettings.password = passwd;
}
sieve.sieveSettings.authenticationType
= static_cast<MailTransport::Transport::EnumAuthenticationType::type>(group.readEntry(QStringLiteral("Authentication"),
static_cast<int>(MailTransport::Transport::EnumAuthenticationType::PLAIN)));
//Imap Account Settings
sieve.sieveImapAccountSettings.setPort(group.readEntry(QStringLiteral("ImapPort"), 0));
sieve.sieveImapAccountSettings.setServerName(group.readEntry(QStringLiteral("ImapServerName")));
sieve.sieveImapAccountSettings.setUserName(group.readEntry(QStringLiteral("ImapUserName")));
sieve.sieveImapAccountSettings.setAuthenticationType(
static_cast<KSieveUi::SieveImapAccountSettings::AuthenticationMode>(group.readEntry(QStringLiteral("ImapAuthentication"), static_cast<int>(KSieveUi::SieveImapAccountSettings::Plain))));
sieve.sieveImapAccountSettings.setEncryptionMode(
static_cast<KSieveUi::SieveImapAccountSettings::EncryptionMode>(group.readEntry(QStringLiteral("ImapEncrypt"), static_cast<int>(KSieveUi::SieveImapAccountSettings::SSLorTLS))));
if (!sieve.sieveImapAccountSettings.userName().isEmpty()
&& !sieve.sieveImapAccountSettings.serverName().isEmpty()
&& (sieve.sieveImapAccountSettings.userName() != sieve.sieveSettings.userName)
&& (sieve.sieveImapAccountSettings.serverName() != sieve.sieveSettings.serverName)) {
const QString imapWalletEntry = QLatin1String("Imap") + sieve.sieveImapAccountSettings.userName() + QLatin1Char('@') + sieve.sieveImapAccountSettings.serverName();
if (wallet && wallet->hasEntry(imapWalletEntry)) {
QString passwd;
wallet->readPassword(imapWalletEntry, passwd);
sieve.sieveImapAccountSettings.setPassword(passwd);
}
sieve.useImapCustomServer = true;
} else {
//Use Sieve Account Settings
sieve.sieveImapAccountSettings.setUserName(sieve.sieveSettings.userName);
sieve.sieveImapAccountSettings.setServerName(sieve.sieveSettings.serverName);
sieve.sieveImapAccountSettings.setPassword(sieve.sieveSettings.password);
sieve.useImapCustomServer = false;
}
lstConfig.append(sieve);
}
return lstConfig;
}
void SieveEditorUtil::writeServerSieveConfig(const QVector<SieveServerConfig> &lstConfig)
{
......
......@@ -62,7 +62,6 @@ struct LIBSIEVEEDITOR_EXPORT SieveServerConfig {
bool useImapCustomServer;
};
QVector<SieveServerConfig> readServerSieveConfig();
void writeServerSieveConfig(const QVector<SieveEditorUtil::SieveServerConfig> &lstConfig);
void addServerSieveConfig(const SieveEditorUtil::SieveServerConfig &conf);
void writeSieveSettings(KWallet::Wallet *wallet, const KSharedConfigPtr &cfg, const SieveEditorUtil::SieveServerConfig &conf, int index);
......
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