Libksieve

multiimapvacationmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "multiimapvacationmanager.h"
8#include "kmanagesieve/sievejob.h"
9#include "managescriptsjob/checkkolabkep14supportjob.h"
10#include "managescriptsjob/parseuserscriptjob.h"
11#include <KSieveCore/SearchServerWithVacationSupportJob>
12#include <KSieveCore/VacationCheckJob>
13
14#include "libksievecore_debug.h"
15#include <QVariant>
16
17using namespace KSieveCore;
18MultiImapVacationManager::MultiImapVacationManager(KSieveCore::SieveImapPasswordProvider *passwordProvider, QObject *parent)
19 : QObject(parent)
20 , mPasswordProvider(passwordProvider)
21{
22}
23
24MultiImapVacationManager::~MultiImapVacationManager() = default;
25
26void MultiImapVacationManager::checkVacation(const QString &serverName, const QUrl &url)
27{
28 ++mNumberOfJobs;
29 if (!mKep14Support.contains(serverName)) {
30 auto checkKep14Job = new KSieveCore::CheckKolabKep14SupportJob(this);
31 checkKep14Job->setProperty("triggerScript", QVariant(true));
32 checkKep14Job->setServerName(serverName);
33 checkKep14Job->setServerUrl(url);
34 connect(checkKep14Job, &KSieveCore::CheckKolabKep14SupportJob::result, this, &MultiImapVacationManager::slotCheckKep14Ended);
35 checkKep14Job->start();
36 return;
37 }
38
39 auto job = new KSieveCore::VacationCheckJob(url, serverName, this);
40 job->setKep14Support(mKep14Support[serverName]);
41 connect(job, &KSieveCore::VacationCheckJob::vacationScriptActive, this, &MultiImapVacationManager::slotScriptActive);
42 job->start();
43}
44
45void MultiImapVacationManager::checkVacation()
46{
47 if (mCheckInProgress) {
48 return;
49 }
50 mNumberOfJobs = 0;
51 mCheckInProgress = true;
52
53 auto job = new KSieveCore::SearchServerWithVacationSupportJob(this);
54 job->setPasswordProvider(passwordProvider());
55 connect(job,
56 &KSieveCore::SearchServerWithVacationSupportJob::searchServerWithVacationSupportFinished,
57 this,
58 &MultiImapVacationManager::slotSearchServerWithVacationSupportFinished);
59 job->start();
60}
61
62void MultiImapVacationManager::slotSearchServerWithVacationSupportFinished(const QMap<QString, KSieveCore::Util::AccountInfo> &list)
63{
65 while (i.hasNext()) {
66 i.next();
67 checkVacation(i.key(), i.value().sieveUrl);
68 }
69}
70
71void MultiImapVacationManager::slotScriptActive(KSieveCore::VacationCheckJob *job, const QString &scriptName, bool active)
72{
73 --mNumberOfJobs;
74 if (mNumberOfJobs == 0) {
75 mCheckInProgress = false;
76 }
77
78 job->deleteLater();
79
80 if (job->noScriptFound()) {
81 Q_EMIT scriptActive(false, job->serverName());
82 return;
83 }
84 Q_EMIT scriptActive(active, job->serverName());
85 Q_EMIT scriptAvailable(job->serverName(), job->sieveCapabilities(), scriptName, job->script(), active);
86}
87
88void MultiImapVacationManager::slotCheckKep14Ended(KSieveCore::CheckKolabKep14SupportJob *job, bool success)
89{
90 job->deleteLater();
91 if (!success) {
92 --mNumberOfJobs;
93 return;
94 }
95
96 mKep14Support.insert(job->serverName(), job->hasKep14Support());
97
98 auto checkJob = new KSieveCore::VacationCheckJob(job->serverUrl(), job->serverName(), this);
99 checkJob->setKep14Support(job->hasKep14Support());
100 connect(checkJob, &KSieveCore::VacationCheckJob::vacationScriptActive, this, &MultiImapVacationManager::slotScriptActive);
101 checkJob->start();
102}
103
104bool MultiImapVacationManager::kep14Support(const QString &serverName) const
105{
106 if (mKep14Support.contains(serverName)) {
107 return mKep14Support[serverName];
108 } else {
109 qCWarning(LIBKSIEVECORE_LOG) << "We don't know the KEP:14 support for this server." << serverName;
110 }
111 return false;
112}
113
114KSieveCore::SieveImapPasswordProvider *MultiImapVacationManager::passwordProvider() const
115{
116 return mPasswordProvider;
117}
118
119#include "moc_multiimapvacationmanager.cpp"
Checks for support of Non-conflicting edits of Sieve scripts by multiple editors (KEP:14)
The SieveImapPasswordProvider class.
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.