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

KDE's Doxygen guidelines are available online.