Libksieve

util.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Till Adam <adam@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "util.h"
8#include "libksievecore_debug.h"
9#include "sieve-vacation.h"
10#include "sieveimapinstance/sieveimapinstance.h"
11#include "sieveimapinstance/sieveimapinstanceinterfacemanager.h"
12#include "util.h"
13#include <PimCommon/PimUtil>
14#include <pimcommon/imapresourcesettings.h>
15
16#include <KMime/Message>
17#include <MailTransport/Transport>
18
19using namespace KSieveCore;
20
21QStringList KSieveCore::Util::sieveImapResourceNames()
22{
24 QStringList resourceNames;
25 resourceNames.reserve(lst.count());
26 for (const KSieveCore::SieveImapInstance &type : lst) {
27 resourceNames << type.identifier();
28 }
29 return resourceNames;
30}
31
33{
34 const QList<KSieveCore::SieveImapInstance> allInstances = KSieveCore::SieveImapInstanceInterfaceManager::self()->sieveImapInstanceList();
36 for (const KSieveCore::SieveImapInstance &instance : allInstances) {
37 if (instance.mimeTypes().contains(KMime::Message::mimeType()) && instance.capabilities().contains(QLatin1StringView("Resource"))
38 && !instance.capabilities().contains(QLatin1StringView("Virtual"))) {
39 if (PimCommon::Util::isImapResource(instance.identifier())) {
40 relevantInstances << instance;
41 }
42 }
43 }
44 return relevantInstances;
45}
46
48{
49 return VacationSettings::self()->checkOutOfOfficeOnStartup();
50}
51
53{
54 return VacationSettings::self()->allowOutOfOfficeSettings();
55}
56
57bool Util::hasKep14CapabilitySupport(const QStringList &sieveCapabilities)
58{
59 const bool hasIncludeCapability = sieveCapabilities.contains(QLatin1StringView("include"));
60 return hasIncludeCapability;
61}
62
63bool Util::hasKep14Support(const QStringList &sieveCapabilities, const QStringList &availableScripts, const QString &activeScript)
64{
65 const bool hasIncludeCapability = Util::hasKep14CapabilitySupport(sieveCapabilities);
66 if (!hasIncludeCapability) {
67 return false;
68 }
69
70 bool masterIsActive = !activeScript.isEmpty();
71 if (masterIsActive) {
72 const QString scriptName = activeScript.split(QLatin1Char('.')).first().toLower();
73 masterIsActive = (scriptName == QLatin1StringView("master") || scriptName == QLatin1StringView("user"));
74 }
75 if (!masterIsActive) {
76 return false;
77 }
78
79 bool hasUserScript = false;
80 for (const QString &script : availableScripts) {
81 if (script.isEmpty()) {
82 continue;
83 }
84 const QString name = script.split(QLatin1Char('.')).first().toLower();
85 if (name == QLatin1StringView("user")) {
86 hasUserScript = true;
87 break;
88 }
89 }
90
91 return hasIncludeCapability && masterIsActive && hasUserScript;
92}
93
95{
96 const QString n = name.split(QLatin1Char('.')).first().toLower();
97 if (n == QLatin1StringView("master") || n == QLatin1StringView("user") || n == QLatin1StringView("management")) {
98 return true;
99 }
100 return false;
101}
102
103QDebug Util::operator<<(QDebug d, const Util::AccountInfo &info)
104{
105 d << "sieveImapAccountSettings " << info.sieveImapAccountSettings;
106 d << "url " << info.sieveUrl.toString();
107 return d;
108}
109
110bool Util::AccountInfo::operator==(const Util::AccountInfo &other) const
111{
112 const bool result = (other.sieveImapAccountSettings == sieveImapAccountSettings) && (other.sieveUrl == sieveUrl);
113 if (!result) {
114 qCDebug(LIBKSIEVECORE_LOG) << "actual :" << *this << "\n other :" << other;
115 }
116 return result;
117}
static QString mimeType()
The SieveImapInstance class.
Type type(const QSqlDatabase &db)
KSIEVECORE_EXPORT QList< KSieveCore::SieveImapInstance > sieveImapInstances()
Returns the list of configured IMAP agent instances.
Definition util.cpp:32
KSIEVECORE_EXPORT bool hasKep14Support(const QStringList &sieveCapabilities, const QStringList &availableScripts, const QString &activeScript)
Checks if a server has KEP:14 support.
Definition util.cpp:63
KSIEVECORE_EXPORT bool isKep14ProtectedName(const QString &scriptName)
Is the given scriptName a protected KEP:14 name, that a normal user should not touch directly.
Definition util.cpp:94
KSIEVECORE_EXPORT bool allowOutOfOfficeSettings()
Returns whether the functionality of vacation sieve script editing shall be available at all.
Definition util.cpp:52
KSIEVECORE_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:47
qsizetype count() const const
T & first()
void reserve(qsizetype size)
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString toString(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.