2010-10-01 22:35:29 +02:00
|
|
|
/* MAPIStoreContext.m - this file is part of SOGo
|
2010-10-01 20:54:30 +02:00
|
|
|
*
|
2010-10-01 22:35:29 +02:00
|
|
|
* Copyright (C) 2010 Inverse inc.
|
2010-10-01 20:54:30 +02:00
|
|
|
*
|
|
|
|
* 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
|
2010-10-18 14:57:31 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2010-10-01 20:54:30 +02: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
#import <Foundation/NSThread.h>
|
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
|
|
|
#import <SOGo/SOGoFolder.h>
|
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
|
|
|
#import <Mailer/SOGoMailFolder.h>
|
|
|
|
|
2010-10-13 23:40:50 +02:00
|
|
|
#import "NSArray+MAPIStore.h"
|
2010-11-06 00:27:08 +01:00
|
|
|
#import "NSDate+MAPIStore.h"
|
2010-10-13 23:40:50 +02:00
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
#import "MAPIApplication.h"
|
|
|
|
#import "MAPIStoreAuthenticator.h"
|
|
|
|
#import "MAPIStoreMapping.h"
|
|
|
|
|
|
|
|
#import "MAPIStoreContext.h"
|
|
|
|
|
|
|
|
#import "NSString+MAPIStore.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
|
|
|
#include <mapistore/mapistore_errors.h>
|
2010-10-12 23:40:54 +02:00
|
|
|
#include <libmapiproxy.h>
|
2010-10-01 20:54:30 +02:00
|
|
|
// #include <dlinklist.h>
|
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
// NSNullK = NSClassFromString (@"NSNull");
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
// SOGoMailAccountsK = NSClassFromString (@"SOGoMailAccounts");
|
|
|
|
// SOGoMailAccountK = NSClassFromString (@"SOGoMailAccount");
|
|
|
|
// SOGoMailFolderK = NSClassFromString (@"SOGoMailFolder");
|
|
|
|
// SOGoUserFolderK = NSClassFromString (@"SOGoUserFolder");
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-06 16:27:09 +02:00
|
|
|
uint8_t *
|
|
|
|
MAPIBoolValue (void *memCtx, BOOL value)
|
|
|
|
{
|
|
|
|
uint8_t *boolValue;
|
|
|
|
|
|
|
|
boolValue = talloc_zero (memCtx, uint8_t);
|
|
|
|
*boolValue = value;
|
|
|
|
|
|
|
|
return boolValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *
|
|
|
|
MAPILongValue (void *memCtx, uint32_t value)
|
|
|
|
{
|
|
|
|
uint32_t *longValue;
|
|
|
|
|
|
|
|
longValue = talloc_zero (memCtx, uint32_t);
|
|
|
|
*longValue = value;
|
|
|
|
|
|
|
|
return longValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t *
|
|
|
|
MAPILongLongValue (void *memCtx, uint64_t value)
|
|
|
|
{
|
|
|
|
uint64_t *llongValue;
|
|
|
|
|
|
|
|
llongValue = talloc_zero (memCtx, uint64_t);
|
|
|
|
*llongValue = value;
|
|
|
|
|
|
|
|
return llongValue;
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
static Class SOGoObjectK, SOGoMailAccountK, SOGoMailFolderK;
|
|
|
|
|
2010-11-06 00:27:08 +01:00
|
|
|
@interface NSObject (MAPIStoreProtocol)
|
|
|
|
|
|
|
|
+ (id) objectFromSPropValue: (struct SPropValue *) value;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@interface SOGoFolder (MAPIStoreProtocol)
|
|
|
|
|
|
|
|
- (BOOL) create;
|
|
|
|
- (NSException *) delete;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface SOGoObject (MAPIStoreProtocol)
|
|
|
|
|
|
|
|
- (NSString *) davContentLength;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-11-06 00:27:08 +01:00
|
|
|
@implementation NSObject (MAPIStoreProtocol)
|
|
|
|
|
|
|
|
+ (id) objectFromSPropValue: (struct SPropValue *) value
|
|
|
|
{
|
|
|
|
short int valueType;
|
|
|
|
id result;
|
|
|
|
|
|
|
|
valueType = (value->ulPropTag & 0xffff);
|
|
|
|
switch (valueType)
|
|
|
|
{
|
|
|
|
case PT_NULL:
|
|
|
|
result = [NSNull null];
|
|
|
|
break;
|
|
|
|
case PT_SHORT:
|
|
|
|
result = [NSNumber numberWithShort: value->value.i];
|
|
|
|
break;
|
|
|
|
case PT_LONG:
|
|
|
|
result = [NSNumber numberWithLong: value->value.l];
|
|
|
|
break;
|
|
|
|
case PT_BOOLEAN:
|
|
|
|
result = [NSNumber numberWithBool: value->value.b];
|
|
|
|
break;
|
|
|
|
case PT_DOUBLE:
|
|
|
|
result = [NSNumber numberWithDouble: value->value.dbl];
|
|
|
|
break;
|
|
|
|
case PT_UNICODE:
|
|
|
|
result = [NSString stringWithUTF8String: value->value.lpszW];
|
|
|
|
break;
|
|
|
|
case PT_STRING8:
|
|
|
|
result = [NSString stringWithUTF8String: value->value.lpszA];
|
|
|
|
break;
|
|
|
|
case PT_SYSTIME:
|
|
|
|
result = [NSDate dateFromFileTime: &(value->value.ft)];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// #define PT_UNSPECIFIED 0x0
|
|
|
|
// #define PT_I2 0x2
|
|
|
|
// #define PT_CURRENCY 0x6
|
|
|
|
// #define PT_APPTIME 0x7
|
|
|
|
// #define PT_ERROR 0xa
|
|
|
|
// #define PT_OBJECT 0xd
|
|
|
|
// #define PT_I8 0x14
|
|
|
|
// #define PT_CLSID 0x48
|
|
|
|
// #define PT_SVREID 0xFB
|
|
|
|
// #define PT_SRESTRICT 0xFD
|
|
|
|
// #define PT_ACTIONS 0xFE
|
|
|
|
// #define PT_BINARY 0x102
|
|
|
|
result = [NSNull null];
|
|
|
|
[self errorWithFormat: @"object type not handled: %d", valueType];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@implementation MAPIStoreContext : NSObject
|
|
|
|
|
|
|
|
/* sogo://username:password@{contacts,calendar,tasks,journal,notes,mail}/dossier/id */
|
|
|
|
|
|
|
|
static MAPIStoreMapping *mapping = nil;
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
SOGoObjectK = [SOGoObject class];
|
2010-10-01 22:35:29 +02:00
|
|
|
SOGoMailAccountK = NSClassFromString (@"SOGoMailAccount");
|
|
|
|
SOGoMailFolderK = NSClassFromString (@"SOGoMailFolder");
|
2010-10-15 19:24:09 +02:00
|
|
|
mapping = [MAPIStoreMapping sharedMapping];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (id) contextFromURI: (const char *) newUri
|
2010-10-13 23:40:50 +02:00
|
|
|
inMemCtx: (struct mapistore_context *) newMemCtx
|
2010-10-01 20:54:30 +02:00
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
MAPIStoreContext *context;
|
|
|
|
MAPIStoreAuthenticator *authenticator;
|
|
|
|
NSString *contextClass, *module, *completeURLString, *urlString;
|
|
|
|
NSURL *baseURL;
|
|
|
|
|
|
|
|
NSLog (@"METHOD '%s' (%d) -- uri: '%s'", __FUNCTION__, __LINE__, newUri);
|
|
|
|
|
|
|
|
context = nil;
|
|
|
|
|
|
|
|
urlString = [NSString stringWithUTF8String: newUri];
|
|
|
|
if (urlString)
|
|
|
|
{
|
|
|
|
completeURLString = [@"sogo://" stringByAppendingString: urlString];
|
|
|
|
baseURL = [NSURL URLWithString: completeURLString];
|
|
|
|
if (baseURL)
|
|
|
|
{
|
|
|
|
module = [baseURL host];
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
if ([module isEqualToString: @"mail"])
|
|
|
|
contextClass = @"MAPIStoreMailContext";
|
|
|
|
else if ([module isEqualToString: @"contacts"])
|
|
|
|
contextClass = @"MAPIStoreContactsContext";
|
|
|
|
else if ([module isEqualToString: @"calendar"])
|
|
|
|
contextClass = @"MAPIStoreCalendarContext";
|
2010-10-01 23:31:58 +02:00
|
|
|
else if ([module isEqualToString: @"tasks"])
|
|
|
|
contextClass = @"MAPIStoreTasksContext";
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog (@"ERROR: unrecognized module name '%@'", module);
|
|
|
|
contextClass = nil;
|
|
|
|
}
|
2010-10-12 23:40:54 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
if (contextClass)
|
|
|
|
{
|
|
|
|
context = [NSClassFromString (contextClass) new];
|
2010-10-13 23:40:50 +02:00
|
|
|
[context setURI: completeURLString andMemCtx: newMemCtx];
|
2010-10-01 22:35:29 +02:00
|
|
|
[context autorelease];
|
|
|
|
|
|
|
|
authenticator = [MAPIStoreAuthenticator new];
|
|
|
|
[authenticator setUsername: [baseURL user]];
|
|
|
|
[authenticator setPassword: [baseURL password]];
|
|
|
|
[context setAuthenticator: authenticator];
|
|
|
|
[authenticator release];
|
|
|
|
|
|
|
|
[context setupRequest];
|
|
|
|
[context setupModuleFolder];
|
|
|
|
[context tearDownRequest];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
NSLog (@"ERROR: url could not be parsed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NSLog (@"ERROR: url is an invalid UTF-8 string");
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return context;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
messageCache = [NSMutableDictionary new];
|
|
|
|
subfolderCache = [NSMutableDictionary new];
|
2010-11-06 00:27:08 +01:00
|
|
|
messages = [NSMutableDictionary new];
|
2010-10-01 22:35:29 +02:00
|
|
|
woContext = [WOContext contextWithRequest: nil];
|
|
|
|
[woContext retain];
|
2010-11-06 00:27:08 +01:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
moduleFolder = nil;
|
2010-10-13 23:40:50 +02:00
|
|
|
uri = nil;
|
|
|
|
baseContextSet = NO;
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"-init"];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return self;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2010-10-14 23:37:39 +02:00
|
|
|
[self logWithFormat: @"-dealloc: %@", self];
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
[messageCache release];
|
|
|
|
[subfolderCache release];
|
2010-11-06 00:27:08 +01:00
|
|
|
[messages release];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
[moduleFolder release];
|
|
|
|
[woContext release];
|
|
|
|
[authenticator release];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-13 23:40:50 +02:00
|
|
|
[uri release];
|
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
[super dealloc];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 23:40:50 +02:00
|
|
|
- (void) setURI: (NSString *) newUri
|
|
|
|
andMemCtx: (struct mapistore_context *) newMemCtx
|
|
|
|
{
|
|
|
|
struct loadparm_context *lpCtx;
|
|
|
|
|
|
|
|
ASSIGN (uri, newUri);
|
|
|
|
memCtx = newMemCtx;
|
|
|
|
|
|
|
|
lpCtx = loadparm_init (newMemCtx);
|
|
|
|
ldbCtx = mapiproxy_server_openchange_ldb_init (lpCtx);
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (void) setAuthenticator: (MAPIStoreAuthenticator *) newAuthenticator
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
ASSIGN (authenticator, newAuthenticator);
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreAuthenticator *) authenticator
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
return authenticator;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setupRequest
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSMutableDictionary *info;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
[MAPIApp setMAPIStoreContext: self];
|
|
|
|
info = [[NSThread currentThread] threadDictionary];
|
|
|
|
[info setObject: woContext forKey:@"WOContext"];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tearDownRequest
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSMutableDictionary *info;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
info = [[NSThread currentThread] threadDictionary];
|
|
|
|
[info removeObjectForKey:@"WOContext"];
|
|
|
|
[MAPIApp setMAPIStoreContext: nil];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setupModuleFolder
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self subclassResponsibility: _cmd];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
// - (void) _setNewLastObject: (id) newLastObject
|
|
|
|
// {
|
|
|
|
// id currentObject, container;
|
|
|
|
|
|
|
|
// if (newLastObject != lastObject)
|
|
|
|
// {
|
|
|
|
// currentObject = lastObject;
|
|
|
|
// while (currentObject)
|
|
|
|
// {
|
|
|
|
// container = [currentObject container];
|
|
|
|
// [currentObject release];
|
|
|
|
// currentObject = container;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// currentObject = newLastObject;
|
|
|
|
// while (currentObject)
|
|
|
|
// {
|
|
|
|
// [currentObject retain];
|
|
|
|
// currentObject = [currentObject container];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// lastObject = newLastObject;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (id) lookupObject: (NSString *) objectURLString
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
id object;
|
|
|
|
NSURL *objectURL;
|
|
|
|
NSArray *path;
|
|
|
|
int count, max;
|
|
|
|
NSString *pathString, *nameInContainer;
|
|
|
|
|
|
|
|
objectURL = [NSURL URLWithString: objectURLString];
|
2010-10-01 23:24:15 +02:00
|
|
|
if (objectURL)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-01 23:24:15 +02:00
|
|
|
object = moduleFolder;
|
|
|
|
|
|
|
|
pathString = [objectURL path];
|
|
|
|
if ([pathString hasPrefix: @"/"])
|
|
|
|
pathString = [pathString substringFromIndex: 1];
|
|
|
|
if ([pathString length] > 0)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-01 23:24:15 +02:00
|
|
|
path = [pathString componentsSeparatedByString: @"/"];
|
|
|
|
max = [path count];
|
|
|
|
if (max > 0)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-01 23:24:15 +02:00
|
|
|
for (count = 0;
|
|
|
|
object && count < max;
|
|
|
|
count++)
|
|
|
|
{
|
|
|
|
nameInContainer = [[path objectAtIndex: count]
|
2010-10-01 22:35:29 +02:00
|
|
|
stringByUnescapingURL];
|
2010-10-01 23:24:15 +02:00
|
|
|
object = [object lookupName: nameInContainer
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
|
|
|
if ([object isKindOfClass: SOGoObjectK])
|
|
|
|
[woContext setClientObject: object];
|
|
|
|
else
|
|
|
|
object = nil;
|
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-01 23:24:15 +02:00
|
|
|
else
|
|
|
|
object = nil;
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
// [self _setNewLastObject: object];
|
|
|
|
// ASSIGN (lastObjectURL, objectURLString);
|
2010-10-01 23:24:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
object = nil;
|
|
|
|
[self errorWithFormat: @"url string gave nil NSURL: '%@'", objectURLString];
|
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
[woContext setClientObject: object];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return object;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _createFolder: (struct SRow *) aRow
|
|
|
|
inParentURL: (NSString *) parentFolderURL
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSString *newFolderURL;
|
|
|
|
NSString *folderName, *nameInContainer;
|
|
|
|
SOGoFolder *parentFolder, *newFolder;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
newFolderURL = nil;
|
|
|
|
|
|
|
|
folderName = nil;
|
|
|
|
for (i = 0; !folderName && i < aRow->cValues; i++)
|
|
|
|
{
|
|
|
|
if (aRow->lpProps[i].ulPropTag == PR_DISPLAY_NAME_UNICODE)
|
|
|
|
folderName = [NSString stringWithUTF8String: aRow->lpProps[i].value.lpszW];
|
|
|
|
else if (aRow->lpProps[i].ulPropTag == PR_DISPLAY_NAME)
|
|
|
|
folderName = [NSString stringWithUTF8String: aRow->lpProps[i].value.lpszA];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folderName)
|
|
|
|
{
|
|
|
|
parentFolder = [self lookupObject: parentFolderURL];
|
|
|
|
if (parentFolder)
|
|
|
|
{
|
|
|
|
if ([parentFolder isKindOfClass: SOGoMailAccountK]
|
|
|
|
|| [parentFolder isKindOfClass: SOGoMailFolderK])
|
|
|
|
{
|
|
|
|
nameInContainer = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[folderName asCSSIdentifier]];
|
|
|
|
newFolder = [SOGoMailFolderK objectWithName: nameInContainer
|
|
|
|
inContainer: parentFolder];
|
|
|
|
if ([newFolder create])
|
|
|
|
newFolderURL = [NSString stringWithFormat: @"%@/%@",
|
|
|
|
parentFolderURL,
|
|
|
|
[nameInContainer stringByEscapingURL]];
|
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return newFolderURL;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\details Create a folder in the sogo backend
|
|
|
|
|
|
|
|
\param private_data pointer to the current sogo context
|
|
|
|
|
|
|
|
\return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
|
2010-10-01 22:35:29 +02:00
|
|
|
*/
|
2010-10-01 20:54:30 +02:00
|
|
|
|
|
|
|
- (int) mkDir: (struct SRow *) aRow
|
|
|
|
withFID: (uint64_t) fid
|
|
|
|
inParentFID: (uint64_t) parentFID
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSString *folderURL, *parentFolderURL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
|
|
|
|
|
|
|
folderURL = [mapping urlFromID: fid];
|
|
|
|
if (folderURL)
|
|
|
|
rc = MAPISTORE_ERR_EXIST;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parentFolderURL = [mapping urlFromID: parentFID];
|
|
|
|
if (!parentFolderURL)
|
|
|
|
[self errorWithFormat: @"No url found for FID: %lld", parentFID];
|
2010-10-13 23:40:50 +02:00
|
|
|
if (parentFolderURL)
|
|
|
|
{
|
|
|
|
folderURL = [self _createFolder: aRow inParentURL: parentFolderURL];
|
|
|
|
if (folderURL)
|
|
|
|
{
|
|
|
|
[mapping registerURL: folderURL withID: fid];
|
|
|
|
// if ([sogoFolder isKindOfClass: SOGoMailAccountK])
|
|
|
|
// [sogoFolder subscribe];
|
|
|
|
rc = MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERR_NO_DIRECTORY;
|
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\details Delete a folder from the sogo backend
|
|
|
|
|
|
|
|
\param private_data pointer to the current sogo context
|
|
|
|
\param parentFID the FID for the parent of the folder to delete
|
|
|
|
\param fid the FID for the folder to delete
|
|
|
|
|
|
|
|
\return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
|
2010-10-01 22:35:29 +02:00
|
|
|
*/
|
2010-10-01 20:54:30 +02:00
|
|
|
- (int) rmDirWithFID: (uint64_t) fid
|
|
|
|
inParentFID: (uint64_t) parentFid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 23:37:39 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\details Open a folder from the sogo backend
|
|
|
|
|
|
|
|
\param private_data pointer to the current sogo context
|
|
|
|
\param parentFID the parent folder identifier
|
|
|
|
\param fid the identifier of the colder to open
|
|
|
|
|
|
|
|
\return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
|
2010-10-01 22:35:29 +02:00
|
|
|
*/
|
2010-10-01 20:54:30 +02:00
|
|
|
- (int) openDir: (uint64_t) fid
|
|
|
|
inParentFID: (uint64_t) parentFID
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 23:37:39 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\details Close a folder from the sogo backend
|
|
|
|
|
|
|
|
\param private_data pointer to the current sogo context
|
|
|
|
|
|
|
|
\return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
|
2010-10-01 22:35:29 +02:00
|
|
|
*/
|
2010-10-01 20:54:30 +02:00
|
|
|
- (int) closeDir
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return MAPISTORE_SUCCESS;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _messageKeysForFolderURL: (NSString *) folderURL
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSArray *keys;
|
|
|
|
SOGoFolder *folder;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
keys = [messageCache objectForKey: folderURL];
|
|
|
|
if (!keys)
|
|
|
|
{
|
|
|
|
folder = [self lookupObject: folderURL];
|
|
|
|
if (folder)
|
2010-10-01 23:24:15 +02:00
|
|
|
keys = [self getFolderMessageKeys: folder];
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
keys = (NSArray *) [NSNull null];
|
|
|
|
[messageCache setObject: keys forKey: folderURL];
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 23:24:15 +02:00
|
|
|
- (NSArray *) getFolderMessageKeys: (SOGoFolder *) folder
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return (NSArray *) [NSNull null];
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (NSArray *) _subfolderKeysForFolderURL: (NSString *) folderURL
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSArray *keys;
|
|
|
|
SOGoFolder *folder;
|
|
|
|
|
|
|
|
keys = [subfolderCache objectForKey: folderURL];
|
|
|
|
if (!keys)
|
|
|
|
{
|
|
|
|
folder = [self lookupObject: folderURL];
|
|
|
|
if (folder)
|
|
|
|
{
|
|
|
|
keys = [folder toManyRelationshipKeys];
|
|
|
|
if (!keys)
|
|
|
|
keys = (NSArray *) [NSNull null];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
keys = (NSArray *) [NSNull null];
|
|
|
|
[subfolderCache setObject: keys forKey: folderURL];
|
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return keys;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\details Read directory content from the sogo backend
|
|
|
|
|
|
|
|
\param private_data pointer to the current sogo context
|
|
|
|
|
|
|
|
\return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
|
2010-10-01 22:35:29 +02:00
|
|
|
*/
|
2010-10-01 20:54:30 +02:00
|
|
|
- (int) readCount: (uint32_t *) rowCount
|
|
|
|
ofTableType: (uint8_t) tableType
|
|
|
|
inFID: (uint64_t) fid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSArray *ids;
|
|
|
|
NSString *url;
|
|
|
|
int rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
url = [mapping urlFromID: fid];
|
2010-10-14 23:37:39 +02:00
|
|
|
if (url)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-14 23:37:39 +02:00
|
|
|
switch (tableType)
|
|
|
|
{
|
|
|
|
case MAPISTORE_FOLDER_TABLE:
|
|
|
|
ids = [self _subfolderKeysForFolderURL: url];
|
|
|
|
break;
|
|
|
|
case MAPISTORE_MESSAGE_TABLE:
|
|
|
|
ids = [self _messageKeysForFolderURL: url];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = MAPISTORE_ERR_INVALID_PARAMETER;
|
|
|
|
ids = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([ids isKindOfClass: [NSArray class]])
|
|
|
|
{
|
|
|
|
rc = MAPI_E_SUCCESS;
|
|
|
|
*rowCount = [ids count];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERR_NO_DIRECTORY;
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-14 23:37:39 +02:00
|
|
|
else
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-14 23:37:39 +02:00
|
|
|
[self errorWithFormat: @"No url found for FID: %lld", fid];
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getCommonTableChildproperty: (void **) data
|
|
|
|
atURL: (NSString *) childURL
|
|
|
|
withTag: (uint32_t) proptag
|
|
|
|
inFolder: (SOGoFolder *) folder
|
|
|
|
withFID: (uint64_t) fid
|
|
|
|
{
|
2010-10-15 19:24:09 +02:00
|
|
|
// NSString *stringValue;
|
2010-10-01 22:35:29 +02:00
|
|
|
id child;
|
|
|
|
// uint64_t *llongValue;
|
|
|
|
// uint32_t *longValue;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = MAPI_E_SUCCESS;
|
|
|
|
switch (proptag)
|
|
|
|
{
|
|
|
|
case PR_DISPLAY_NAME_UNICODE:
|
|
|
|
child = [self lookupObject: childURL];
|
|
|
|
*data = [[child displayName] asUnicodeInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
default:
|
2010-10-15 19:24:09 +02:00
|
|
|
// *data = NULL;
|
2010-10-05 15:56:43 +02:00
|
|
|
rc = MAPI_E_NOT_FOUND;
|
2010-10-15 19:24:09 +02:00
|
|
|
// if ((proptag & 0x001F) == 0x001F)
|
|
|
|
// {
|
|
|
|
// stringValue = [NSString stringWithFormat: @"Unhandled unicode value: 0x%x", proptag];
|
|
|
|
// *data = [stringValue asUnicodeInMemCtx: memCtx];
|
|
|
|
// rc = MAPI_E_SUCCESS;
|
2010-10-01 22:35:29 +02:00
|
|
|
[self errorWithFormat: @"Unknown proptag (returned): %.8x for child '%@'",
|
|
|
|
proptag, childURL];
|
2010-10-15 19:24:09 +02:00
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// [self errorWithFormat: @"Unknown proptag: %.8x for child '%@'",
|
|
|
|
// proptag, childURL];
|
2010-10-05 15:56:43 +02:00
|
|
|
// *data = NULL;
|
2010-10-15 19:24:09 +02:00
|
|
|
rc = MAPI_E_NOT_FOUND;
|
|
|
|
break;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getMessageTableChildproperty: (void **) data
|
|
|
|
atURL: (NSString *) childURL
|
|
|
|
withTag: (uint32_t) proptag
|
|
|
|
inFolder: (SOGoFolder *) folder
|
|
|
|
withFID: (uint64_t) fid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
int rc;
|
2010-10-12 23:40:54 +02:00
|
|
|
uint32_t contextId;
|
|
|
|
uint64_t mappingId;
|
2010-10-13 23:40:50 +02:00
|
|
|
NSString *folderURL;
|
2010-10-12 23:40:54 +02:00
|
|
|
id child;
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
rc = MAPI_E_SUCCESS;
|
|
|
|
switch (proptag)
|
|
|
|
{
|
|
|
|
case PR_INST_ID: // TODO: DOUBT
|
2010-10-06 16:27:09 +02:00
|
|
|
/* we return a unique id based on the url */
|
|
|
|
*data = MAPILongLongValue (memCtx, [childURL hash]);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
2010-10-12 23:40:54 +02:00
|
|
|
case PR_INSTANCE_NUM: // TODO: DOUBT
|
|
|
|
*data = MAPILongValue (memCtx, 0);
|
2010-10-06 15:59:49 +02:00
|
|
|
break;
|
|
|
|
case PR_ROW_TYPE: // TODO: DOUBT
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPILongValue (memCtx, TBL_LEAF_ROW);
|
2010-10-06 15:59:49 +02:00
|
|
|
break;
|
2010-10-12 23:40:54 +02:00
|
|
|
case PR_DEPTH: // TODO: DOUBT
|
|
|
|
*data = MAPILongLongValue (memCtx, 0);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
2010-10-14 23:37:39 +02:00
|
|
|
case PR_ACCESS: // TODO
|
|
|
|
*data = MAPILongValue (memCtx, 0x02);
|
|
|
|
break;
|
|
|
|
case PR_ACCESS_LEVEL: // TODO
|
|
|
|
*data = MAPILongValue (memCtx, 0x00000000);
|
|
|
|
break;
|
2010-10-01 22:35:29 +02:00
|
|
|
case PR_VD_VERSION:
|
2010-10-06 16:27:09 +02:00
|
|
|
/* mandatory value... wtf? */
|
|
|
|
*data = MAPILongValue (memCtx, 8);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_FID:
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPILongLongValue (memCtx, fid);
|
2010-10-13 17:45:18 +02:00
|
|
|
break;
|
2010-10-01 22:35:29 +02:00
|
|
|
case PR_MID:
|
2010-10-06 16:27:09 +02:00
|
|
|
mappingId = [mapping idFromURL: childURL];
|
|
|
|
if (mappingId == NSNotFound)
|
|
|
|
{
|
2010-10-12 23:40:54 +02:00
|
|
|
openchangedb_get_new_folderID (ldbCtx, &mappingId);
|
|
|
|
[mapping registerURL: childURL withID: mappingId];
|
2010-10-13 23:40:50 +02:00
|
|
|
folderURL = [mapping urlFromID: fid];
|
|
|
|
NSAssert (folderURL != nil,
|
|
|
|
@"folder URL is expected to be known here");
|
|
|
|
contextId = 0;
|
|
|
|
mapistore_search_context_by_uri (memCtx, [uri UTF8String] + 7,
|
2010-10-13 17:55:21 +02:00
|
|
|
&contextId);
|
2010-10-13 23:40:50 +02:00
|
|
|
NSAssert (contextId > 0, @"no matching context found");
|
2010-10-12 23:40:54 +02:00
|
|
|
mapistore_indexing_record_add_mid (memCtx, contextId, mappingId);
|
2010-10-06 16:27:09 +02:00
|
|
|
}
|
|
|
|
*data = MAPILongLongValue (memCtx, mappingId);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
2010-10-12 23:40:54 +02:00
|
|
|
case PR_MESSAGE_CODEPAGE:
|
|
|
|
*data = MAPILongValue (memCtx, 0x0000); // use folder object codepage
|
|
|
|
break;
|
|
|
|
case PR_MESSAGE_LOCALE_ID:
|
|
|
|
*data = MAPILongValue (memCtx, 0x0409);
|
|
|
|
break;
|
|
|
|
case PR_MESSAGE_FLAGS: // TODO
|
|
|
|
*data = MAPILongValue (memCtx, 0x02 | 0x20); // fromme + unmodified
|
|
|
|
break;
|
|
|
|
case PR_MESSAGE_SIZE: // TODO
|
|
|
|
child = [self lookupObject: childURL];
|
|
|
|
/* TODO: choose another name in SOGo for that method */
|
|
|
|
*data = MAPILongValue (memCtx, [[child davContentLength] intValue]);
|
|
|
|
break;
|
|
|
|
case PR_MSG_STATUS: // TODO
|
|
|
|
*data = MAPILongValue (memCtx, 0);
|
|
|
|
break;
|
|
|
|
case PR_SUBJECT_PREFIX_UNICODE: // TODO
|
|
|
|
*data = [@"" asUnicodeInMemCtx: memCtx];
|
|
|
|
break;
|
|
|
|
case PR_IMPORTANCE: // TODO -> subclass?
|
|
|
|
*data = MAPILongValue (memCtx, 1);
|
|
|
|
break;
|
|
|
|
case PR_PRIORITY: // TODO -> subclass?
|
|
|
|
*data = MAPILongValue (memCtx, 0);
|
|
|
|
break;
|
|
|
|
case PR_SENSITIVITY: // TODO -> subclass in calendar
|
|
|
|
*data = MAPILongValue (memCtx, 0);
|
|
|
|
break;
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
/* those are queried while they really pertain to the
|
|
|
|
addressbook module */
|
|
|
|
// #define PR_OAB_LANGID PROP_TAG(PT_LONG , 0x6807) /* 0x68070003 */
|
|
|
|
// case PR_OAB_NAME_UNICODE:
|
|
|
|
// case PR_OAB_CONTAINER_GUID_UNICODE:
|
|
|
|
|
|
|
|
// 0x68420102 PidTagScheduleInfoDelegatorWantsCopy (BOOL)
|
|
|
|
|
|
|
|
default:
|
|
|
|
rc = [self getCommonTableChildproperty: data
|
|
|
|
atURL: childURL
|
|
|
|
withTag: proptag
|
|
|
|
inFolder: folder
|
|
|
|
withFID: fid];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _parentURLFromURL: (NSString *) urlString
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSString *newURL;
|
|
|
|
NSArray *parts;
|
|
|
|
NSMutableArray *newParts;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
parts = [urlString componentsSeparatedByString: @"/"];
|
|
|
|
if ([parts count] > 3)
|
|
|
|
{
|
|
|
|
newParts = [parts mutableCopy];
|
|
|
|
[newParts autorelease];
|
|
|
|
[newParts removeLastObject];
|
|
|
|
newURL = [newParts componentsJoinedByString: @"/"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newURL = nil;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return newURL;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getFolderTableChildproperty: (void **) data
|
|
|
|
atURL: (NSString *) childURL
|
|
|
|
withTag: (uint32_t) proptag
|
|
|
|
inFolder: (SOGoFolder *) folder
|
|
|
|
withFID: (uint64_t) fid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
// id child;
|
|
|
|
struct Binary_r *binaryValue;
|
2010-10-12 23:40:54 +02:00
|
|
|
uint32_t contextId;
|
|
|
|
uint64_t mappingId;
|
2010-10-01 22:35:29 +02:00
|
|
|
int rc;
|
2010-10-13 23:40:50 +02:00
|
|
|
NSString *folderURL;
|
2010-10-01 22:35:29 +02:00
|
|
|
|
|
|
|
rc = MAPI_E_SUCCESS;
|
|
|
|
switch (proptag)
|
|
|
|
{
|
|
|
|
case PR_FID:
|
2010-10-12 23:40:54 +02:00
|
|
|
mappingId = [mapping idFromURL: childURL];
|
|
|
|
if (mappingId == NSNotFound)
|
|
|
|
{
|
|
|
|
openchangedb_get_new_folderID (ldbCtx, &mappingId);
|
|
|
|
[mapping registerURL: childURL withID: mappingId];
|
2010-10-13 23:40:50 +02:00
|
|
|
folderURL = [mapping urlFromID: fid];
|
|
|
|
NSAssert (folderURL != nil,
|
|
|
|
@"folder URL is expected to be known here");
|
|
|
|
contextId = 0;
|
|
|
|
mapistore_search_context_by_uri (memCtx, [uri UTF8String] + 7,
|
2010-10-13 17:55:21 +02:00
|
|
|
&contextId);
|
2010-10-13 23:40:50 +02:00
|
|
|
NSAssert (contextId > 0, @"no matching context found");
|
2010-10-12 23:40:54 +02:00
|
|
|
mapistore_indexing_record_add_fid (memCtx, contextId, mappingId);
|
|
|
|
}
|
|
|
|
// mappingId = [mapping idFromURL: childURL];
|
|
|
|
// }
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPILongLongValue (memCtx, mappingId);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_PARENT_FID:
|
2010-10-13 23:40:50 +02:00
|
|
|
*data = MAPILongLongValue (memCtx, fid);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_ATTR_HIDDEN:
|
|
|
|
case PR_ATTR_SYSTEM:
|
|
|
|
case PR_ATTR_READONLY:
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPIBoolValue (memCtx, NO);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_SUBFOLDERS:
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPIBoolValue (memCtx,
|
|
|
|
[[self _subfolderKeysForFolderURL: childURL]
|
|
|
|
count] > 0);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_CONTENT_COUNT:
|
2010-10-06 16:27:09 +02:00
|
|
|
*data = MAPILongValue (memCtx,
|
|
|
|
[[self _messageKeysForFolderURL: childURL]
|
|
|
|
count]);
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case PR_EXTENDED_FOLDER_FLAGS: // TODO: DOUBT: how to indicate the
|
|
|
|
// number of subresponses ?
|
|
|
|
binaryValue = talloc_zero(memCtx, struct Binary_r);
|
|
|
|
*data = binaryValue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = [self getCommonTableChildproperty: data
|
|
|
|
atURL: childURL
|
|
|
|
withTag: proptag
|
|
|
|
inFolder: folder
|
|
|
|
withFID: fid];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getTableProperty: (void **) data
|
|
|
|
withTag: (uint32_t) proptag
|
|
|
|
atPosition: (uint32_t) pos
|
|
|
|
withTableType: (uint8_t) tableType
|
|
|
|
inFID: (uint64_t) fid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
NSArray *children;
|
|
|
|
NSString *folderURL, *childURL, *childName;
|
|
|
|
SOGoFolder *folder;
|
|
|
|
int rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-12 23:40:54 +02:00
|
|
|
// [self logWithFormat: @"METHOD '%s' (%d) -- proptag: 0x%.8x, pos: %ld, tableType: %d, fid: %lld",
|
|
|
|
// __FUNCTION__, __LINE__, proptag, pos, tableType, fid];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
folderURL = [mapping urlFromID: fid];
|
|
|
|
if (folderURL)
|
|
|
|
{
|
|
|
|
folder = [self lookupObject: folderURL];
|
|
|
|
switch (tableType)
|
|
|
|
{
|
|
|
|
case MAPISTORE_FOLDER_TABLE:
|
|
|
|
children = [self _subfolderKeysForFolderURL: folderURL];
|
|
|
|
break;
|
|
|
|
case MAPISTORE_MESSAGE_TABLE:
|
|
|
|
children = [self _messageKeysForFolderURL: folderURL];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
children = nil;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
if ([children count] > pos)
|
|
|
|
{
|
|
|
|
childName = [children objectAtIndex: pos];
|
|
|
|
childURL = [folderURL stringByAppendingFormat: @"/%@",
|
|
|
|
[childName stringByEscapingURL]];
|
|
|
|
|
|
|
|
if (tableType == MAPISTORE_FOLDER_TABLE)
|
|
|
|
{
|
|
|
|
[self logWithFormat: @" querying child folder at URL: %@", childURL];
|
|
|
|
rc = [self getFolderTableChildproperty: data
|
|
|
|
atURL: childURL
|
|
|
|
withTag: proptag
|
|
|
|
inFolder: folder
|
|
|
|
withFID: fid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-12 23:40:54 +02:00
|
|
|
// [self logWithFormat: @" querying child message at URL: %@", childURL];
|
2010-10-01 22:35:29 +02:00
|
|
|
rc = [self getMessageTableChildproperty: data
|
|
|
|
atURL: childURL
|
|
|
|
withTag: proptag
|
|
|
|
inFolder: folder
|
|
|
|
withFID: fid];
|
|
|
|
}
|
|
|
|
/* Unhandled: */
|
|
|
|
// #define PR_EXPIRY_TIME PROP_TAG(PT_SYSTIME , 0x0015) /* 0x00150040 */
|
|
|
|
// #define PR_REPLY_TIME PROP_TAG(PT_SYSTIME , 0x0030) /* 0x00300040 */
|
|
|
|
// #define PR_SENSITIVITY PROP_TAG(PT_LONG , 0x0036) /* 0x00360003 */
|
|
|
|
// #define PR_MESSAGE_DELIVERY_TIME PROP_TAG(PT_SYSTIME , 0x0e06) /* 0x0e060040 */
|
|
|
|
// #define PR_FOLLOWUP_ICON PROP_TAG(PT_LONG , 0x1095) /* 0x10950003 */
|
|
|
|
// #define PR_ITEM_TEMPORARY_FLAGS PROP_TAG(PT_LONG , 0x1097) /* 0x10970003 */
|
|
|
|
// #define PR_SEARCH_KEY PROP_TAG(PT_BINARY , 0x300b) /* 0x300b0102 */
|
|
|
|
// #define PR_CONTENT_COUNT PROP_TAG(PT_LONG , 0x3602) /* 0x36020003 */
|
|
|
|
// #define PR_CONTENT_UNREAD PROP_TAG(PT_LONG , 0x3603) /* 0x36030003 */
|
|
|
|
// #define PR_FID PROP_TAG(PT_I8 , 0x6748) /* 0x67480014 */
|
|
|
|
// unknown 36de0003 http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/17c68add-1f62-4b68-9d83-f9ec7c1c6c9b
|
|
|
|
// unknown 819d0003
|
|
|
|
// unknown 81f80003
|
|
|
|
// unknown 81fa000b
|
2010-10-01 20:54:30 +02:00
|
|
|
|
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"No url found for FID: %lld", fid];
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) openMessage: (struct mapistore_message *) msg
|
|
|
|
withMID: (uint64_t) mid
|
|
|
|
inFID: (uint64_t) fid
|
2010-10-14 15:22:26 +02:00
|
|
|
{
|
|
|
|
NSString *childURL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
childURL = [mapping urlFromID: mid];
|
|
|
|
if (childURL)
|
|
|
|
{
|
|
|
|
rc = [self openMessage: msg atURL: childURL];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) openMessage: (struct mapistore_message *) msg
|
|
|
|
atURL: (NSString *) childURL
|
2010-10-01 20:54:30 +02:00
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) createMessageWithMID: (uint64_t) mid
|
|
|
|
inFID: (uint64_t) fid
|
|
|
|
{
|
2010-11-06 00:27:08 +01:00
|
|
|
NSMutableDictionary *newMessage;
|
|
|
|
NSNumber *midNbr;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-11-06 00:27:08 +01:00
|
|
|
newMessage = [NSMutableDictionary new];
|
|
|
|
[newMessage setObject: [NSNumber numberWithUnsignedLongLong: fid]
|
|
|
|
forKey: @"fid"];
|
|
|
|
midNbr = [NSNumber numberWithUnsignedLongLong: mid];
|
|
|
|
[newMessage setObject: midNbr forKey: @"fid"];
|
|
|
|
[messages setObject: newMessage forKey: midNbr];
|
|
|
|
[newMessage release];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) saveChangesInMessageWithMID: (uint64_t) mid
|
|
|
|
andFlags: (uint8_t) flags
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) submitMessageWithMID: (uint64_t) mid
|
|
|
|
andFlags: (uint8_t) flags
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 18:38:15 +02:00
|
|
|
- (int) getProperties: (struct SPropTagArray *) sPropTagArray
|
2010-10-01 20:54:30 +02:00
|
|
|
inRow: (struct SRow *) aRow
|
|
|
|
withMID: (uint64_t) fmid
|
|
|
|
type: (uint8_t) tableType
|
|
|
|
{
|
2010-10-14 18:38:15 +02:00
|
|
|
NSString *childURL;
|
|
|
|
int rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 18:38:15 +02:00
|
|
|
childURL = [mapping urlFromID: fmid];
|
|
|
|
if (childURL)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-10-14 18:38:15 +02:00
|
|
|
switch (tableType)
|
|
|
|
{
|
|
|
|
case MAPISTORE_MESSAGE:
|
|
|
|
rc = [self getMessageProperties: sPropTagArray inRow: aRow
|
|
|
|
atURL: childURL];
|
|
|
|
break;
|
|
|
|
case MAPISTORE_FOLDER:
|
|
|
|
default:
|
|
|
|
rc = MAPISTORE_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"No url found for FMID: %lld", fmid];
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 18:38:15 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getMessageProperties: (struct SPropTagArray *) sPropTagArray
|
|
|
|
inRow: (struct SRow *) aRow
|
|
|
|
atURL: (NSString *) childURL
|
|
|
|
{
|
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-15 19:24:09 +02:00
|
|
|
// struct indexing_context_list {
|
|
|
|
// struct tdb_wrap *index_ctx;
|
|
|
|
// char *username;
|
|
|
|
// uint32_t ref_count;
|
|
|
|
// struct indexing_context_list *prev;
|
|
|
|
// struct indexing_context_list *next;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// struct tdb_wrap {
|
|
|
|
// struct tdb_context *tdb;
|
|
|
|
// const char *name;
|
|
|
|
// struct tdb_wrap *prev;
|
|
|
|
// struct tdb_wrap *next;
|
|
|
|
// };
|
|
|
|
|
2010-10-13 23:40:50 +02:00
|
|
|
- (int) getPath: (char **) path
|
|
|
|
ofFMID: (uint64_t) fmid
|
|
|
|
withTableType: (uint8_t) tableType
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
NSString *objectURL;
|
2010-10-15 19:24:09 +02:00
|
|
|
// TDB_DATA key, dbuf;
|
2010-10-13 23:40:50 +02:00
|
|
|
|
|
|
|
objectURL = [mapping urlFromID: fmid];
|
|
|
|
if (objectURL)
|
|
|
|
{
|
2010-10-15 19:24:09 +02:00
|
|
|
if ([objectURL hasPrefix: uri])
|
|
|
|
{
|
|
|
|
*path = [[objectURL substringFromIndex: 7] asUnicodeInMemCtx: memCtx];
|
|
|
|
rc = MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* An id was found that is not part of this context...x */
|
|
|
|
*path = NULL;
|
|
|
|
rc = MAPI_E_NOT_FOUND;
|
|
|
|
}
|
2010-10-13 23:40:50 +02:00
|
|
|
}
|
|
|
|
else
|
2010-10-15 19:24:09 +02:00
|
|
|
{
|
|
|
|
[self errorWithFormat: @"%s: you should *never* get here", __PRETTY_FUNCTION__];
|
|
|
|
// /* attempt to populate our mapping dict with data from indexing.tdb */
|
|
|
|
// key.dptr = (unsigned char *) talloc_asprintf (memCtx, "0x%.16llx",
|
|
|
|
// (long long unsigned int )fmid);
|
|
|
|
// key.dsize = strlen ((const char *) key.dptr);
|
|
|
|
|
|
|
|
// dbuf = tdb_fetch (memCtx->indexing_list->index_ctx->tdb, key);
|
|
|
|
// talloc_free (key.dptr);
|
|
|
|
// uri = talloc_strndup (memCtx, (const char *)dbuf.dptr, dbuf.dsize);
|
|
|
|
*path = NULL;
|
|
|
|
rc = MAPI_E_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self logWithFormat: @"getPath.... %lld -> (%s, %d)", fmid, *path, rc];
|
2010-10-13 23:40:50 +02:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (int) getFID: (uint64_t *) fid
|
|
|
|
byName: (const char *) foldername
|
|
|
|
inParentFID: (uint64_t) parent_fid
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d) -- foldername: %s, parent_fid: %lld",
|
|
|
|
__FUNCTION__, __LINE__, foldername, parent_fid];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-11-06 00:27:08 +01:00
|
|
|
- (int) setPropertiesOfMessage: (NSMutableDictionary *) message
|
|
|
|
fromRow: (struct SRow *) aRow
|
2010-10-01 20:54:30 +02:00
|
|
|
{
|
2010-11-06 00:27:08 +01:00
|
|
|
int counter;
|
|
|
|
NSNumber *key;
|
|
|
|
struct SPropValue *cValue;
|
|
|
|
|
|
|
|
for (counter = 0; counter < aRow->cValues; counter++)
|
|
|
|
{
|
|
|
|
cValue = &(aRow->lpProps[counter]);
|
|
|
|
key = [NSNumber numberWithUnsignedLong: cValue->ulPropTag];
|
|
|
|
[message setObject: [NSObject objectFromSPropValue: cValue]
|
|
|
|
forKey: key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) setPropertiesWithFMID: (uint64_t) fmid
|
|
|
|
type: (uint8_t) type
|
|
|
|
inRow: (struct SRow *) aRow
|
|
|
|
{
|
|
|
|
NSMutableDictionary *message;
|
|
|
|
NSNumber *midNbr;
|
|
|
|
int rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-01 22:35:29 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MAPISTORE_FOLDER:
|
2010-11-06 00:27:08 +01:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
|
|
|
|
|
|
|
rc = MAPISTORE_ERROR;
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
|
|
|
case MAPISTORE_MESSAGE:
|
2010-11-06 00:27:08 +01:00
|
|
|
midNbr = [NSNumber numberWithUnsignedLongLong: fmid];
|
|
|
|
message = [messages objectForKey: midNbr];
|
|
|
|
if (message)
|
|
|
|
rc = [self setPropertiesOfMessage: message
|
|
|
|
fromRow: aRow];
|
|
|
|
else
|
|
|
|
rc = MAPISTORE_ERR_NOT_FOUND;
|
2010-10-01 22:35:29 +02:00
|
|
|
break;
|
2010-11-06 00:27:08 +01:00
|
|
|
default:
|
|
|
|
rc = MAPISTORE_ERROR;
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-11-06 00:27:08 +01:00
|
|
|
return rc;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) deleteMessageWithMID: (uint64_t) mid
|
|
|
|
withFlags: (uint8_t) flags
|
|
|
|
{
|
2010-10-01 22:35:29 +02:00
|
|
|
[self logWithFormat: @"METHOD '%s' (%d)", __FUNCTION__, __LINE__];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-10-14 15:22:26 +02:00
|
|
|
return MAPISTORE_ERROR;
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 23:40:50 +02:00
|
|
|
- (int) getFoldersList: (struct indexing_folders_list **) folders_list
|
|
|
|
withFMID: (uint64_t) fmid
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
NSString *currentURL;
|
|
|
|
NSMutableArray *nsFolderList;
|
|
|
|
uint64_t fid;
|
|
|
|
|
|
|
|
rc = MAPI_E_SUCCESS;
|
|
|
|
|
|
|
|
currentURL = [mapping urlFromID: fmid];
|
2010-10-15 19:24:09 +02:00
|
|
|
if (currentURL && ![currentURL isEqualToString: uri]
|
|
|
|
&& [currentURL hasPrefix: uri])
|
2010-10-13 23:40:50 +02:00
|
|
|
{
|
|
|
|
nsFolderList = [NSMutableArray arrayWithCapacity: 32];
|
|
|
|
currentURL = [self _parentURLFromURL: currentURL];
|
|
|
|
while (currentURL && rc == MAPI_E_SUCCESS
|
|
|
|
&& ![currentURL isEqualToString: uri])
|
|
|
|
{
|
|
|
|
fid = [mapping idFromURL: currentURL];
|
|
|
|
if (fid == NSNotFound)
|
|
|
|
rc = MAPI_E_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[nsFolderList insertObject: [NSNumber numberWithUnsignedLongLong: fid]
|
|
|
|
atIndex: 0];
|
|
|
|
currentURL = [self _parentURLFromURL: currentURL];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc != MAPI_E_NOT_FOUND)
|
|
|
|
{
|
|
|
|
fid = [mapping idFromURL: uri];
|
|
|
|
[nsFolderList insertObject: [NSNumber numberWithUnsignedLongLong: fid]
|
|
|
|
atIndex: 0];
|
|
|
|
*folders_list = [nsFolderList asFoldersListInCtx: memCtx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = MAPI_E_NOT_FOUND;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@end
|