KIMAP

getacljob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "getacljob.h"
8 
9 #include "kimap_debug.h"
10 #include <KLocalizedString>
11 
12 #include "acljobbase_p.h"
13 #include "response_p.h"
14 #include "rfccodecs.h"
15 #include "session_p.h"
16 
17 namespace KIMAP
18 {
19 class GetAclJobPrivate : public AclJobBasePrivate
20 {
21 public:
22  GetAclJobPrivate(Session *session, const QString &name)
23  : AclJobBasePrivate(session, name)
24  {
25  }
26  ~GetAclJobPrivate()
27  {
28  }
29 
31 };
32 }
33 
34 using namespace KIMAP;
35 
36 GetAclJob::GetAclJob(Session *session)
37  : AclJobBase(*new GetAclJobPrivate(session, i18n("GetAcl")))
38 {
39 }
40 
41 GetAclJob::~GetAclJob()
42 {
43 }
44 
45 void GetAclJob::doStart()
46 {
47  Q_D(GetAclJob);
48 
49  d->tags << d->sessionInternal()->sendCommand("GETACL", '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"');
50 }
51 
52 void GetAclJob::handleResponse(const Response &response)
53 {
54  Q_D(GetAclJob);
55  // qCDebug(KIMAP_LOG) << response.toString();
56 
57  if (handleErrorReplies(response) == NotHandled) {
58  if (response.content.size() >= 4 && response.content[1].toString() == "ACL") {
59  int i = 3;
60  while (i < response.content.size() - 1) {
61  QByteArray id = response.content[i].toString();
62  QByteArray rights = response.content[i + 1].toString();
63  d->userRights[id] = Acl::rightsFromString(rights);
64  i += 2;
65  }
66  }
67  }
68 }
69 
71 {
72  Q_D(const GetAclJob);
73  return d->userRights.keys();
74 }
75 
76 bool GetAclJob::hasRightEnabled(const QByteArray &identifier, Acl::Right right) const
77 {
78  Q_D(const GetAclJob);
79  if (d->userRights.contains(identifier)) {
80  Acl::Rights rights = d->userRights[identifier];
81  return rights & right;
82  }
83 
84  return false;
85 }
86 
87 Acl::Rights GetAclJob::rights(const QByteArray &identifier) const
88 {
89  Q_D(const GetAclJob);
91  if (d->userRights.contains(identifier)) {
92  result = d->userRights[identifier];
93  }
94  return result;
95 }
96 
98 {
99  Q_D(const GetAclJob);
100  return d->userRights;
101 }
102 
103 #include "moc_getacljob.cpp"
Right
Possible rights that can be held on a mailbox.
Definition: acl.h:23
Base class for jobs that operate on mailbox ACLs.
Definition: acljobbase.h:29
QMap< QByteArray, Acl::Rights > allRights() const
Gets the full access control list.
Definition: getacljob.cpp:97
Gets the ACL for a mailbox.
Definition: getacljob.h:48
void result(KJob *job)
KIMAP_EXPORT Rights rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition: acl.cpp:55
QString i18n(const char *text, const TYPE &arg...)
const char * name(StandardAction id)
QList< QByteArray > identifiers() const
The identifiers present in the ACL.
Definition: getacljob.cpp:70
Acl::Rights rights(const QByteArray &identifier) const
Get the rights associated with an identifier.
Definition: getacljob.cpp:87
Provides handlers for various RFC/MIME encodings.
bool hasRightEnabled(const QByteArray &identifier, Acl::Right right) const
Check whether an identifier has a given right set.
Definition: getacljob.cpp:76
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 03:51:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.