KIMAP2

acl.cpp
1/*
2 Copyright (c) 2009 Andras Mantia <amantia@kde.org>
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
25namespace KIMAP2
26{
27namespace Acl
28{
29
30class RightsMap
31{
32public:
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
64Q_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}
Right
Possible rights that can be held on a mailbox.
Definition acl.h:39
@ CreateMailbox
Create new child mailboxes, or move a mailbox with this mailbox as the new parent.
Definition acl.h:63
@ Custom9
Server-specific right 9.
Definition acl.h:93
@ Write
Set or clear flags other than \Seen and \Deleted on messages in the mailbox.
Definition acl.h:48
@ Post
Send mail to the submission address for the mailbox.
Definition acl.h:55
@ Insert
Perform APPEND and COPY with the mailbox as the target.
Definition acl.h:50
@ Expunge
Expunge the messages in this mailbox.
Definition acl.h:77
@ Custom0
Server-specific right 0.
Definition acl.h:84
@ Custom6
Server-specific right 6.
Definition acl.h:90
@ Custom4
Server-specific right 4.
Definition acl.h:88
@ DeleteMailbox
Delete or move the mailbox.
Definition acl.h:65
@ Custom3
Server-specific right 3.
Definition acl.h:87
@ Read
SELECT the mailbox, perform STATUS.
Definition acl.h:44
@ Custom8
Server-specific right 8.
Definition acl.h:92
@ Create
Obsolete as of RFC 4314, replaced by CreateMailbox and DeleteMailbox.
Definition acl.h:57
@ Admin
View and modify the access control list for the mailbox.
Definition acl.h:71
@ DeleteMessage
Set or clear the \Deleted flag on messages in the mailbox.
Definition acl.h:67
@ Custom7
Server-specific right 7.
Definition acl.h:91
@ WriteShared
Write shared annotations.
Definition acl.h:83
@ Custom5
Server-specific right 5.
Definition acl.h:89
@ Custom1
Server-specific right 1.
Definition acl.h:85
@ Delete
Obsolete as of RFC 4314, replaced by DeleteMessage and Expunge.
Definition acl.h:69
@ Lookup
Mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox.
Definition acl.h:42
@ Custom2
Server-specific right 2.
Definition acl.h:86
@ KeepSeen
Set or clear the \Seen flag on messages in the mailbox, and keep it across sessions.
Definition acl.h:46
KIMAP2_EXPORT Rights rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition acl.cpp:69
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
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:59:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.