2012-06-29 19:59:38 +02:00
|
|
|
/* MAPIStoreDBFolder.m - this file is part of SOGo
|
2011-02-24 21:32:27 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Inverse inc
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2011-08-12 17:02:01 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2011-02-24 21:32:27 +01:00
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2011-06-23 15:57:09 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2011-02-24 21:32:27 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2012-06-01 17:15:30 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2011-02-24 21:32:27 +01:00
|
|
|
#import <Foundation/NSString.h>
|
2011-06-07 02:17:46 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2011-02-24 21:32:27 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2011-08-12 00:56:04 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
2011-12-01 23:53:11 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2011-10-27 01:52:55 +02:00
|
|
|
#import "EOQualifier+MAPI.h"
|
2011-12-01 23:53:11 +01:00
|
|
|
#import "MAPIStoreContext.h"
|
2012-06-29 19:59:38 +02:00
|
|
|
#import "MAPIStoreDBFolderTable.h"
|
|
|
|
#import "MAPIStoreDBMessage.h"
|
|
|
|
#import "MAPIStoreDBMessageTable.h"
|
2011-06-07 02:17:46 +02:00
|
|
|
#import "MAPIStoreTypes.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2012-06-29 19:59:38 +02:00
|
|
|
#import "SOGoMAPIDBFolder.h"
|
|
|
|
#import "SOGoMAPIDBMessage.h"
|
2011-02-24 21:32:27 +01:00
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
#import "MAPIStoreDBFolder.h"
|
2011-02-24 21:32:27 +01:00
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
2012-02-03 16:05:19 +01:00
|
|
|
#include <mapistore/mapistore_errors.h>
|
2011-02-24 21:32:27 +01:00
|
|
|
|
2011-09-23 17:36:49 +02:00
|
|
|
static Class EOKeyValueQualifierK;
|
2011-02-24 21:32:27 +01:00
|
|
|
|
2011-12-02 00:02:45 +01:00
|
|
|
static NSString *MAPIStoreRightReadItems = @"RightsReadItems";
|
|
|
|
static NSString *MAPIStoreRightCreateItems = @"RightsCreateItems";
|
|
|
|
static NSString *MAPIStoreRightEditOwn = @"RightsEditOwn";
|
|
|
|
static NSString *MAPIStoreRightEditAll = @"RightsEditAll";
|
|
|
|
static NSString *MAPIStoreRightDeleteOwn = @"RightsDeleteOwn";
|
|
|
|
static NSString *MAPIStoreRightDeleteAll = @"RightsDeleteAll";
|
|
|
|
static NSString *MAPIStoreRightCreateSubfolders = @"RightsCreateSubfolders";
|
|
|
|
static NSString *MAPIStoreRightFolderOwner = @"RightsFolderOwner";
|
|
|
|
static NSString *MAPIStoreRightFolderContact = @"RightsFolderContact";
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
@implementation MAPIStoreDBFolder
|
2011-02-24 21:32:27 +01:00
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2011-08-12 00:56:04 +02:00
|
|
|
EOKeyValueQualifierK = [EOKeyValueQualifier class];
|
2011-02-24 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
2012-06-29 19:59:38 +02:00
|
|
|
- (void) setupAuxiliaryObjects
|
|
|
|
{
|
|
|
|
[super setupAuxiliaryObjects];
|
|
|
|
ASSIGN (sogoObject, dbFolder);
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:32:27 +01:00
|
|
|
- (MAPIStoreMessageTable *) messageTable
|
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return [MAPIStoreDBMessageTable tableForContainer: self];
|
2011-02-24 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:56:04 +02:00
|
|
|
- (MAPIStoreFolderTable *) folderTable
|
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return [MAPIStoreDBFolderTable tableForContainer: self];
|
2011-08-12 00:56:04 +02:00
|
|
|
}
|
|
|
|
|
2012-02-03 16:05:19 +01:00
|
|
|
- (enum mapistore_error) createFolder: (struct SRow *) aRow
|
|
|
|
withFID: (uint64_t) newFID
|
|
|
|
andKey: (NSString **) newKeyP
|
2011-06-07 02:17:46 +02:00
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
*newKeyP = [NSString stringWithFormat: @"0x%.16"PRIx64, (unsigned long long) newFID];
|
2011-06-07 02:17:46 +02:00
|
|
|
|
2012-02-03 16:05:19 +01:00
|
|
|
return MAPISTORE_SUCCESS;
|
2011-06-07 02:17:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:33:35 +02:00
|
|
|
- (MAPIStoreMessage *) createMessage
|
2011-02-24 21:32:27 +01:00
|
|
|
{
|
|
|
|
MAPIStoreMessage *newMessage;
|
2012-06-29 19:59:38 +02:00
|
|
|
SOGoMAPIDBMessage *fsObject;
|
2011-02-24 21:32:27 +01:00
|
|
|
NSString *newKey;
|
|
|
|
|
|
|
|
newKey = [NSString stringWithFormat: @"%@.plist",
|
|
|
|
[SOGoObject globallyUniqueObjectId]];
|
2012-06-29 19:59:38 +02:00
|
|
|
fsObject = [SOGoMAPIDBMessage objectWithName: newKey
|
2011-12-01 23:42:30 +01:00
|
|
|
inContainer: sogoObject];
|
2012-06-29 19:59:38 +02:00
|
|
|
[fsObject setObjectType: MAPIDBObjectTypeMessage];
|
|
|
|
newMessage = [MAPIStoreDBMessage mapiStoreObjectWithSOGoObject: fsObject
|
2011-02-24 21:32:27 +01:00
|
|
|
inContainer: self];
|
|
|
|
|
|
|
|
return newMessage;
|
|
|
|
}
|
|
|
|
|
2011-07-26 22:13:10 +02:00
|
|
|
- (NSArray *) messageKeysMatchingQualifier: (EOQualifier *) qualifier
|
|
|
|
andSortOrderings: (NSArray *) sortOrderings
|
2011-02-24 21:32:27 +01:00
|
|
|
{
|
2011-12-02 18:14:19 +01:00
|
|
|
NSArray *keys;
|
2012-01-29 20:55:21 +01:00
|
|
|
SOGoUser *ownerUser;
|
2011-12-02 18:14:19 +01:00
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
ownerUser = [[self userContext] sogoUser];
|
|
|
|
if ([[context activeUser] isEqual: ownerUser]
|
2011-12-02 18:14:19 +01:00
|
|
|
|| [self subscriberCanReadMessages])
|
2012-06-29 19:59:38 +02:00
|
|
|
keys = [(SOGoMAPIDBFolder *) sogoObject childKeysOfType: MAPIDBObjectTypeMessage
|
|
|
|
includeDeleted: NO
|
|
|
|
matchingQualifier: qualifier
|
|
|
|
andSortOrderings: sortOrderings];
|
2011-12-02 18:14:19 +01:00
|
|
|
else
|
|
|
|
keys = [NSArray array];
|
|
|
|
|
|
|
|
return keys;
|
2011-02-24 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:56:04 +02:00
|
|
|
- (NSArray *) folderKeysMatchingQualifier: (EOQualifier *) qualifier
|
|
|
|
andSortOrderings: (NSArray *) sortOrderings
|
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return [dbFolder childKeysOfType: MAPIDBObjectTypeFolder
|
|
|
|
includeDeleted: NO
|
|
|
|
matchingQualifier: qualifier
|
|
|
|
andSortOrderings: sortOrderings];
|
2011-08-12 00:56:04 +02:00
|
|
|
}
|
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
- (NSDate *) lastMessageModificationTime
|
|
|
|
{
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSDate *date, *fileDate;
|
2012-06-29 19:59:38 +02:00
|
|
|
MAPIStoreDBMessage *msg;
|
2012-03-09 03:08:57 +01:00
|
|
|
NSArray *messageKeys;
|
2011-06-07 02:17:46 +02:00
|
|
|
|
2012-03-09 03:08:57 +01:00
|
|
|
messageKeys = [self messageKeys];
|
2011-06-07 02:17:46 +02:00
|
|
|
|
|
|
|
date = [NSCalendarDate date];
|
|
|
|
[self logWithFormat: @"current date: %@", date];
|
|
|
|
|
|
|
|
max = [messageKeys count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2011-07-26 21:02:45 +02:00
|
|
|
msg = [self lookupMessage: [messageKeys objectAtIndex: count]];
|
2011-06-07 02:17:46 +02:00
|
|
|
fileDate = [msg lastModificationTime];
|
|
|
|
if ([date laterDate: fileDate] == fileDate)
|
|
|
|
{
|
|
|
|
[self logWithFormat: @"current date: %@", date];
|
|
|
|
|
|
|
|
date = fileDate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
- (SOGoFolder *) aclFolder
|
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
return sogoObject;
|
2011-11-18 16:26:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) rolesForExchangeRights: (uint32_t) rights
|
|
|
|
{
|
|
|
|
NSMutableArray *roles;
|
|
|
|
|
|
|
|
roles = [NSMutableArray arrayWithCapacity: 9];
|
|
|
|
if (rights & RightsReadItems)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightReadItems];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsCreateItems)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightCreateItems];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsEditOwn)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightEditOwn];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsDeleteOwn)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightDeleteOwn];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsEditAll)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightEditAll];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsDeleteAll)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightDeleteAll];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsCreateSubfolders)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightCreateSubfolders];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsFolderOwner)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightFolderOwner];
|
2011-11-18 16:26:03 +01:00
|
|
|
if (rights & RightsFolderContact)
|
2011-12-02 00:02:45 +01:00
|
|
|
[roles addObject: MAPIStoreRightFolderContact];
|
2011-11-18 16:26:03 +01:00
|
|
|
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint32_t) exchangeRightsForRoles: (NSArray *) roles
|
|
|
|
{
|
|
|
|
uint32_t rights = 0;
|
|
|
|
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightReadItems])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsReadItems;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightCreateItems])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsCreateItems;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightEditOwn])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsEditOwn;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightDeleteOwn])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsDeleteOwn;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightEditAll])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsEditAll;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightDeleteAll])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsDeleteAll;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightCreateSubfolders])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsCreateSubfolders;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightFolderOwner])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsFolderOwner;
|
2011-12-02 00:02:45 +01:00
|
|
|
if ([roles containsObject: MAPIStoreRightFolderContact])
|
2011-11-18 16:26:03 +01:00
|
|
|
rights |= RightsFolderContact;
|
|
|
|
if (rights != 0)
|
|
|
|
rights |= RoleNone; /* actually "folder visible" */
|
|
|
|
|
|
|
|
return rights;
|
|
|
|
}
|
|
|
|
|
2011-12-02 00:02:45 +01:00
|
|
|
- (BOOL) _testRoleForActiveUser: (const NSString *) role
|
2011-12-01 23:53:11 +01:00
|
|
|
{
|
|
|
|
SOGoUser *activeUser;
|
|
|
|
NSArray *roles;
|
|
|
|
|
|
|
|
activeUser = [[self context] activeUser];
|
|
|
|
|
|
|
|
roles = [[self aclFolder] aclsForUser: [activeUser login]];
|
|
|
|
|
|
|
|
return [roles containsObject: role];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanCreateMessages
|
|
|
|
{
|
2011-12-02 00:02:45 +01:00
|
|
|
return [self _testRoleForActiveUser: MAPIStoreRightCreateItems];
|
2011-12-01 23:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanModifyMessages
|
|
|
|
{
|
2011-12-02 00:02:45 +01:00
|
|
|
return ([self _testRoleForActiveUser: MAPIStoreRightEditAll]
|
|
|
|
|| [self _testRoleForActiveUser: MAPIStoreRightEditOwn]);
|
2011-12-01 23:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanReadMessages
|
|
|
|
{
|
2011-12-02 00:02:45 +01:00
|
|
|
return [self _testRoleForActiveUser: MAPIStoreRightReadItems];
|
2011-12-01 23:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanDeleteMessages
|
|
|
|
{
|
2011-12-02 00:02:45 +01:00
|
|
|
return ([self _testRoleForActiveUser: MAPIStoreRightDeleteAll]
|
|
|
|
|| [self _testRoleForActiveUser: MAPIStoreRightDeleteOwn]);
|
2011-12-01 23:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanCreateSubFolders
|
|
|
|
{
|
2011-12-02 00:02:45 +01:00
|
|
|
return [self _testRoleForActiveUser: MAPIStoreRightCreateSubfolders];
|
2011-12-01 23:53:11 +01:00
|
|
|
}
|
|
|
|
|
2012-01-26 20:56:24 +01:00
|
|
|
- (BOOL) supportsSubFolders
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:32:27 +01:00
|
|
|
@end
|