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 }
@ DeleteMailbox
Delete or move the mailbox.
Definition: acl.h:49
@ Custom4
Server-specific right 4.
Definition: acl.h:72
@ Custom2
Server-specific right 2.
Definition: acl.h:70
@ Custom3
Server-specific right 3.
Definition: acl.h:71
@ Expunge
Expunge the messages in this mailbox.
Definition: acl.h:61
Right
Possible rights that can be held on a mailbox.
Definition: acl.h:23
@ Custom9
Server-specific right 9.
Definition: acl.h:77
@ Custom1
Server-specific right 1.
Definition: acl.h:69
@ Insert
Perform APPEND and COPY with the mailbox as the target.
Definition: acl.h:34
@ Custom0
Server-specific right 0.
Definition: acl.h:68
@ WriteShared
Write shared annotations.
Definition: acl.h:67
@ Create
Obsolete as of RFC 4314, replaced by CreateMailbox and DeleteMailbox.
Definition: acl.h:41
KIMAP_EXPORT Rights rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition: acl.cpp:55
@ Custom6
Server-specific right 6.
Definition: acl.h:74
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
@ Delete
Obsolete as of RFC 4314, replaced by DeleteMessage and Expunge.
Definition: acl.h:53
@ Custom8
Server-specific right 8.
Definition: acl.h:76
@ Write
Set or clear flags other than \Seen and \Deleted on messages in the mailbox.
Definition: acl.h:32
@ Custom5
Server-specific right 5.
Definition: acl.h:73
@ DeleteMessage
Set or clear the \Deleted flag on messages in the mailbox.
Definition: acl.h:51
@ Admin
View and modify the access control list for the mailbox.
Definition: acl.h:55
@ KeepSeen
Set or clear the \Seen flag on messages in the mailbox, and keep it across sessions.
Definition: acl.h:30
@ Custom7
Server-specific right 7.
Definition: acl.h:75
KIMAP_EXPORT Rights normalizedRights(Rights rights)
Returns a rights mask that has no obsolete members anymore, i.e.
Definition: acl.cpp:90
@ Read
SELECT the mailbox, perform STATUS.
Definition: acl.h:28
@ Lookup
Mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox.
Definition: acl.h:26
@ Post
Send mail to the submission address for the mailbox.
Definition: acl.h:39
@ CreateMailbox
Create new child mailboxes, or move a mailbox with this mailbox as the new parent.
Definition: acl.h:47
KIMAP_EXPORT QByteArray rightsToString(Rights rights)
Convert a set of rights into text format.
Definition: acl.cpp:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 03:48:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.