From a5a2d75a4879dcdef4e3bfb0aadb526782bd8ab6 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 30 Dec 2010 14:28:33 +0000 Subject: [PATCH] Monotone-Parent: 8a338c5caf581e45823828957eefcbd38abd2ee7 Monotone-Revision: db8560398c89d701d67964f47b08024ba18ae1cb Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-12-30T14:28:33 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 + ...BaseContext.h => MAPIStoreFSBaseContext.h} | 10 +- OpenChange/MAPIStoreFSBaseContext.m | 70 +++++ OpenChange/MAPIStoreFSMessageTable.h | 31 ++ OpenChange/MAPIStoreFSMessageTable.m | 152 +++++++++ OpenChange/MAPIStoreFileSystemBaseContext.m | 289 ------------------ 6 files changed, 262 insertions(+), 294 deletions(-) rename OpenChange/{MAPIStoreFileSystemBaseContext.h => MAPIStoreFSBaseContext.h} (77%) create mode 100644 OpenChange/MAPIStoreFSBaseContext.m create mode 100644 OpenChange/MAPIStoreFSMessageTable.h create mode 100644 OpenChange/MAPIStoreFSMessageTable.m delete mode 100644 OpenChange/MAPIStoreFileSystemBaseContext.m diff --git a/ChangeLog b/ChangeLog index d854758a6..797632b1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-12-30 Wolfgang Sourdeau + * OpenChange/MAPIStoreFSBaseContext.[hm]: renamed from + MAPIStoreFileSystemBaseContext. Old table methods (see below) + split into the new "MAPIStoreFSMessageTable" class. + * OpenChange/MAPIStoreSOGo.m (sogo_op_openmessage): added some debugging. (sogo_op_createmessage): takes a new "associated" flag parameter. diff --git a/OpenChange/MAPIStoreFileSystemBaseContext.h b/OpenChange/MAPIStoreFSBaseContext.h similarity index 77% rename from OpenChange/MAPIStoreFileSystemBaseContext.h rename to OpenChange/MAPIStoreFSBaseContext.h index 57a530b0a..ecc63d1e6 100644 --- a/OpenChange/MAPIStoreFileSystemBaseContext.h +++ b/OpenChange/MAPIStoreFSBaseContext.h @@ -1,4 +1,4 @@ -/* MAPIStoreFileSystemBaseContext.h - this file is part of SOGo +/* MAPIStoreFSBaseContext.h - this file is part of SOGo * * Copyright (C) 2010 Inverse inc. * @@ -20,13 +20,13 @@ * Boston, MA 02111-1307, USA. */ -#ifndef MAPISTOREFILESYSTEMBASECONTEXT_H -#define MAPISTOREFILESYSTEMBASECONTEXT_H +#ifndef MAPISTOREFSBASECONTEXT_H +#define MAPISTOREFSBASECONTEXT_H #import "MAPIStoreContext.h" -@interface MAPIStoreFileSystemBaseContext : MAPIStoreContext +@interface MAPIStoreFSBaseContext : MAPIStoreContext @end -#endif /* MAPISTOREFILESYSTEMBASECONTEXT_H */ +#endif /* MAPISTOREFSBASECONTEXT_H */ diff --git a/OpenChange/MAPIStoreFSBaseContext.m b/OpenChange/MAPIStoreFSBaseContext.m new file mode 100644 index 000000000..e817921ae --- /dev/null +++ b/OpenChange/MAPIStoreFSBaseContext.m @@ -0,0 +1,70 @@ +/* MAPIStoreFSBaseContext.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 + * the Free Software Foundation; either version 3, or (at your option) + * 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. + */ + +/* A generic parent class for all context that will store their data on the + disk in the form of a plist. */ + +#import +#import + +#import + +#import "MAPIStoreFSMessageTable.h" +#import "MAPIStoreMapping.h" +#import "SOGoMAPIFSFolder.h" + +#import "MAPIStoreFSBaseContext.h" + +#undef DEBUG +#include + +@implementation MAPIStoreFSBaseContext + ++ (NSString *) MAPIModuleName +{ + return nil; +} + +- (void) setupModuleFolder +{ + [self logWithFormat: @"invoked %s", __PRETTY_FUNCTION__]; + moduleFolder = [SOGoMAPIFSFolder folderWithURL: [NSURL URLWithString: uri] + andTableType: MAPISTORE_MESSAGE_TABLE]; + [moduleFolder retain]; +} + +- (Class) messageTableClass +{ + return [MAPIStoreFSMessageTable class]; +} + +- (id) createMessageOfClass: (NSString *) messageClass + inFolderAtURL: (NSString *) folderURL; +{ + SOGoMAPIFSFolder *parentFolder; + + parentFolder = [self lookupObject: folderURL]; + + return [parentFolder newMessage]; +} + +@end diff --git a/OpenChange/MAPIStoreFSMessageTable.h b/OpenChange/MAPIStoreFSMessageTable.h new file mode 100644 index 000000000..452c8ffdb --- /dev/null +++ b/OpenChange/MAPIStoreFSMessageTable.h @@ -0,0 +1,31 @@ +/* MAPIStoreFSMessageTable.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * 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. + */ + +#ifndef MAPISTOREFSMESSAGETABLE_H +#define MAPISTOREFSMESSAGETABLE_H + +#import "MAPIStoreMessageTable.h" + +@interface MAPIStoreFSMessageTable : MAPIStoreMessageTable +@end + +#endif /* MAPISTOREFSMESSAGETABLE_H */ diff --git a/OpenChange/MAPIStoreFSMessageTable.m b/OpenChange/MAPIStoreFSMessageTable.m new file mode 100644 index 000000000..fa4cdc9ca --- /dev/null +++ b/OpenChange/MAPIStoreFSMessageTable.m @@ -0,0 +1,152 @@ +/* MAPIStoreFSMessageTable.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 + * the Free Software Foundation; either version 3, or (at your option) + * 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 +#import + +#import + +#import "EOQualifier+MAPIFS.h" +#import "MAPIStoreTypes.h" +#import "SOGoMAPIFSFolder.h" +#import "SOGoMAPIFSMessage.h" + +#import "MAPIStoreFSMessageTable.h" +#import "NSCalendarDate+MAPIStore.h" +#import "NSData+MAPIStore.h" +#import "NSString+MAPIStore.h" +#import "NSValue+MAPIStore.h" + +#undef DEBUG +#include + +@implementation MAPIStoreFSMessageTable + +- (enum MAPISTATUS) getChildProperty: (void **) data + forKey: (NSString *) childKey + withTag: (enum MAPITAGS) propTag +{ + NSDictionary *properties; + SOGoMAPIFSMessage *child; + uint16_t valueType; + id value; + int rc; + + rc = MAPI_E_SUCCESS; + + child = [self lookupChild: childKey]; + properties = [child properties]; + value = [properties objectForKey: MAPIPropertyKey (propTag)]; + if (value) + { + // [self logWithFormat: @"property %.8x found", propTag]; + valueType = (propTag & 0xffff); + switch (valueType) + { + case PT_NULL: + *data = NULL; + break; + case PT_SHORT: + *data = [value asShortInMemCtx: memCtx]; + break; + case PT_LONG: + *data = [value asLongInMemCtx: memCtx]; + break; + case PT_BOOLEAN: + *data = [value asBooleanInMemCtx: memCtx]; + break; + case PT_DOUBLE: + *data = [value asDoubleInMemCtx: memCtx]; + break; + case PT_UNICODE: + case PT_STRING8: + *data = [value asUnicodeInMemCtx: memCtx]; + break; + case PT_SYSTIME: + *data = [value asFileTimeInMemCtx: memCtx]; + break; + case PT_BINARY: + *data = [value asShortBinaryInMemCtx: memCtx]; + break; + case PT_CLSID: + *data = [value asGUIDInMemCtx: memCtx]; + break; + + default: + [self errorWithFormat: @"object type not handled: %d (0x%.4x)", + valueType, valueType]; + *data = NULL; + rc = MAPI_E_NO_SUPPORT; + } + } + else + rc = [super getChildProperty: data forKey: childKey withTag: propTag]; + + return rc; +} + +- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property +{ + return [NSString stringWithFormat: @"%@", MAPIPropertyKey (property)]; +} + +- (NSArray *) childKeys +{ + return [folder toOneRelationshipKeys]; +} + +- (NSArray *) restrictedChildKeys +{ + NSMutableArray *keys; + NSArray *allKeys; + NSUInteger count, max; + NSString *messageKey; + + allKeys = [self cachedChildKeys]; + if (restrictionState == MAPIRestrictionStateAlwaysTrue) + keys = (NSMutableArray *) allKeys; + else if (restrictionState == MAPIRestrictionStateAlwaysFalse) + keys = (NSMutableArray *) [NSArray array]; + else + { + [self logWithFormat: @"%s: getting restricted keys", __PRETTY_FUNCTION__]; + max = [allKeys count]; + keys = [NSMutableArray arrayWithCapacity: max]; + if (restrictionState == MAPIRestrictionStateNeedsEval) + { + for (count = 0; count < max; count++) + { + messageKey = [allKeys objectAtIndex: count]; + if ([restriction evaluateMAPIFSMessage: + [folder lookupName: messageKey + inContext: nil + acquire: NO]]) + [keys addObject: messageKey]; + } + } + [self logWithFormat: @" resulting keys: $$$%@$$$", keys]; + } + + return keys; +} + +@end diff --git a/OpenChange/MAPIStoreFileSystemBaseContext.m b/OpenChange/MAPIStoreFileSystemBaseContext.m deleted file mode 100644 index f3a083465..000000000 --- a/OpenChange/MAPIStoreFileSystemBaseContext.m +++ /dev/null @@ -1,289 +0,0 @@ -/* MAPIStoreFileSystemBaseContext.m - this file is part of SOGo - * - * Copyright (C) 2010 Inverse inc. - * - * Author: Wolfgang Sourdeau - * - * 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 - * the Free Software Foundation; either version 3, or (at your option) - * 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. - */ - -/* A generic parent class for all context that will store their data on the - disk in the form of a plist. */ - -#import -#import -#import -#import - -#import - -#import "EOQualifier+MAPIFS.h" - -#import "MAPIStoreMapping.h" -#import "MAPIStoreTypes.h" - -#import "SOGoMAPIFSFolder.h" -#import "SOGoMAPIFSMessage.h" - -#import "NSCalendarDate+MAPIStore.h" -#import "NSData+MAPIStore.h" -#import "NSString+MAPIStore.h" -#import "NSValue+MAPIStore.h" - -#undef DEBUG -#include -#include -#include -#include -#include - -#import "MAPIStoreFileSystemBaseContext.h" - -@implementation MAPIStoreFileSystemBaseContext - -+ (NSString *) MAPIModuleName -{ - return nil; -} - -- (void) setupModuleFolder -{ - [self logWithFormat: @"invoked %s", __PRETTY_FUNCTION__]; - moduleFolder = [SOGoMAPIFSFolder folderWithURL: [NSURL URLWithString: uri]]; - [moduleFolder retain]; -} - -- (NSArray *) getFolderMessageKeys: (SOGoFolder *) folder - matchingQualifier: (EOQualifier *) qualifier -{ - NSMutableArray *messageKeys; - NSArray *allKeys; - NSUInteger count, max; - NSString *messageKey; - - allKeys = [(SOGoMAPIFSFolder *) folder toOneRelationshipKeys]; - if (qualifier) - { - [self logWithFormat: @"%s: getting restricted keys", __PRETTY_FUNCTION__]; - max = [allKeys count]; - messageKeys = [NSMutableArray arrayWithCapacity: max]; - for (count = 0; count < max; count++) - { - messageKey = [allKeys objectAtIndex: count]; - if ([qualifier evaluateMAPIFSMessage: - [folder lookupName: messageKey - inContext: nil - acquire: NO]]) - [messageKeys addObject: messageKey]; - } - } - else - messageKeys = (NSMutableArray *) allKeys; - - return messageKeys; -} - -- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property -{ - return [NSString stringWithFormat: @"%@", MAPIPropertyKey (property)]; -} - -- (id) createMessageInFolder: (id) parentFolder -{ - return [moduleFolder newMessage]; -} - -- (enum MAPISTATUS) getMessageTableChildproperty: (void **) data - atURL: (NSString *) childURL - withTag: (enum MAPITAGS) proptag - inFolder: (SOGoFolder *) folder - withFID: (uint64_t) fid -{ - SOGoMAPIFSMessage *message; - NSDictionary *properties; - NSString *folderURL; - MAPIStoreMapping *mapping; - uint16_t valueType; - uint32_t contextId; - uint64_t mappingId; - id value; - int rc; - - message = [self lookupObject: childURL]; - if (message) - { - properties = [message properties]; - value = [properties objectForKey: MAPIPropertyKey (proptag)]; - if (value) - { - rc = MAPI_E_SUCCESS; - - // [self logWithFormat: @"property %.8x found", proptag]; - valueType = (proptag & 0xffff); - switch (valueType) - { - case PT_NULL: - *data = NULL; - break; - case PT_SHORT: - *data = [value asShortInMemCtx: memCtx]; - break; - case PT_LONG: - *data = [value asLongInMemCtx: memCtx]; - break; - case PT_BOOLEAN: - *data = [value asBooleanInMemCtx: memCtx]; - break; - case PT_DOUBLE: - *data = [value asDoubleInMemCtx: memCtx]; - break; - case PT_UNICODE: - case PT_STRING8: - *data = [value asUnicodeInMemCtx: memCtx]; - break; - case PT_SYSTIME: - *data = [value asFileTimeInMemCtx: memCtx]; - break; - case PT_BINARY: - *data = [value asShortBinaryInMemCtx: memCtx]; - break; - default: - [self errorWithFormat: @"object type not handled: %d (0x%.4x)", - valueType, valueType]; - *data = NULL; - rc = MAPI_E_NO_SUPPORT; - } - } - else - { - if (proptag == PR_MID) - { - rc = MAPI_E_SUCCESS; - mapping = [MAPIStoreMapping sharedMapping]; - mappingId = [mapping idFromURL: childURL]; - if (mappingId == NSNotFound) - { - mappingId = [[properties objectForKey: @"mid"] - unsignedLongLongValue]; - [mapping registerURL: childURL withID: mappingId]; - 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, - &contextId); - NSAssert (contextId > 0, @"no matching context found"); - mapistore_indexing_record_add_mid (memCtx, contextId, mappingId); - } - *data = MAPILongLongValue (memCtx, mappingId); - } - else if (proptag == PR_SUBJECT_UNICODE) - { - rc = MAPI_E_SUCCESS; - *data = [@"No subject" asUnicodeInMemCtx: memCtx]; - } - else - rc = [super getMessageTableChildproperty: data - atURL: childURL - withTag: proptag - inFolder: folder - withFID: fid]; - } - } - else - { - [self logWithFormat: @"object at url '%@' *not* found", childURL]; - rc = MAPI_E_INVALID_OBJECT; - } - - return rc; -} - -- (int) openMessage: (struct mapistore_message *) msg - atURL: (NSString *) childURL -{ - static enum MAPITAGS tags[] = { PR_SUBJECT_UNICODE }; - id child; - struct SRowSet *recipients; - struct SRow *properties; - NSInteger count, max; - int rc; - void *propValue; - - [self logWithFormat: @"INCOMPLETE METHOD '%s' (%d): no recipient handling", - __FUNCTION__, __LINE__]; - child = [self lookupObject: childURL]; - if (child) - { - recipients = talloc_zero (memCtx, struct SRowSet); - recipients->cRows = 0; - recipients->aRow = NULL; - msg->recipients = recipients; - - max = 1; - - properties = talloc_zero (memCtx, struct SRow); - properties->cValues = 0; - properties->ulAdrEntryPad = 0; - properties->lpProps = talloc_array (properties, struct SPropValue, max); - for (count = 0; count < max; count++) - { - if ([self getMessageTableChildproperty: &propValue - atURL: childURL - withTag: tags[count] - inFolder: nil - withFID: 0] - == MAPI_E_SUCCESS) - { - set_SPropValue_proptag (&(properties->lpProps[properties->cValues]), - tags[count], - propValue); - properties->cValues++; - } - } - - msg->properties = properties; - - rc = MAPI_E_SUCCESS; - } - else - rc = MAPI_E_NOT_FOUND; - - return rc; -} - -- (enum MAPISTATUS) getTableProperty: (void **) data - withTag: (enum MAPITAGS) proptag - atPosition: (uint32_t) pos - withTableType: (uint8_t) tableType - andQueryType: (enum table_query_type) queryType - inFID: (uint64_t) fid -{ - enum MAPISTATUS rc; - - rc = [super getTableProperty: data - withTag: proptag - atPosition: pos - withTableType: tableType - andQueryType: queryType - inFID: fid]; - if (rc) - NSLog (@"returning code for prop"); - - return rc; -} - -@end