• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.5 API Reference
  • KDE Home
  • Contact Us
 

KIMAP Library

acl.cpp
00001 /*
00002     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "acl.h"
00021 
00022 #include <QtCore/QByteArray>
00023 #include <QtCore/QMap>
00024 #include <KDE/KGlobal>
00025 
00026 namespace KIMAP {
00027 namespace Acl {
00028 
00029 class RightsMap
00030 {
00031   public:
00032     RightsMap()
00033     {
00034       map['l'] = Lookup;
00035       map['r'] = Read;
00036       map['s'] = KeepSeen;
00037       map['w'] = Write;
00038       map['i'] = Insert;
00039       map['p'] = Post;
00040       map['c'] = Create; //TODO: obsolete, keep it?
00041       map['d'] = Delete; //TODO: obsolete, keep it?
00042       map['k'] = CreateMailbox;
00043       map['x'] = DeleteMailbox;
00044       map['t'] = DeleteMessage;
00045       map['e'] = Expunge;
00046       map['a'] = Admin;
00047       map['n'] = WriteShared;
00048       map['0'] = Custom0;
00049       map['1'] = Custom1;
00050       map['2'] = Custom2;
00051       map['3'] = Custom3;
00052       map['4'] = Custom4;
00053       map['5'] = Custom5;
00054       map['6'] = Custom6;
00055       map['7'] = Custom7;
00056       map['8'] = Custom8;
00057       map['9'] = Custom9;
00058     }
00059 
00060     QMap<char, Right> map;
00061 };
00062 
00063 K_GLOBAL_STATIC(RightsMap, globalRights)
00064 
00065 }
00066 }
00067 
00068 KIMAP::Acl::Rights KIMAP::Acl::rightsFromString( const QByteArray &string )
00069 {
00070   Rights result;
00071 
00072   if ( string.isEmpty() )
00073     return result;
00074 
00075   int pos = 0;
00076   if ( string[0] == '+' || string[0]== '-') { // Skip modifier if any
00077     pos++;
00078   }
00079 
00080   for ( int i = pos; i < string.size(); i++ ) {
00081     if ( globalRights->map.contains( string[i] ) ) {
00082       result|= globalRights->map[string[i]];
00083     }
00084   }
00085 
00086   return result;
00087 }
00088 
00089 QByteArray KIMAP::Acl::rightsToString( Rights rights )
00090 {
00091   QByteArray result;
00092 
00093   for ( int right = Lookup; right<=Custom9; right<<=1 ) {
00094     if ( rights & right ) {
00095       result+= globalRights->map.key( (Right)right );
00096     }
00097   }
00098 
00099   return result;
00100 }
00101 
00102 KIMAP::Acl::Rights KIMAP::Acl::normalizedRights( KIMAP::Acl::Rights rights )
00103 {
00104   Rights normalized = rights;
00105   if ( normalized & Create ) {
00106     normalized |= ( CreateMailbox | DeleteMailbox );
00107     normalized &= ~Create;
00108   }
00109   if ( normalized & Delete ) {
00110     normalized |= ( DeleteMessage | Expunge );
00111     normalized &= ~Delete;
00112   }
00113   return normalized;
00114 }
00115 
00116 KIMAP::Acl::Rights KIMAP::Acl::denormalizedRights( KIMAP::Acl::Rights rights )
00117 {
00118   Rights denormalized = normalizedRights( rights );
00119   if ( denormalized & ( CreateMailbox | DeleteMailbox ) ) {
00120     denormalized |= Create;
00121   }
00122   if ( denormalized & ( DeleteMessage | Expunge ) ) {
00123     denormalized |= Delete;
00124   }
00125   return denormalized;
00126 }
00127 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:08:13 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal