Libksieve

util.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Till Adam <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "util.h"
8 #include "akonadiimapsettinginterface.h"
9 #include "imapresourcesettings.h"
10 #include "libksieve_debug.h"
11 #include "sieve-vacation.h"
12 #include "sieveimapinstance/sieveimapinstance.h"
13 #include "sieveimapinstance/sieveimapinstanceinterfacemanager.h"
14 #include "sieveimappasswordprovider.h"
15 #include "util_p.h"
16 #include <PimCommon/PimUtil>
17 
18 #include <MailTransport/Transport>
19 #include <kmime/kmime_message.h>
20 
21 using namespace KSieveUi;
22 
23 QStringList KSieveUi::Util::sieveImapResourceNames()
24 {
25  const QVector<KSieveUi::SieveImapInstance> lst = KSieveUi::Util::sieveImapInstances();
26  QStringList resourceNames;
27  resourceNames.reserve(lst.count());
28  for (const KSieveUi::SieveImapInstance &type : lst) {
29  resourceNames << type.identifier();
30  }
31  return resourceNames;
32 }
33 
34 QVector<KSieveUi::SieveImapInstance> KSieveUi::Util::sieveImapInstances()
35 {
36  const QVector<KSieveUi::SieveImapInstance> allInstances = KSieveUi::SieveImapInstanceInterfaceManager::self()->sieveImapInstanceList();
37  QVector<KSieveUi::SieveImapInstance> relevantInstances;
38  for (const KSieveUi::SieveImapInstance &instance : allInstances) {
39  if (instance.mimeTypes().contains(KMime::Message::mimeType()) && instance.capabilities().contains(QLatin1String("Resource"))
40  && !instance.capabilities().contains(QLatin1String("Virtual"))) {
41  if (PimCommon::Util::isImapResource(instance.identifier())) {
42  relevantInstances << instance;
43  }
44  }
45  }
46  return relevantInstances;
47 }
48 
50 {
51  return VacationSettings::self()->checkOutOfOfficeOnStartup();
52 }
53 
55 {
56  return VacationSettings::self()->allowOutOfOfficeSettings();
57 }
58 
59 bool Util::hasKep14CapabilitySupport(const QStringList &sieveCapabilities)
60 {
61  const bool hasIncludeCapability = sieveCapabilities.contains(QLatin1String("include"));
62  return hasIncludeCapability;
63 }
64 
65 bool Util::hasKep14Support(const QStringList &sieveCapabilities, const QStringList &availableScripts, const QString &activeScript)
66 {
67  const bool hasIncludeCapability = Util::hasKep14CapabilitySupport(sieveCapabilities);
68  if (!hasIncludeCapability) {
69  return false;
70  }
71 
72  bool masterIsActive = !activeScript.isEmpty();
73  if (masterIsActive) {
74  const QString scriptName = activeScript.split(QLatin1Char('.')).first().toLower();
75  masterIsActive = (scriptName == QLatin1String("master") || scriptName == QLatin1String("user"));
76  }
77  if (!masterIsActive) {
78  return false;
79  }
80 
81  bool hasUserScript = false;
82  for (const QString &script : availableScripts) {
83  if (script.isEmpty()) {
84  continue;
85  }
86  const QString name = script.split(QLatin1Char('.')).first().toLower();
87  if (name == QLatin1String("user")) {
88  hasUserScript = true;
89  break;
90  }
91  }
92 
93  return hasIncludeCapability && masterIsActive && hasUserScript;
94 }
95 
96 bool Util::isKep14ProtectedName(const QString &name)
97 {
98  const QString n = name.split(QLatin1Char('.')).first().toLower();
99  if (n == QLatin1String("master") || n == QLatin1String("user") || n == QLatin1String("management")) {
100  return true;
101  }
102  return false;
103 }
104 
105 QDebug Util::operator<<(QDebug d, const Util::AccountInfo &info)
106 {
107  d << "sieveImapAccountSettings " << info.sieveImapAccountSettings;
108  d << "url " << info.sieveUrl.toString();
109  return d;
110 }
111 
112 bool Util::AccountInfo::operator==(const Util::AccountInfo &other) const
113 {
114  const bool result = (other.sieveImapAccountSettings == sieveImapAccountSettings) && (other.sieveUrl == sieveUrl);
115  if (!result) {
116  qCDebug(LIBKSIEVE_LOG) << "actual :" << *this << "\n other :" << other;
117  }
118  return result;
119 }
void reserve(int alloc)
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
The SieveImapInstance class.
Type type(const QSqlDatabase &db)
bool isEmpty() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
T & first()
KSIEVEUI_EXPORT bool allowOutOfOfficeSettings()
Returns whether the functionality of vacation sieve script editing shall be available at all...
Definition: util.cpp:54
static QString mimeType()
int count(const T &value) const const
KSIEVEUI_EXPORT bool checkOutOfOfficeOnStartup()
Returns whether the availability of a vacation sieve script shall be checked at the start up of an ap...
Definition: util.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.