Libksieve

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

KDE's Doxygen guidelines are available online.