Libksieve

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

KDE's Doxygen guidelines are available online.