KIMAP2

acl.cpp
1 /*
2  Copyright (c) 2009 Andras Mantia <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "acl.h"
21 
22 #include <QtCore/QByteArray>
23 #include <QtCore/QMap>
24 
25 namespace KIMAP2
26 {
27 namespace Acl
28 {
29 
30 class RightsMap
31 {
32 public:
33  RightsMap()
34  {
35  map['l'] = Lookup;
36  map['r'] = Read;
37  map['s'] = KeepSeen;
38  map['w'] = Write;
39  map['i'] = Insert;
40  map['p'] = Post;
41  map['c'] = Create; //TODO: obsolete, keep it?
42  map['d'] = Delete; //TODO: obsolete, keep it?
43  map['k'] = CreateMailbox;
44  map['x'] = DeleteMailbox;
45  map['t'] = DeleteMessage;
46  map['e'] = Expunge;
47  map['a'] = Admin;
48  map['n'] = WriteShared;
49  map['0'] = Custom0;
50  map['1'] = Custom1;
51  map['2'] = Custom2;
52  map['3'] = Custom3;
53  map['4'] = Custom4;
54  map['5'] = Custom5;
55  map['6'] = Custom6;
56  map['7'] = Custom7;
57  map['8'] = Custom8;
58  map['9'] = Custom9;
59  }
60 
62 };
63 
64 Q_GLOBAL_STATIC(RightsMap, globalRights)
65 
66 }
67 }
68 
70 {
71  Rights result;
72 
73  if (string.isEmpty()) {
74  return result;
75  }
76 
77  int pos = 0;
78  if (string[0] == '+' || string[0] == '-') { // Skip modifier if any
79  pos++;
80  }
81 
82  for (int i = pos; i < string.size(); i++) {
83  if (globalRights->map.contains(string[i])) {
84  result |= globalRights->map[string[i]];
85  }
86  }
87 
88  return result;
89 }
90 
92 {
93  QByteArray result;
94 
95  for (int right = Lookup; right <= Custom9; right <<= 1) {
96  if (rights & right) {
97  result += globalRights->map.key((Right)right);
98  }
99  }
100 
101  return result;
102 }
103 
105 {
106  Rights normalized = rights;
107  if (normalized & Create) {
108  normalized |= (CreateMailbox | DeleteMailbox);
109  normalized &= ~Create;
110  }
111  if (normalized & Delete) {
112  normalized |= (DeleteMessage | Expunge);
113  normalized &= ~Delete;
114  }
115  return normalized;
116 }
117 
119 {
120  Rights denormalized = normalizedRights(rights);
121  if (denormalized & (CreateMailbox | DeleteMailbox)) {
122  denormalized |= Create;
123  }
124  if (denormalized & (DeleteMessage | Expunge)) {
125  denormalized |= Delete;
126  }
127  return denormalized;
128 }
Mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox.
Definition: acl.h:42
Delete or move the mailbox.
Definition: acl.h:65
Server-specific right 1.
Definition: acl.h:85
Server-specific right 9.
Definition: acl.h:93
Perform APPEND and COPY with the mailbox as the target.
Definition: acl.h:50
Create new child mailboxes, or move a mailbox with this mailbox as the new parent.
Definition: acl.h:63
Server-specific right 6.
Definition: acl.h:90
Server-specific right 4.
Definition: acl.h:88
KIMAP2_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:118
Write shared annotations.
Definition: acl.h:83
Server-specific right 0.
Definition: acl.h:84
Obsolete as of RFC 4314, replaced by CreateMailbox and DeleteMailbox.
Definition: acl.h:57
Expunge the messages in this mailbox.
Definition: acl.h:77
Definition: acl.cpp:25
KIMAP2_EXPORT Rights rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition: acl.cpp:69
Right
Possible rights that can be held on a mailbox.
Definition: acl.h:39
Server-specific right 5.
Definition: acl.h:89
Server-specific right 3.
Definition: acl.h:87
Server-specific right 7.
Definition: acl.h:91
Set or clear the flag on messages in the mailbox, and keep it across sessions.
Definition: acl.h:46
Obsolete as of RFC 4314, replaced by DeleteMessage and Expunge.
Definition: acl.h:69
Server-specific right 2.
Definition: acl.h:86
SELECT the mailbox, perform STATUS.
Definition: acl.h:44
Server-specific right 8.
Definition: acl.h:92
Send mail to the submission address for the mailbox.
Definition: acl.h:55
Set or clear flags other than and on messages in the mailbox.
Definition: acl.h:48
View and modify the access control list for the mailbox.
Definition: acl.h:71
KIMAP2_EXPORT QByteArray rightsToString(Rights rights)
Convert a set of rights into text format.
Definition: acl.cpp:91
KIMAP2_EXPORT Rights normalizedRights(Rights rights)
Returns a rights mask that has no obsolete members anymore, i.e.
Definition: acl.cpp:104
Set or clear the flag on messages in the mailbox.
Definition: acl.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 23:07:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.