KIMAP

acl.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "acl.h"
8 
9 #include <QByteArray>
10 #include <QMap>
11 
12 namespace KIMAP
13 {
14 namespace Acl
15 {
16 class RightsMap
17 {
18 public:
19  RightsMap()
20  {
21  map['l'] = Lookup;
22  map['r'] = Read;
23  map['s'] = KeepSeen;
24  map['w'] = Write;
25  map['i'] = Insert;
26  map['p'] = Post;
27  map['c'] = Create; // TODO: obsolete, keep it?
28  map['d'] = Delete; // TODO: obsolete, keep it?
29  map['k'] = CreateMailbox;
30  map['x'] = DeleteMailbox;
31  map['t'] = DeleteMessage;
32  map['e'] = Expunge;
33  map['a'] = Admin;
34  map['n'] = WriteShared;
35  map['0'] = Custom0;
36  map['1'] = Custom1;
37  map['2'] = Custom2;
38  map['3'] = Custom3;
39  map['4'] = Custom4;
40  map['5'] = Custom5;
41  map['6'] = Custom6;
42  map['7'] = Custom7;
43  map['8'] = Custom8;
44  map['9'] = Custom9;
45  }
46 
48 };
49 
50 Q_GLOBAL_STATIC(RightsMap, globalRights)
51 
52 }
53 }
54 
56 {
57  Rights result;
58 
59  if (string.isEmpty()) {
60  return result;
61  }
62 
63  int pos = 0;
64  if (string[0] == '+' || string[0] == '-') { // Skip modifier if any
65  pos++;
66  }
67 
68  for (int i = pos; i < string.size(); i++) {
69  if (globalRights->map.contains(string[i])) {
70  result |= globalRights->map[string[i]];
71  }
72  }
73 
74  return result;
75 }
76 
78 {
79  QByteArray result;
80 
81  for (int right = Lookup; right <= Custom9; right <<= 1) {
82  if (rights & right) {
83  result += globalRights->map.key(static_cast<Right>(right));
84  }
85  }
86 
87  return result;
88 }
89 
91 {
92  Rights normalized = rights;
93  if (normalized & Create) {
94  normalized |= (CreateMailbox | DeleteMailbox);
95  normalized &= ~Create;
96  }
97  if (normalized & Delete) {
98  normalized |= (DeleteMessage | Expunge);
99  normalized &= ~Delete;
100  }
101  return normalized;
102 }
103 
105 {
106  Rights denormalized = normalizedRights(rights);
107  if (denormalized & (CreateMailbox | DeleteMailbox)) {
108  denormalized |= Create;
109  }
110  if (denormalized & (DeleteMessage | Expunge)) {
111  denormalized |= Delete;
112  }
113  return denormalized;
114 }
KIMAP_EXPORT Rights normalizedRights(Rights rights)
Returns a rights mask that has no obsolete members anymore, i.e.
Definition: acl.cpp:90
Set or clear the flag on messages in the mailbox, and keep it across sessions.
Definition: acl.h:30
Create new child mailboxes, or move a mailbox with this mailbox as the new parent.
Definition: acl.h:47
Server-specific right 2.
Definition: acl.h:70
KIMAP_EXPORT QByteArray rightsToString(Rights rights)
Convert a set of rights into text format.
Definition: acl.cpp:77
Server-specific right 4.
Definition: acl.h:72
Server-specific right 1.
Definition: acl.h:69
Send mail to the submission address for the mailbox.
Definition: acl.h:39
Write shared annotations.
Definition: acl.h:67
Obsolete as of RFC 4314, replaced by CreateMailbox and DeleteMailbox.
Definition: acl.h:41
Delete or move the mailbox.
Definition: acl.h:49
SELECT the mailbox, perform STATUS.
Definition: acl.h:28
Mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox.
Definition: acl.h:26
Server-specific right 0.
Definition: acl.h:68
Obsolete as of RFC 4314, replaced by DeleteMessage and Expunge.
Definition: acl.h:53
Set or clear flags other than and on messages in the mailbox.
Definition: acl.h:32
Server-specific right 8.
Definition: acl.h:76
KIMAP_EXPORT Rights denormalizedRights(Rights rights)
Returns a rights mask that contains both obsolete and new flags if one of them is set...
Definition: acl.cpp:104
Set or clear the flag on messages in the mailbox.
Definition: acl.h:51
KIMAP_EXPORT Rights rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition: acl.cpp:55
Expunge the messages in this mailbox.
Definition: acl.h:61
Server-specific right 9.
Definition: acl.h:77
View and modify the access control list for the mailbox.
Definition: acl.h:55
Server-specific right 3.
Definition: acl.h:71
Definition: acl.cpp:12
Perform APPEND and COPY with the mailbox as the target.
Definition: acl.h:34
Server-specific right 5.
Definition: acl.h:73
Server-specific right 6.
Definition: acl.h:74
Server-specific right 7.
Definition: acl.h:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 23:12:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.