2011-02-24 21:32:27 +01:00
|
|
|
/* MAPIStoreFSFolder.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#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"
|
2011-08-12 00:56:04 +02:00
|
|
|
#import "MAPIStoreFSFolderTable.h"
|
2011-02-24 21:32:27 +01:00
|
|
|
#import "MAPIStoreFSMessage.h"
|
2011-03-07 20:15:16 +01:00
|
|
|
#import "MAPIStoreFSMessageTable.h"
|
2011-06-07 02:17:46 +02:00
|
|
|
#import "MAPIStoreTypes.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2011-02-24 21:32:27 +01:00
|
|
|
#import "SOGoMAPIFSFolder.h"
|
|
|
|
#import "SOGoMAPIFSMessage.h"
|
|
|
|
|
|
|
|
#import "MAPIStoreFSFolder.h"
|
|
|
|
|
|
|
|
#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";
|
|
|
|
|
2011-02-24 21:32:27 +01:00
|
|
|
@implementation MAPIStoreFSFolder
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2011-08-12 00:56:04 +02:00
|
|
|
EOKeyValueQualifierK = [EOKeyValueQualifier class];
|
2011-02-24 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreMessageTable *) messageTable
|
|
|
|
{
|
2011-03-07 20:15:16 +01:00
|
|
|
return [MAPIStoreFSMessageTable tableForContainer: self];
|
2011-02-24 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:56:04 +02:00
|
|
|
- (MAPIStoreFolderTable *) folderTable
|
|
|
|
{
|
|
|
|
return [MAPIStoreFSFolderTable tableForContainer: self];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
NSString *newKey, *urlString;
|
2011-07-08 22:02:02 +02:00
|
|
|
NSURL *childURL;
|
2011-06-07 02:17:46 +02:00
|
|
|
SOGoMAPIFSFolder *childFolder;
|
|
|
|
|
|
|
|
newKey = [NSString stringWithFormat: @"0x%.16"PRIx64, (unsigned long long) newFID];
|
|
|
|
|
|
|
|
urlString = [NSString stringWithFormat: @"%@/%@", [self url], newKey];
|
2011-07-08 22:02:02 +02:00
|
|
|
childURL = [NSURL URLWithString: [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
|
|
|
|
childFolder = [SOGoMAPIFSFolder folderWithURL: childURL
|
2011-06-07 02:17:46 +02:00
|
|
|
andTableType: MAPISTORE_MESSAGE_TABLE];
|
|
|
|
[childFolder ensureDirectory];
|
2012-02-03 16:05:19 +01:00
|
|
|
*newKeyP = newKey;
|
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;
|
|
|
|
SOGoMAPIFSMessage *fsObject;
|
|
|
|
NSString *newKey;
|
|
|
|
|
|
|
|
newKey = [NSString stringWithFormat: @"%@.plist",
|
|
|
|
[SOGoObject globallyUniqueObjectId]];
|
2011-12-01 23:42:30 +01:00
|
|
|
fsObject = [SOGoMAPIFSMessage objectWithName: newKey
|
|
|
|
inContainer: sogoObject];
|
2011-02-24 21:32:27 +01:00
|
|
|
newMessage = [MAPIStoreFSMessage mapiStoreObjectWithSOGoObject: fsObject
|
|
|
|
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])
|
|
|
|
keys = [(SOGoMAPIFSFolder *) sogoObject
|
|
|
|
toOneRelationshipKeysMatchingQualifier: qualifier
|
|
|
|
andSortOrderings: sortOrderings];
|
|
|
|
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
|
|
|
|
{
|
|
|
|
NSArray *entries;
|
|
|
|
NSMutableArray *filteredEntries;
|
|
|
|
NSUInteger count, max;
|
|
|
|
MAPIStoreFSFolder *subfolder;
|
|
|
|
SOGoMAPIFSMessage *propertiesMessage;
|
|
|
|
NSString *subfolderKey;
|
|
|
|
|
|
|
|
entries = [(SOGoMAPIFSFolder *) sogoObject toManyRelationshipKeys];
|
|
|
|
if (qualifier)
|
|
|
|
{
|
|
|
|
max = [entries count];
|
|
|
|
filteredEntries = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
subfolderKey = [entries objectAtIndex: count];
|
|
|
|
subfolder = [self lookupFolder: subfolderKey];
|
|
|
|
propertiesMessage = [subfolder propertiesMessage];
|
2011-10-27 01:52:55 +02:00
|
|
|
if ([qualifier evaluateMAPIVolatileMessage: propertiesMessage])
|
2011-08-12 00:56:04 +02:00
|
|
|
[filteredEntries addObject: subfolderKey];
|
|
|
|
}
|
|
|
|
entries = filteredEntries;
|
|
|
|
}
|
|
|
|
if (sortOrderings)
|
|
|
|
[self errorWithFormat: @"sort orderings are not used for folders"];
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
- (NSDate *) lastMessageModificationTime
|
|
|
|
{
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSDate *date, *fileDate;
|
|
|
|
MAPIStoreFSMessage *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
|
|
|
|
{
|
|
|
|
return propsFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|