job_8cpp_source

namespacejob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "namespacejob.h"
8
9#include "kimap_debug.h"
10#include <KLocalizedString>
11
12#include "imapstreamparser.h"
13#include "job_p.h"
14#include "listjob.h"
15#include "response_p.h"
16#include "rfccodecs.h"
17#include "session_p.h"
18
19namespace KIMAP
20{
21class NamespaceJobPrivate : public JobPrivate
22{
23public:
24 NamespaceJobPrivate(Session *session, const QString &name)
25 : JobPrivate(session, name)
26 {
27 }
28 ~NamespaceJobPrivate()
29 {
30 }
31
32 QList<MailBoxDescriptor> processNamespaceList(const QList<QByteArray> &namespaceList)
33 {
35
36 for (const QByteArray &namespaceItem : namespaceList) {
37 ImapStreamParser parser(nullptr);
38 parser.setData(namespaceItem);
39
40 try {
41 QList<QByteArray> parts = parser.readParenthesizedList();
42 if (parts.size() < 2) {
43 continue;
44 }
45 MailBoxDescriptor descriptor;
46 descriptor.name = QString::fromUtf8(decodeImapFolderName(parts[0]));
47 descriptor.separator = QLatin1Char(parts[1][0]);
48
49 result << descriptor;
50 } catch (const KIMAP::ImapParserException &e) {
51 qCWarning(KIMAP_LOG) << "The stream parser raised an exception during namespace list parsing:" << e.what();
52 qCWarning(KIMAP_LOG) << "namespacelist:" << namespaceList;
53 }
54 }
55
56 return result;
57 }
58
59 QList<MailBoxDescriptor> personalNamespaces;
60 QList<MailBoxDescriptor> userNamespaces;
61 QList<MailBoxDescriptor> sharedNamespaces;
62};
63}
64
65using namespace KIMAP;
66
67NamespaceJob::NamespaceJob(Session *session)
68 : Job(*new NamespaceJobPrivate(session, i18n("Namespace")))
69{
70}
71
72NamespaceJob::~NamespaceJob()
73{
74}
75
76QList<MailBoxDescriptor> NamespaceJob::personalNamespaces() const
77{
78 Q_D(const NamespaceJob);
79 return d->personalNamespaces;
80}
81
82QList<MailBoxDescriptor> NamespaceJob::userNamespaces() const
83{
84 Q_D(const NamespaceJob);
85 return d->userNamespaces;
86}
87
88QList<MailBoxDescriptor> NamespaceJob::sharedNamespaces() const
89{
90 Q_D(const NamespaceJob);
91 return d->sharedNamespaces;
92}
93
94bool NamespaceJob::containsEmptyNamespace() const
95{
96 Q_D(const NamespaceJob);
97 const QList<MailBoxDescriptor> completeList = d->personalNamespaces + d->userNamespaces + d->sharedNamespaces;
98
99 for (const MailBoxDescriptor &descriptor : completeList) {
100 if (descriptor.name.isEmpty()) {
101 return true;
102 }
103 }
104
105 return false;
106}
107
108void NamespaceJob::doStart()
109{
110 Q_D(NamespaceJob);
111 d->tags << d->sessionInternal()->sendCommand("NAMESPACE");
112}
113
114void NamespaceJob::handleResponse(const Response &response)
115{
116 Q_D(NamespaceJob);
117 if (handleErrorReplies(response) == NotHandled) {
118 if (response.content.size() >= 5 && response.content[1].toString() == "NAMESPACE") {
119 // Personal namespaces
120 d->personalNamespaces = d->processNamespaceList(response.content[2].toList());
121
122 // User namespaces
123 d->userNamespaces = d->processNamespaceList(response.content[3].toList());
124
125 // Shared namespaces
126 d->sharedNamespaces = d->processNamespaceList(response.content[4].toList());
127 }
128 }
129}
130
131#include "moc_namespacejob.cpp"
Parser for IMAP messages that operates on a local socket stream.
QString i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
qsizetype size() const const
QString fromUtf8(QByteArrayView str)
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP_EXPORT QByteArray decodeImapFolderName(const QByteArray &inSrc)
Converts an UTF-7 encoded IMAP mailbox to a QByteArray.
Definition rfccodecs.cpp:53
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:51:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.