Libksieve

multiimapvacationmanager.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "multiimapvacationmanager.h"
21 #include "vacationcheckjob.h"
22 #include "sieveimapinstance/sieveimapinstanceinterface.h"
23 #include "util/util_p.h"
24 #include <managescriptsjob/checkkolabkep14supportjob.h>
25 #include <managescriptsjob/parseuserscriptjob.h>
26 #include <kmanagesieve/sievejob.h>
27 
28 #include "libksieve_debug.h"
29 
30 using namespace KSieveUi;
31 MultiImapVacationManager::MultiImapVacationManager(SieveImapPasswordProvider *passwordProvider, QObject *parent)
32  : QObject(parent)
33  , mPasswordProvider(passwordProvider)
34 {
35 }
36 
37 MultiImapVacationManager::~MultiImapVacationManager()
38 {
39 }
40 
41 QMap <QString, KSieveUi::Util::AccountInfo> MultiImapVacationManager::serverList() const
42 {
44  const QVector<KSieveUi::SieveImapInstance> instances = KSieveUi::Util::sieveImapInstances();
45  for (const KSieveUi::SieveImapInstance &instance : instances) {
46  if (instance.status() == KSieveUi::SieveImapInstance::Broken) {
47  continue;
48  }
49 
50  const KSieveUi::Util::AccountInfo info = KSieveUi::Util::fullAccountInfo(instance.identifier(), mPasswordProvider);
51  const QUrl url = info.sieveUrl;
52  if (!url.isEmpty()) {
53  list.insert(instance.name(), info);
54  }
55  }
56  return list;
57 }
58 
59 void MultiImapVacationManager::checkVacation(const QString &serverName, const QUrl &url)
60 {
61  ++mNumberOfJobs;
62  if (!mKep14Support.contains(serverName)) {
63  CheckKolabKep14SupportJob *checkKep14Job = new CheckKolabKep14SupportJob(this);
64  checkKep14Job->setProperty("triggerScript", true);
65  checkKep14Job->setServerName(serverName);
66  checkKep14Job->setServerUrl(url);
67  connect(checkKep14Job, &CheckKolabKep14SupportJob::result, this, &MultiImapVacationManager::slotCheckKep14Ended);
68  checkKep14Job->start();
69  return;
70  }
71 
72  VacationCheckJob *job = new VacationCheckJob(url, serverName, this);
73  job->setKep14Support(mKep14Support[serverName]);
74  connect(job, &VacationCheckJob::vacationScriptActive, this, &MultiImapVacationManager::slotScriptActive);
75  job->start();
76 }
77 
78 void MultiImapVacationManager::checkVacation()
79 {
80  if (mCheckInProgress) {
81  return;
82  }
83  mNumberOfJobs = 0;
84  mCheckInProgress = true;
85 
87  while (i.hasNext()) {
88  i.next();
89  checkVacation(i.key(), i.value().sieveUrl);
90  }
91 }
92 
93 void MultiImapVacationManager::slotScriptActive(VacationCheckJob *job, const QString &scriptName, bool active)
94 {
95  --mNumberOfJobs;
96  if (mNumberOfJobs == 0) {
97  mCheckInProgress = false;
98  }
99 
100  job->deleteLater();
101 
102  if (job->noScriptFound()) {
103  Q_EMIT scriptActive(false, job->serverName());
104  return;
105  }
106  Q_EMIT scriptActive(active, job->serverName());
107  Q_EMIT scriptAvailable(job->serverName(), job->sieveCapabilities(), scriptName, job->script(), active);
108 }
109 
110 void MultiImapVacationManager::slotCheckKep14Ended(CheckKolabKep14SupportJob *job, bool success)
111 {
112  job->deleteLater();
113  if (!success) {
114  --mNumberOfJobs;
115  return;
116  }
117 
118  mKep14Support.insert(job->serverName(), job->hasKep14Support());
119 
120  VacationCheckJob *checkJob = new VacationCheckJob(job->serverUrl(), job->serverName(), this);
121  checkJob->setKep14Support(job->hasKep14Support());
122  connect(checkJob, &VacationCheckJob::vacationScriptActive, this, &MultiImapVacationManager::slotScriptActive);
123  checkJob->start();
124 }
125 
126 bool MultiImapVacationManager::kep14Support(const QString &serverName) const
127 {
128  if (mKep14Support.contains(serverName)) {
129  return mKep14Support[serverName];
130  } else {
131  qCWarning(LIBKSIEVE_LOG) << "We don't know the KEP:14 support for this server." << serverName;
132  }
133  return false;
134 }
Checks for support of Non-conflicting edits of Sieve scripts by multiple editors (KEP:14) ...
The agent instance encountered an error state.
The SieveImapPasswordProvider class.
The SieveImapInstance class.
void deleteLater()
bool setProperty(const char *name, const QVariant &value)
QMap::iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.