Libksieve

searchserverwithvacationsupportjob.cpp
1/*
2 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "searchserverwithvacationsupportjob.h"
8#include "util/findaccountinfojob.h"
9#include <QVariant>
10
11using namespace KSieveCore;
12
13SearchServerWithVacationSupportJob::SearchServerWithVacationSupportJob(QObject *parent)
14 : QObject(parent)
15{
16}
17
18SearchServerWithVacationSupportJob::~SearchServerWithVacationSupportJob() = default;
19
20void SearchServerWithVacationSupportJob::sendAccountList()
21{
22 Q_EMIT searchServerWithVacationSupportFinished(mAccountList);
24}
25
26void SearchServerWithVacationSupportJob::start()
27{
28 if (!canStart()) {
29 sendAccountList();
30 return;
31 }
33 for (const KSieveCore::SieveImapInstance &instance : instances) {
34 if (instance.status() == KSieveCore::SieveImapInstance::Broken) {
35 continue;
36 }
37 mServerSieveInfos.insert(instance.name(), instance.identifier());
38 }
39 searchNextInfo();
40}
41
42void SearchServerWithVacationSupportJob::searchNextInfo()
43{
44 mSieveServerMapIterator = mServerSieveInfos.constBegin();
45 if (mSieveServerMapIterator != mServerSieveInfos.constEnd()) {
46 slotSearchSieveScript(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
47 } else {
48 sendAccountList();
49 }
50}
51
52void SearchServerWithVacationSupportJob::slotSearchSieveScript(const QString &name, const QString &identifier)
53{
54 auto job = new KSieveCore::FindAccountInfoJob(this);
55 connect(job, &KSieveCore::FindAccountInfoJob::findAccountInfoFinished, this, &SearchServerWithVacationSupportJob::slotFindAccountInfoFinished);
56 job->setIdentifier(identifier);
57 job->setProperty("serverName", QVariant(name));
58 job->setProvider(mPasswordProvider);
59 job->start();
60}
61
62void SearchServerWithVacationSupportJob::slotFindAccountInfoFinished(const KSieveCore::Util::AccountInfo &info)
63{
64 const QUrl url = info.sieveUrl;
65 if (!url.isEmpty()) {
66 const QString serverName = sender()->property("serverName").toString();
67 mAccountList.insert(serverName, info);
68 }
69 searchNextServerSieve();
70}
71
72void SearchServerWithVacationSupportJob::searchNextServerSieve()
73{
74 ++mSieveServerMapIterator;
75 if (mSieveServerMapIterator != mServerSieveInfos.constEnd()) {
76 slotSearchSieveScript(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
77 } else {
78 sendAccountList();
79 }
80}
81
82bool SearchServerWithVacationSupportJob::canStart() const
83{
84 return mPasswordProvider;
85}
86
87KSieveCore::SieveImapPasswordProvider *SearchServerWithVacationSupportJob::passwordProvider() const
88{
89 return mPasswordProvider;
90}
91
92void SearchServerWithVacationSupportJob::setPasswordProvider(KSieveCore::SieveImapPasswordProvider *newProvider)
93{
94 mPasswordProvider = newProvider;
95}
96
97#include "moc_searchserverwithvacationsupportjob.cpp"
The SieveImapInstance class.
@ Broken
The agent instance encountered an error state.
The SieveImapPasswordProvider class.
KSIEVECORE_EXPORT QList< KSieveCore::SieveImapInstance > sieveImapInstances()
Returns the list of configured IMAP agent instances.
Definition util.cpp:32
const_iterator constBegin() const const
const_iterator constEnd() const const
iterator insert(const Key &key, const T &value)
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
QVariant property(const char *name) const const
QObject * sender() const const
bool isEmpty() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.