Commit 9ea4e6e2 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to implement async method

parent efba9638
Pipeline #40554 canceled with stage
......@@ -38,61 +38,66 @@ ReadServerSieveConfigJob::~ReadServerSieveConfigJob()
}
void ReadServerSieveConfigJob::start()
void ReadServerSieveConfigJob::loadSettings(const QString &conf)
{
QVector<SieveEditorUtil::SieveServerConfig> lstConfig;
KSharedConfigPtr cfg = KSharedConfig::openConfig();
QRegularExpression re(QStringLiteral("^ServerSieve (.+)$"));
const QStringList groups = cfg->groupList().filter(re);
KWallet::Wallet *wallet = SieveEditorUtil::selectWalletFolder();
SieveEditorUtil::SieveServerConfig sieve;
KSharedConfigPtr cfg = KSharedConfig::openConfig();
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)));
for (const QString &conf : groups) {
SieveEditorUtil::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)) {
//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(walletEntry, passwd);
sieve.sieveSettings.password = passwd;
wallet->readPassword(imapWalletEntry, passwd);
sieve.sieveImapAccountSettings.setPassword(passwd);
}
sieve.sieveSettings.authenticationType
= static_cast<MailTransport::Transport::EnumAuthenticationType::type>(group.readEntry(QStringLiteral("Authentication"),
static_cast<int>(MailTransport::Transport::EnumAuthenticationType::PLAIN)));
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;
}
mLstConfig.append(sieve);
}
//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))));
void ReadServerSieveConfigJob::start()
{
KSharedConfigPtr cfg = KSharedConfig::openConfig();
QRegularExpression re(QStringLiteral("^ServerSieve (.+)$"));
const QStringList groups = cfg->groupList().filter(re);
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);
for (const QString &conf : groups) {
loadSettings(conf);
}
Q_EMIT finished(lstConfig);
Q_EMIT finished(mLstConfig);
deleteLater();
}
......@@ -33,7 +33,9 @@ public:
void start();
Q_SIGNALS:
void finished(const QVector<SieveEditorUtil::SieveServerConfig> &lstConfig);
private:
void loadSettings(const QString &conf);
QVector<SieveEditorUtil::SieveServerConfig> mLstConfig;
};
#endif // READSERVERSIEVECONFIGJOB_H
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