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-10-27 01:52:55 +02:00
|
|
|
#import "EOQualifier+MAPI.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"
|
2011-02-24 21:32:27 +01:00
|
|
|
#import "SOGoMAPIFSFolder.h"
|
|
|
|
#import "SOGoMAPIFSMessage.h"
|
|
|
|
|
|
|
|
#import "MAPIStoreFSFolder.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
|
|
|
// #include <mapistore/mapistore_errors.h>
|
|
|
|
// #include <libmapiproxy.h>
|
|
|
|
// #include <param.h>
|
|
|
|
|
2011-09-23 17:36:49 +02:00
|
|
|
static Class EOKeyValueQualifierK;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithURL: (NSURL *) newURL
|
|
|
|
inContext: (MAPIStoreContext *) newContext
|
|
|
|
{
|
|
|
|
if ((self = [super initWithURL: newURL
|
|
|
|
inContext: newContext]))
|
|
|
|
{
|
|
|
|
sogoObject = [SOGoMAPIFSFolder folderWithURL: newURL
|
|
|
|
andTableType: MAPISTORE_MESSAGE_TABLE];
|
|
|
|
[sogoObject retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:17:46 +02:00
|
|
|
- (NSString *) createFolder: (struct SRow *) aRow
|
|
|
|
withFID: (uint64_t) newFID
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
|
|
|
|
return newKey;
|
|
|
|
}
|
|
|
|
|
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-03-07 23:35:24 +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-07-27 23:59:37 +02:00
|
|
|
return [(SOGoMAPIFSFolder *) sogoObject
|
|
|
|
toOneRelationshipKeysMatchingQualifier: qualifier
|
|
|
|
andSortOrderings: sortOrderings];
|
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;
|
|
|
|
|
|
|
|
[self messageKeys];
|
|
|
|
|
|
|
|
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)
|
|
|
|
[roles addObject: @"RightsReadItems"];
|
|
|
|
if (rights & RightsCreateItems)
|
|
|
|
[roles addObject: @"RightsCreateItems"];
|
|
|
|
if (rights & RightsEditOwn)
|
|
|
|
[roles addObject: @"RightsEditOwn"];
|
|
|
|
if (rights & RightsDeleteOwn)
|
|
|
|
[roles addObject: @"RightsDeleteOwn"];
|
|
|
|
if (rights & RightsEditAll)
|
|
|
|
[roles addObject: @"RightsEditAll"];
|
|
|
|
if (rights & RightsDeleteAll)
|
|
|
|
[roles addObject: @"RightsDeleteAll"];
|
|
|
|
if (rights & RightsCreateSubfolders)
|
|
|
|
[roles addObject: @"RightsCreateSubfolders"];
|
|
|
|
if (rights & RightsFolderOwner)
|
|
|
|
[roles addObject: @"RightsFolderOwner"];
|
|
|
|
if (rights & RightsFolderContact)
|
|
|
|
[roles addObject: @"RightsFolderContact"];
|
|
|
|
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint32_t) exchangeRightsForRoles: (NSArray *) roles
|
|
|
|
{
|
|
|
|
uint32_t rights = 0;
|
|
|
|
|
|
|
|
if ([roles containsObject: @"RightsReadItems"])
|
|
|
|
rights |= RightsReadItems;
|
|
|
|
if ([roles containsObject: @"RightsCreateItems"])
|
|
|
|
rights |= RightsCreateItems;
|
|
|
|
if ([roles containsObject: @"RightsEditOwn"])
|
|
|
|
rights |= RightsEditOwn;
|
|
|
|
if ([roles containsObject: @"RightsDeleteOwn"])
|
|
|
|
rights |= RightsDeleteOwn;
|
|
|
|
if ([roles containsObject: @"RightsEditAll"])
|
|
|
|
rights |= RightsEditAll;
|
|
|
|
if ([roles containsObject: @"RightsDeleteAll"])
|
|
|
|
rights |= RightsDeleteAll;
|
|
|
|
if ([roles containsObject: @"RightsCreateSubfolders"])
|
|
|
|
rights |= RightsCreateSubfolders;
|
|
|
|
if ([roles containsObject: @"RightsFolderOwner"])
|
|
|
|
rights |= RightsFolderOwner;
|
|
|
|
if ([roles containsObject: @"RightsFolderContact"])
|
|
|
|
rights |= RightsFolderContact;
|
|
|
|
if (rights != 0)
|
|
|
|
rights |= RoleNone; /* actually "folder visible" */
|
|
|
|
|
|
|
|
return rights;
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:32:27 +01:00
|
|
|
@end
|