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

KDE's Doxygen guidelines are available online.