job_8cpp_source

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

KDE's Doxygen guidelines are available online.