KIMAP

acl.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "acl.h"
8
9#include <QByteArray>
10#include <QMap>
11
12namespace KIMAP
13{
14namespace Acl
15{
16class RightsMap
17{
18public:
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
50Q_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 rightsFromString(const QByteArray &string)
Convert the text form of a set of rights into a Rights bitflag.
Definition acl.cpp:55
KIMAP_EXPORT QByteArray rightsToString(Rights rights)
Convert a set of rights into text format.
Definition acl.cpp:77
Right
Possible rights that can be held on a mailbox.
Definition acl.h:23
@ Expunge
Expunge the messages in this mailbox.
Definition acl.h:61
@ WriteShared
Write shared annotations.
Definition acl.h:67
@ CreateMailbox
Create new child mailboxes, or move a mailbox with this mailbox as the new parent.
Definition acl.h:47
@ Delete
Obsolete as of RFC 4314, replaced by DeleteMessage and Expunge.
Definition acl.h:53
@ Custom3
Server-specific right 3.
Definition acl.h:71
@ KeepSeen
Set or clear the \Seen flag on messages in the mailbox, and keep it across sessions.
Definition acl.h:30
@ Custom9
Server-specific right 9.
Definition acl.h:77
@ Admin
View and modify the access control list for the mailbox.
Definition acl.h:55
@ Create
Obsolete as of RFC 4314, replaced by CreateMailbox and DeleteMailbox.
Definition acl.h:41
@ Insert
Perform APPEND and COPY with the mailbox as the target.
Definition acl.h:34
@ Custom5
Server-specific right 5.
Definition acl.h:73
@ Custom0
Server-specific right 0.
Definition acl.h:68
@ Custom2
Server-specific right 2.
Definition acl.h:70
@ Lookup
Mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox.
Definition acl.h:26
@ Custom1
Server-specific right 1.
Definition acl.h:69
@ Custom4
Server-specific right 4.
Definition acl.h:72
@ Custom7
Server-specific right 7.
Definition acl.h:75
@ Post
Send mail to the submission address for the mailbox.
Definition acl.h:39
@ DeleteMessage
Set or clear the \Deleted flag on messages in the mailbox.
Definition acl.h:51
@ Custom6
Server-specific right 6.
Definition acl.h:74
@ Read
SELECT the mailbox, perform STATUS.
Definition acl.h:28
@ Write
Set or clear flags other than \Seen and \Deleted on messages in the mailbox.
Definition acl.h:32
@ Custom8
Server-specific right 8.
Definition acl.h:76
@ DeleteMailbox
Delete or move the mailbox.
Definition acl.h:49
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
KIMAP_EXPORT Rights normalizedRights(Rights rights)
Returns a rights mask that has no obsolete members anymore, i.e.
Definition acl.cpp:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.