mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-06 04:20:33 +00:00
Monotone-Parent: dd136334b53404f4fb419f4960bacd50ae38a47c
Monotone-Revision: f5f2ee70c2acc45239a32d38bf99d6078e2dbe39 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-12-30T14:18:42 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,5 +1,29 @@
|
||||
2010-12-30 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* OpenChange/MAPIStoreContext.m: refactored to extract the table
|
||||
handling code into a separate class. This enables the introduction
|
||||
of real classes for contents tables, folder tables and FAI tables,
|
||||
as well as any other type that could be handled later. Changes:
|
||||
- new messageTableClass and folderTableClass methods for
|
||||
determining the class that is appropriate to the current datatype.
|
||||
- new messageTable, folderTable ivars.
|
||||
- new faiTable ivar, always an instance of
|
||||
MAPIStoreFAIMessageTable.
|
||||
- created MAPIStoreTable, subclassed into MAPIStoreMessageTable
|
||||
and MAPIStoreFolderTable from which appropriate subclasses are
|
||||
derived for handling mails, tasks or calendar items.
|
||||
- renamed
|
||||
"getMessageTableChildproperty:atURL:withTag:inFolder:withFID:" and
|
||||
"getFolderTableChildproperty:atURL:withTag:inFolder:withFID:" to
|
||||
the simpler "getChildProperty:forKey:withTag:" form and moved them
|
||||
to the MAPIStoreTable class.
|
||||
- moved "-setRestrictions:" to MAPIStoreTable.
|
||||
- renamed "getFolderMessageKeys:matchingQualifier:" to
|
||||
"cachedChildKeys" and "cachedRestrictedChildKeys" and moved them
|
||||
to MAPIStoreTable.
|
||||
- moved all the "evaluateRestriction:intoQualifier:" methods to
|
||||
MAPIStoreTable.
|
||||
|
||||
* OpenChange/EOBitmaskQualifier.m (-description): new method.
|
||||
|
||||
2010-12-29 Ludovic Marcotte <lmarcotte@inverse.ca>
|
||||
|
||||
@@ -25,16 +25,6 @@
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
#define SENSITIVITY_NONE 0
|
||||
#define SENSITIVITY_PERSONAL 1
|
||||
#define SENSITIVITY_PRIVATE 2
|
||||
#define SENSITIVITY_COMPANY_CONFIDENTIAL 3
|
||||
|
||||
#define TBL_LEAF_ROW 0x00000001
|
||||
#define TBL_EMPTY_CATEGORY 0x00000002
|
||||
#define TBL_EXPANDED_CATEGORY 0x00000003
|
||||
#define TBL_COLLAPSED_CATEGORY 0x00000004
|
||||
|
||||
@class NSArray;
|
||||
@class NSFileHandle;
|
||||
@class NSMutableArray;
|
||||
@@ -46,40 +36,33 @@
|
||||
@class WOContext;
|
||||
|
||||
@class SOGoFolder;
|
||||
@class SOGoMAPIFSFolder;
|
||||
@class SOGoObject;
|
||||
|
||||
@class MAPIStoreAuthenticator;
|
||||
@class MAPIStoreMapping;
|
||||
|
||||
typedef enum {
|
||||
MAPIRestrictionStateAlwaysFalse = NO,
|
||||
MAPIRestrictionStateAlwaysTrue = YES,
|
||||
MAPIRestrictionStateNeedsEval, /* needs passing of qualifier to underlying
|
||||
database */
|
||||
} MAPIRestrictionState;
|
||||
@class MAPIStoreTable;
|
||||
|
||||
@interface MAPIStoreContext : NSObject
|
||||
{
|
||||
struct mapistore_context *memCtx;
|
||||
void *ldbCtx;
|
||||
|
||||
BOOL baseContextSet;
|
||||
|
||||
NSString *uri;
|
||||
|
||||
NSMutableArray *parentFoldersBag;
|
||||
|
||||
NSMutableDictionary *objectCache;
|
||||
NSMutableDictionary *messages;
|
||||
MAPIStoreAuthenticator *authenticator;
|
||||
WOContext *woContext;
|
||||
NSMutableDictionary *messageCache;
|
||||
NSMutableDictionary *subfolderCache;
|
||||
id moduleFolder;
|
||||
|
||||
NSMutableDictionary *restrictedMessageCache;
|
||||
MAPIRestrictionState restrictionState;
|
||||
EOQualifier *restriction;
|
||||
id moduleFolder;
|
||||
SOGoMAPIFSFolder *faiModuleFolder;
|
||||
|
||||
MAPIStoreTable *folderTable;
|
||||
MAPIStoreTable *messageTable;
|
||||
MAPIStoreTable *faiTable;
|
||||
|
||||
/* for active messages (NSDictionary instances) */
|
||||
NSMutableDictionary *messages;
|
||||
}
|
||||
|
||||
+ (id) contextFromURI: (const char *) newUri
|
||||
@@ -107,9 +90,9 @@ typedef enum {
|
||||
byName: (const char *) foldername
|
||||
inParentFID: (uint64_t) parent_fid;
|
||||
|
||||
- (int) setRestrictions: (struct mapi_SRestriction *) res
|
||||
- (int) setRestrictions: (const struct mapi_SRestriction *) res
|
||||
withFID: (uint64_t) fid
|
||||
andTableType: (uint8_t) type
|
||||
andTableType: (uint8_t) tableType
|
||||
getTableStatus: (uint8_t *) tableStatus;
|
||||
|
||||
- (enum MAPISTATUS) getTableProperty: (void **) data
|
||||
@@ -134,7 +117,8 @@ typedef enum {
|
||||
withMID: (uint64_t) mid
|
||||
inFID: (uint64_t) fid;
|
||||
- (int) createMessagePropertiesWithMID: (uint64_t) mid
|
||||
inFID: (uint64_t) fid;
|
||||
inFID: (uint64_t) fid
|
||||
isAssociated: (BOOL) isAssociated;
|
||||
- (int) saveChangesInMessageWithMID: (uint64_t) mid
|
||||
andFlags: (uint8_t) flags;
|
||||
- (int) submitMessageWithMID: (uint64_t) mid
|
||||
@@ -161,71 +145,31 @@ typedef enum {
|
||||
withFlags: (uint8_t) flags;
|
||||
- (int) releaseRecordWithFMID: (uint64_t) fmid
|
||||
ofTableType: (uint8_t) tableType;
|
||||
- (int) getFoldersList: (struct indexing_folders_list **) folders_list
|
||||
withFMID: (uint64_t) fmid;
|
||||
|
||||
|
||||
/* util methods */
|
||||
- (NSString *) extractChildNameFromURL: (NSString *) childURL
|
||||
andFolderURLAt: (NSString **) folderURL;
|
||||
|
||||
- (void) registerValue: (id) value
|
||||
asProperty: (enum MAPITAGS) property
|
||||
forURL: (NSString *) url;
|
||||
|
||||
|
||||
/* restrictions */
|
||||
|
||||
- (MAPIRestrictionState) evaluateRestriction: (struct mapi_SRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluateNotRestriction: (struct mapi_SNotRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr;
|
||||
- (MAPIRestrictionState) evaluateAndRestriction: (struct mapi_SAndRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr;
|
||||
- (MAPIRestrictionState) evaluateOrRestriction: (struct mapi_SOrRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr;
|
||||
|
||||
/* subclass methods */
|
||||
+ (NSString *) MAPIModuleName;
|
||||
+ (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping;
|
||||
|
||||
- (NSArray *) getFolderMessageKeys: (SOGoFolder *) folder
|
||||
matchingQualifier: (EOQualifier *) qualifier;
|
||||
- (Class) messageTableClass;
|
||||
- (Class) folderTableClass;
|
||||
|
||||
- (enum MAPISTATUS) getCommonTableChildproperty: (void **) data
|
||||
atURL: (NSString *) childURL
|
||||
withTag: (enum MAPITAGS) proptag
|
||||
inFolder: (SOGoFolder *) folder
|
||||
withFID: (uint64_t) fid;
|
||||
|
||||
- (enum MAPISTATUS) getMessageTableChildproperty: (void **) data
|
||||
atURL: (NSString *) childURL
|
||||
withTag: (enum MAPITAGS) proptag
|
||||
inFolder: (SOGoFolder *) folder
|
||||
withFID: (uint64_t) fid;
|
||||
|
||||
- (enum MAPISTATUS) getFolderTableChildproperty: (void **) data
|
||||
atURL: (NSString *) childURL
|
||||
withTag: (enum MAPITAGS) proptag
|
||||
inFolder: (SOGoFolder *) folder
|
||||
withFID: (uint64_t) fid;
|
||||
|
||||
- (int) getFoldersList: (struct indexing_folders_list **) folders_list
|
||||
withFMID: (uint64_t) fmid;
|
||||
- (id) createMessageOfClass: (NSString *) messageClass
|
||||
inFolderAtURL: (NSString *) folderURL;
|
||||
|
||||
- (int) openMessage: (struct mapistore_message *) msg
|
||||
atURL: (NSString *) childURL;
|
||||
|
||||
- (int) getMessageProperties: (struct SPropTagArray *) sPropTagArray
|
||||
inRow: (struct SRow *) aRow
|
||||
atURL: (NSString *) childURL;
|
||||
|
||||
- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property;
|
||||
|
||||
/* restrictions */
|
||||
- (MAPIRestrictionState) evaluateContentRestriction: (struct mapi_SContentRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluatePropertyRestriction: (struct mapi_SPropertyRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluateBitmaskRestriction: (struct mapi_SBitmaskRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluateExistRestriction: (struct mapi_SExistRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
forKey: (NSString *) childKey
|
||||
inTable: (MAPIStoreTable *) table;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+406
-1136
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
/* MAPIStoreFolderTable.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MAPISTOREFOLDERTABLE_H
|
||||
#define MAPISTOREFOLDERTABLE_H
|
||||
|
||||
#import "MAPIStoreTable.h"
|
||||
|
||||
@interface MAPIStoreFolderTable : MAPIStoreTable
|
||||
@end
|
||||
|
||||
#endif /* MAPISTOREFOLDERTABLE_H */
|
||||
@@ -0,0 +1,129 @@
|
||||
/* MAPIStoreFolderTable.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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 <Foundation/NSArray.h>
|
||||
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
|
||||
#import <SOGo/SOGoFolder.h>
|
||||
|
||||
#import "MAPIStoreMapping.h"
|
||||
#import "MAPIStoreTypes.h"
|
||||
|
||||
#import "MAPIStoreFolderTable.h"
|
||||
|
||||
#undef DEBUG
|
||||
#include <mapistore/mapistore.h>
|
||||
#include <mapistore/mapistore_nameid.h>
|
||||
#include <libmapiproxy.h>
|
||||
|
||||
@implementation MAPIStoreFolderTable
|
||||
|
||||
static MAPIStoreMapping *mapping;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
mapping = [MAPIStoreMapping sharedMapping];
|
||||
}
|
||||
|
||||
- (NSArray *) childKeys
|
||||
{
|
||||
return [NSArray array];
|
||||
// return [folder toManyRelationshipKeys];
|
||||
}
|
||||
|
||||
- (NSArray *) restrictedChildKeys
|
||||
{
|
||||
[self errorWithFormat: @"restrictions are ignored on mail folder tables"];
|
||||
return [folder toManyRelationshipKeys];
|
||||
}
|
||||
|
||||
- (enum MAPISTATUS) getChildProperty: (void **) data
|
||||
forKey: (NSString *) childKey
|
||||
withTag: (enum MAPITAGS) propTag
|
||||
{
|
||||
SOGoFolder *child;
|
||||
// id child;
|
||||
// struct Binary_r *binaryValue;
|
||||
NSString *childURL;
|
||||
uint32_t contextId;
|
||||
uint64_t mappingId;
|
||||
int rc;
|
||||
|
||||
rc = MAPI_E_SUCCESS;
|
||||
switch (propTag)
|
||||
{
|
||||
case PR_FID:
|
||||
childURL = [NSString stringWithFormat: @"%@%@", folderURL, childKey];
|
||||
mappingId = [mapping idFromURL: childURL];
|
||||
if (mappingId == NSNotFound)
|
||||
{
|
||||
openchangedb_get_new_folderID (ldbCtx, &mappingId);
|
||||
[mapping registerURL: childURL withID: mappingId];
|
||||
contextId = 0;
|
||||
mapistore_search_context_by_uri (memCtx, [folderURL UTF8String] + 7,
|
||||
&contextId);
|
||||
mapistore_indexing_record_add_mid (memCtx, contextId, mappingId);
|
||||
}
|
||||
*data = MAPILongLongValue (memCtx, mappingId);
|
||||
break;
|
||||
case PR_ACCESS: // TODO
|
||||
*data = MAPILongValue (memCtx, 0x63);
|
||||
break;
|
||||
case PR_ACCESS_LEVEL: // TODO
|
||||
*data = MAPILongValue (memCtx, 0x01);
|
||||
break;
|
||||
case PR_PARENT_FID:
|
||||
*data = MAPILongLongValue (memCtx, fid);
|
||||
break;
|
||||
case PR_ATTR_HIDDEN:
|
||||
case PR_ATTR_SYSTEM:
|
||||
case PR_ATTR_READONLY:
|
||||
*data = MAPIBoolValue (memCtx, NO);
|
||||
break;
|
||||
case PR_SUBFOLDERS:
|
||||
child = [self lookupChild: childKey];
|
||||
*data = MAPIBoolValue (memCtx, 0);
|
||||
// [[child toManyRelationshipKeys] count] > 0);
|
||||
// *data = MAPIBoolValue (memCtx,
|
||||
// [[child toManyRelationshipKeys] count] > 0);
|
||||
break;
|
||||
case PR_CONTENT_COUNT:
|
||||
child = [self lookupChild: childKey];
|
||||
*data = MAPILongValue (memCtx,
|
||||
[[child toOneRelationshipKeys] count]);
|
||||
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 = [super getChildProperty: data
|
||||
forKey: childKey
|
||||
withTag: propTag];
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
/* MAPIStoreMessageTable.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MAPISTOREMESSAGETABLE_H
|
||||
#define MAPISTOREMESSAGETABLE_H
|
||||
|
||||
#import "MAPIStoreTable.h"
|
||||
|
||||
@interface MAPIStoreMessageTable : MAPIStoreTable
|
||||
@end
|
||||
|
||||
#endif /* MAPISTOREMESSAGETABLE_H */
|
||||
@@ -0,0 +1,201 @@
|
||||
/* MAPIStoreMessageTable.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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 <SOGo/SOGoFolder.h>
|
||||
#import <SOGo/SOGoObject.h>
|
||||
|
||||
#import "MAPIStoreMapping.h"
|
||||
#import "MAPIStoreTypes.h"
|
||||
#import "NSData+MAPIStore.h"
|
||||
#import "NSString+MAPIStore.h"
|
||||
|
||||
#import "MAPIStoreMessageTable.h"
|
||||
|
||||
#undef DEBUG
|
||||
#include <stdbool.h>
|
||||
#include <gen_ndr/exchange.h>
|
||||
#include <libmapiproxy.h>
|
||||
#include <mapistore/mapistore.h>
|
||||
#include <mapistore/mapistore_nameid.h>
|
||||
#include <talloc.h>
|
||||
|
||||
@interface SOGoObject (MAPIStoreProtocol)
|
||||
|
||||
- (NSString *) davEntityTag;
|
||||
- (NSString *) davContentLength;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MAPIStoreMessageTable
|
||||
|
||||
static MAPIStoreMapping *mapping;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
mapping = [MAPIStoreMapping sharedMapping];
|
||||
}
|
||||
|
||||
- (NSArray *) childKeys
|
||||
{
|
||||
return [folder toOneRelationshipKeys];
|
||||
}
|
||||
|
||||
- (enum MAPISTATUS) getChildProperty: (void **) data
|
||||
forKey: (NSString *) childKey
|
||||
withTag: (enum MAPITAGS) propTag
|
||||
{
|
||||
int rc;
|
||||
uint32_t contextId;
|
||||
uint64_t mappingId;
|
||||
NSString *stringValue, *childURL;
|
||||
NSUInteger length;
|
||||
id child;
|
||||
|
||||
rc = MAPI_E_SUCCESS;
|
||||
switch (propTag)
|
||||
{
|
||||
case PR_INST_ID: // TODO: DOUBT
|
||||
/* we return a unique id based on the key */
|
||||
*data = MAPILongLongValue (memCtx, [childKey hash]);
|
||||
break;
|
||||
case PR_INSTANCE_NUM: // TODO: DOUBT
|
||||
*data = MAPILongValue (memCtx, 0);
|
||||
break;
|
||||
case PR_ROW_TYPE: // TODO: DOUBT
|
||||
*data = MAPILongValue (memCtx, TBL_LEAF_ROW);
|
||||
break;
|
||||
case PR_DEPTH: // TODO: DOUBT
|
||||
*data = MAPILongLongValue (memCtx, 0);
|
||||
break;
|
||||
case PR_ACCESS: // TODO
|
||||
*data = MAPILongValue (memCtx, 0x02);
|
||||
break;
|
||||
case PR_ACCESS_LEVEL: // TODO
|
||||
*data = MAPILongValue (memCtx, 0x00000000);
|
||||
break;
|
||||
case PR_VIEW_STYLE:
|
||||
case PR_VIEW_MAJORVERSION:
|
||||
*data = MAPILongValue (memCtx, 0);
|
||||
break;
|
||||
case PidLidSideEffects: // TODO
|
||||
*data = MAPILongValue (memCtx, 0x00000000);
|
||||
break;
|
||||
case PidLidCurrentVersion:
|
||||
*data = MAPILongValue (memCtx, 115608); // Outlook 11.5608
|
||||
break;
|
||||
case PidLidCurrentVersionName:
|
||||
*data = [@"11.0" asUnicodeInMemCtx: memCtx];
|
||||
break;
|
||||
case PidLidAutoProcessState:
|
||||
*data = MAPILongValue (memCtx, 0x00000000);
|
||||
break;
|
||||
case PidNameContentClass:
|
||||
*data = [@"Sharing" asUnicodeInMemCtx: memCtx];
|
||||
break;
|
||||
|
||||
// case PR_VD_NAME_UNICODE:
|
||||
// *data = [@"PR_VD_NAME_UNICODE fake value" asUnicodeInMemCtx: memCtx];
|
||||
// break;
|
||||
// case PR_VD_VERSION:
|
||||
// /* mandatory value... wtf? */g
|
||||
// *data = MAPILongValue (memCtx, 8);
|
||||
// break;
|
||||
case PR_FID:
|
||||
*data = MAPILongLongValue (memCtx, fid);
|
||||
break;
|
||||
case PR_MID:
|
||||
childURL = [NSString stringWithFormat: @"%@%@", folderURL, childKey];
|
||||
mappingId = [mapping idFromURL: childURL];
|
||||
if (mappingId == NSNotFound)
|
||||
{
|
||||
openchangedb_get_new_folderID (ldbCtx, &mappingId);
|
||||
[mapping registerURL: childURL withID: mappingId];
|
||||
contextId = 0;
|
||||
mapistore_search_context_by_uri (memCtx, [folderURL UTF8String] + 7,
|
||||
&contextId);
|
||||
mapistore_indexing_record_add_mid (memCtx, contextId, mappingId);
|
||||
}
|
||||
*data = MAPILongLongValue (memCtx, mappingId);
|
||||
break;
|
||||
case PR_MESSAGE_CODEPAGE:
|
||||
case PR_INTERNET_CPID:
|
||||
*data = MAPILongValue (memCtx, 1200);
|
||||
break;
|
||||
case PR_MESSAGE_LOCALE_ID:
|
||||
*data = MAPILongValue (memCtx, 0x0409);
|
||||
break;
|
||||
case PR_MESSAGE_FLAGS: // TODO
|
||||
*data = MAPILongValue (memCtx, MSGFLAG_FROMME | MSGFLAG_READ | MSGFLAG_UNMODIFIED);
|
||||
break;
|
||||
case PR_MESSAGE_SIZE: // TODO
|
||||
child = [self lookupChild: childKey];
|
||||
/* 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;
|
||||
case PR_CHANGE_KEY:
|
||||
child = [self lookupChild: childKey];
|
||||
stringValue = [child davEntityTag];
|
||||
length = [stringValue length];
|
||||
if (length < 6) /* guid = 16 bytes */
|
||||
{
|
||||
length += 6;
|
||||
stringValue = [NSString stringWithFormat: @"000000%@",
|
||||
stringValue];
|
||||
}
|
||||
if (length > 6)
|
||||
stringValue = [stringValue substringFromIndex: length - 7];
|
||||
stringValue = [NSString stringWithFormat: @"SOGo%@%@%@",
|
||||
stringValue, stringValue, stringValue];
|
||||
*data = [[stringValue dataUsingEncoding: NSASCIIStringEncoding]
|
||||
asShortBinaryInMemCtx: memCtx];
|
||||
break;
|
||||
|
||||
case PR_SUBJECT_UNICODE:
|
||||
rc = [self getChildProperty: data forKey: childKey
|
||||
withTag: PR_NORMALIZED_SUBJECT_UNICODE];
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = [super getChildProperty: data
|
||||
forKey: childKey
|
||||
withTag: propTag];
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,106 @@
|
||||
/* MAPIStoreTable.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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 MAPISTORETABLE_H
|
||||
#define MAPISTORETABLE_H
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
#define SENSITIVITY_NONE 0
|
||||
#define SENSITIVITY_PERSONAL 1
|
||||
#define SENSITIVITY_PRIVATE 2
|
||||
#define SENSITIVITY_COMPANY_CONFIDENTIAL 3
|
||||
|
||||
#define TBL_LEAF_ROW 0x00000001
|
||||
#define TBL_EMPTY_CATEGORY 0x00000002
|
||||
#define TBL_EXPANDED_CATEGORY 0x00000003
|
||||
#define TBL_COLLAPSED_CATEGORY 0x00000004
|
||||
|
||||
typedef enum {
|
||||
MAPIRestrictionStateAlwaysFalse = NO,
|
||||
MAPIRestrictionStateAlwaysTrue = YES,
|
||||
MAPIRestrictionStateNeedsEval, /* needs passing of qualifier to underlying
|
||||
database */
|
||||
} MAPIRestrictionState;
|
||||
|
||||
@class NSArray;
|
||||
@class NSString;
|
||||
@class EOQualifier;
|
||||
|
||||
@interface MAPIStoreTable : NSObject
|
||||
{
|
||||
id context;
|
||||
struct mapistore_context *memCtx;
|
||||
void *ldbCtx;
|
||||
|
||||
id folder;
|
||||
NSString *folderURL;
|
||||
uint64_t fid;
|
||||
|
||||
id lastChild;
|
||||
NSString *lastChildKey;
|
||||
|
||||
NSArray *cachedKeys;
|
||||
NSArray *cachedRestrictedKeys;
|
||||
EOQualifier *restriction; /* should probably be a dictionary too */
|
||||
MAPIRestrictionState restrictionState;
|
||||
}
|
||||
|
||||
- (id) folder;
|
||||
|
||||
- (void) setContext: (id) newContext
|
||||
withMemCtx: (struct mapistore_context *) newMemCtx;
|
||||
- (void) setFolder: (id) newFolder
|
||||
withURL: (NSString *) newFolderURL
|
||||
andFID: (uint64_t) newFid;
|
||||
|
||||
- (void) setRestrictions: (const struct mapi_SRestriction *) res;
|
||||
|
||||
- (NSArray *) cachedChildKeys;
|
||||
- (NSArray *) cachedRestrictedChildKeys;
|
||||
|
||||
- (id) lookupChild: (NSString *) childKey;
|
||||
|
||||
- (void) cleanupCaches;
|
||||
|
||||
- (enum MAPISTATUS) getChildProperty: (void **) data
|
||||
forKey: (NSString *) childKey
|
||||
withTag: (enum MAPITAGS) proptag;
|
||||
|
||||
/* subclasses */
|
||||
|
||||
- (NSArray *) childKeys;
|
||||
- (NSArray *) restrictedChildKeys;
|
||||
|
||||
- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property;
|
||||
- (MAPIRestrictionState) evaluateContentRestriction: (const struct mapi_SContentRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluatePropertyRestriction: (const struct mapi_SPropertyRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluateBitmaskRestriction: (const struct mapi_SBitmaskRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
- (MAPIRestrictionState) evaluateExistRestriction: (const struct mapi_SExistRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* MAPISTORETABLE_H */
|
||||
@@ -0,0 +1,792 @@
|
||||
/* MAPIStoreTable.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2010 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSException.h>
|
||||
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
#import <EOControl/EOQualifier.h>
|
||||
|
||||
#import <SOGo/SOGoFolder.h>
|
||||
|
||||
#import "EOBitmaskQualifier.h"
|
||||
#import "MAPIStoreTypes.h"
|
||||
#import "NSData+MAPIStore.h"
|
||||
#import "NSString+MAPIStore.h"
|
||||
|
||||
#import "MAPIStoreTable.h"
|
||||
|
||||
#undef DEBUG
|
||||
#include <mapistore/mapistore.h>
|
||||
#include <libmapiproxy.h>
|
||||
|
||||
@interface MAPIStoreTable (Private)
|
||||
|
||||
- (MAPIRestrictionState) evaluateRestriction: (const struct mapi_SRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier;
|
||||
@end
|
||||
|
||||
static Class NSDataK, NSStringK;
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForRestrictionState (MAPIRestrictionState state)
|
||||
// {
|
||||
// NSString *stateStr;
|
||||
|
||||
// if (state == MAPIRestrictionStateAlwaysTrue)
|
||||
// stateStr = @"always true";
|
||||
// else if (state == MAPIRestrictionStateAlwaysFalse)
|
||||
// stateStr = @"always false";
|
||||
// else
|
||||
// stateStr = @"needs eval";
|
||||
|
||||
// return stateStr;
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForRestriction (const struct mapi_SRestriction *resPtr);
|
||||
|
||||
// static NSString *
|
||||
// _MAPIIndentString(int indent)
|
||||
// {
|
||||
// NSString *spaces;
|
||||
// char *buffer;
|
||||
|
||||
// if (indent > 0)
|
||||
// {
|
||||
// buffer = malloc (indent + 1);
|
||||
// memset (buffer, 32, indent);
|
||||
// *(buffer+indent) = 0;
|
||||
// spaces = [NSString stringWithFormat: @"%s", buffer];
|
||||
// free (buffer);
|
||||
// }
|
||||
// else
|
||||
// spaces = @"";
|
||||
|
||||
// return spaces;
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForAndRestriction (const struct mapi_SAndRestriction *resAnd)
|
||||
// {
|
||||
// NSMutableArray *restrictions;
|
||||
// uint16_t count;
|
||||
|
||||
// restrictions = [NSMutableArray arrayWithCapacity: 8];
|
||||
// for (count = 0; count < resAnd->cRes; count++)
|
||||
// [restrictions addObject: MAPIStringForRestriction ((struct mapi_SRestriction *) resAnd->res + count)];
|
||||
|
||||
// return [NSString stringWithFormat: @"(%@)", [restrictions componentsJoinedByString: @" && "]];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForOrRestriction (const struct mapi_SOrRestriction *resOr)
|
||||
// {
|
||||
// NSMutableArray *restrictions;
|
||||
// uint16_t count;
|
||||
|
||||
// restrictions = [NSMutableArray arrayWithCapacity: 8];
|
||||
// for (count = 0; count < resOr->cRes; count++)
|
||||
// [restrictions addObject: MAPIStringForRestriction ((struct mapi_SRestriction *) resOr->res + count)];
|
||||
|
||||
// return [NSString stringWithFormat: @"(%@)", [restrictions componentsJoinedByString: @" || "]];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForNotRestriction (const struct mapi_SNotRestriction *resNot)
|
||||
// {
|
||||
// return [NSString stringWithFormat: @"!(%@)",
|
||||
// MAPIStringForRestriction ((struct mapi_SRestriction *) &resNot->res)];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForContentRestriction (const struct mapi_SContentRestriction *resContent)
|
||||
// {
|
||||
// NSString *eqMatch, *caseMatch;
|
||||
// id value;
|
||||
// const char *propName;
|
||||
|
||||
// switch (resContent->fuzzy & 0xf)
|
||||
// {
|
||||
// case 0: eqMatch = @"eq"; break;
|
||||
// case 1: eqMatch = @"substring"; break;
|
||||
// case 2: eqMatch = @"prefix"; break;
|
||||
// default: eqMatch = @"[unknown]";
|
||||
// }
|
||||
|
||||
// switch (((resContent->fuzzy) >> 16) & 0xf)
|
||||
// {
|
||||
// case 0: caseMatch = @"fl"; break;
|
||||
// case 1: caseMatch = @"nc"; break;
|
||||
// case 2: caseMatch = @"ns"; break;
|
||||
// case 4: caseMatch = @"lo"; break;
|
||||
// default: caseMatch = @"[unknown]";
|
||||
// }
|
||||
|
||||
// propName = get_proptag_name (resContent->ulPropTag);
|
||||
// if (!propName)
|
||||
// propName = "<unknown>";
|
||||
|
||||
// value = NSObjectFromMAPISPropValue (&resContent->lpProp);
|
||||
|
||||
// return [NSString stringWithFormat: @"%s(0x%.8x) %@,%@ %@",
|
||||
// propName, resContent->ulPropTag, eqMatch, caseMatch, value];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForExistRestriction (const struct mapi_SExistRestriction *resExist)
|
||||
// {
|
||||
// const char *propName;
|
||||
|
||||
// propName = get_proptag_name (resExist->ulPropTag);
|
||||
// if (!propName)
|
||||
// propName = "<unknown>";
|
||||
|
||||
// return [NSString stringWithFormat: @"%s(0x%.8x) IS NOT NULL", propName, resExist->ulPropTag];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForPropertyRestriction (const struct mapi_SPropertyRestriction *resProperty)
|
||||
// {
|
||||
// static NSString *operators[] = { @"<", @"<=", @">", @">=", @"==", @"!=",
|
||||
// @"=~" };
|
||||
// NSString *operator;
|
||||
// id value;
|
||||
// const char *propName;
|
||||
|
||||
// propName = get_proptag_name (resProperty->ulPropTag);
|
||||
// if (!propName)
|
||||
// propName = "<unknown>";
|
||||
|
||||
// if (resProperty->relop >= 0 && resProperty->relop < 7)
|
||||
// operator = operators[resProperty->relop];
|
||||
// else
|
||||
// operator = [NSString stringWithFormat: @"<invalid op %d>", resProperty->relop];
|
||||
// value = NSObjectFromMAPISPropValue (&resProperty->lpProp);
|
||||
|
||||
// return [NSString stringWithFormat: @"%s(0x%.8x) %@ %@",
|
||||
// propName, resProperty->ulPropTag, operator, value];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForBitmaskRestriction (const struct mapi_SBitmaskRestriction *resBitmask)
|
||||
// {
|
||||
// NSString *format;
|
||||
// const char *propName;
|
||||
|
||||
// propName = get_proptag_name (resBitmask->ulPropTag);
|
||||
// if (!propName)
|
||||
// propName = "<unknown>";
|
||||
|
||||
// if (resBitmask->relMBR == 0)
|
||||
// format = @"((%s(0x%.8x) & 0x%.8x) == 0)";
|
||||
// else
|
||||
// format = @"((%s(0x%.8x) & 0x%.8x) != 0)";
|
||||
|
||||
// return [NSString stringWithFormat: format,
|
||||
// propName, resBitmask->ulPropTag, resBitmask->ulMask];
|
||||
// }
|
||||
|
||||
// static NSString *
|
||||
// MAPIStringForRestriction (const struct mapi_SRestriction *resPtr)
|
||||
// {
|
||||
// NSString *restrictionStr;
|
||||
|
||||
// if (resPtr)
|
||||
// {
|
||||
// switch (resPtr->rt)
|
||||
// {
|
||||
// // RES_CONTENT=(int)(0x3),
|
||||
// // RES_BITMASK=(int)(0x6),
|
||||
// // RES_EXIST=(int)(0x8),
|
||||
|
||||
// case 0: restrictionStr = MAPIStringForAndRestriction(&resPtr->res.resAnd); break;
|
||||
// case 1: restrictionStr = MAPIStringForOrRestriction(&resPtr->res.resOr); break;
|
||||
// case 2: restrictionStr = MAPIStringForNotRestriction(&resPtr->res.resNot); break;
|
||||
// case 3: restrictionStr = MAPIStringForContentRestriction(&resPtr->res.resContent); break;
|
||||
// case 4: restrictionStr = MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// case 6: restrictionStr = MAPIStringForBitmaskRestriction(&resPtr->res.resBitmask); break;
|
||||
// case 8: restrictionStr = MAPIStringForExistRestriction(&resPtr->res.resExist); break;
|
||||
// // case 5: MAPIStringForComparePropsRestriction(&resPtr->res.resCompareProps); break;
|
||||
// // case 7: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// // case 9: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// // case 10: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// default:
|
||||
// restrictionStr
|
||||
// = [NSString stringWithFormat: @"[unhandled restriction type: %d]",
|
||||
// resPtr->rt];
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// restrictionStr = @"[unrestricted]";
|
||||
|
||||
// return restrictionStr;
|
||||
// }
|
||||
|
||||
@implementation MAPIStoreTable
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
NSDataK = [NSData class];
|
||||
NSStringK = [NSString class];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
context = nil;
|
||||
memCtx = NULL;
|
||||
|
||||
folder = nil;
|
||||
folderURL = nil;
|
||||
|
||||
lastChild = nil;
|
||||
lastChildKey = nil;
|
||||
|
||||
cachedKeys = nil;
|
||||
cachedRestrictedKeys = nil;
|
||||
restriction = nil;
|
||||
restrictionState = MAPIRestrictionStateAlwaysTrue;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[folder release];
|
||||
[folderURL release];
|
||||
[lastChildKey release];
|
||||
[lastChild release];
|
||||
[cachedKeys release];
|
||||
[cachedRestrictedKeys release];
|
||||
[restriction release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) setContext: (id) newContext
|
||||
withMemCtx: (struct mapistore_context *) newMemCtx
|
||||
{
|
||||
struct loadparm_context *lpCtx;
|
||||
|
||||
context = newContext;
|
||||
|
||||
memCtx = newMemCtx;
|
||||
lpCtx = loadparm_init (newMemCtx);
|
||||
ldbCtx = mapiproxy_server_openchange_ldb_init (lpCtx);
|
||||
}
|
||||
|
||||
- (void) setFolder: (id) newFolder
|
||||
withURL: (NSString *) newFolderURL
|
||||
andFID: (uint64_t) newFid
|
||||
{
|
||||
ASSIGN (folder, newFolder);
|
||||
ASSIGN (folderURL, newFolderURL);
|
||||
fid = newFid;
|
||||
}
|
||||
|
||||
- (id) folder
|
||||
{
|
||||
if (!folder)
|
||||
[self warnWithFormat: @"returning nil folder"];
|
||||
return folder;
|
||||
}
|
||||
|
||||
- (NSArray *) cachedChildKeys
|
||||
{
|
||||
if (!cachedKeys)
|
||||
{
|
||||
cachedKeys = [self childKeys];
|
||||
[cachedKeys retain];
|
||||
}
|
||||
|
||||
return cachedKeys;
|
||||
}
|
||||
|
||||
- (NSArray *) cachedRestrictedChildKeys
|
||||
{
|
||||
if (!cachedRestrictedKeys)
|
||||
{
|
||||
cachedRestrictedKeys = [self restrictedChildKeys];
|
||||
[cachedRestrictedKeys retain];
|
||||
}
|
||||
|
||||
return cachedRestrictedKeys;
|
||||
}
|
||||
|
||||
- (void) cleanupCaches
|
||||
{
|
||||
[cachedRestrictedKeys release];
|
||||
cachedRestrictedKeys = nil;
|
||||
[cachedKeys release];
|
||||
cachedKeys = nil;
|
||||
}
|
||||
|
||||
- (id) lookupChild: (NSString *) childKey
|
||||
{
|
||||
id newChild;
|
||||
|
||||
if ([lastChildKey isEqualToString: childKey])
|
||||
newChild = lastChild;
|
||||
else
|
||||
{
|
||||
[self logWithFormat: @"child key is now '%@'", childKey];
|
||||
newChild = [folder lookupName: childKey
|
||||
inContext: nil
|
||||
acquire: NO];
|
||||
ASSIGN (lastChildKey, childKey);
|
||||
ASSIGN (lastChild, newChild);
|
||||
}
|
||||
|
||||
return newChild;
|
||||
}
|
||||
|
||||
- (void) setRestrictions: (const struct mapi_SRestriction *) res
|
||||
{
|
||||
EOQualifier *oldRestriction;
|
||||
|
||||
// [self logWithFormat: @"set restriction to (table type: %d): %@",
|
||||
// type, MAPIStringForRestriction (res)];
|
||||
|
||||
oldRestriction = restriction;
|
||||
[restriction release];
|
||||
if (res)
|
||||
restrictionState = [self evaluateRestriction: res
|
||||
intoQualifier: &restriction];
|
||||
else
|
||||
restrictionState = MAPIRestrictionStateAlwaysTrue;
|
||||
|
||||
if (restrictionState == MAPIRestrictionStateNeedsEval)
|
||||
[restriction retain];
|
||||
else
|
||||
restriction = nil;
|
||||
|
||||
[cachedRestrictedKeys release];
|
||||
cachedRestrictedKeys = nil;
|
||||
|
||||
if (restriction)
|
||||
[self logWithFormat: @"restriction set to EOQualifier: %@",
|
||||
restriction];
|
||||
else if (oldRestriction)
|
||||
[self logWithFormat: @"restriction unset"];
|
||||
}
|
||||
|
||||
- (enum MAPISTATUS) getChildProperty: (void **) data
|
||||
forKey: (NSString *) childKey
|
||||
withTag: (enum MAPITAGS) propTag
|
||||
{
|
||||
NSString *stringValue;
|
||||
id child;
|
||||
// uint64_t *llongValue;
|
||||
// uint32_t *longValue;
|
||||
int rc;
|
||||
const char *propName;
|
||||
|
||||
rc = MAPI_E_SUCCESS;
|
||||
switch (propTag)
|
||||
{
|
||||
case PR_DISPLAY_NAME_UNICODE:
|
||||
child = [self lookupChild: childKey];
|
||||
*data = [[child displayName] asUnicodeInMemCtx: memCtx];
|
||||
break;
|
||||
case PR_SEARCH_KEY: // TODO
|
||||
child = [self lookupChild: childKey];
|
||||
stringValue = [child nameInContainer];
|
||||
*data = [[stringValue dataUsingEncoding: NSASCIIStringEncoding]
|
||||
asBinaryInMemCtx: memCtx];
|
||||
break;
|
||||
case PR_GENERATE_EXCHANGE_VIEWS: // TODO
|
||||
*data = MAPIBoolValue (memCtx, NO);
|
||||
break;
|
||||
|
||||
default:
|
||||
propName = get_proptag_name (propTag);
|
||||
if (!propName)
|
||||
propName = "<unknown>";
|
||||
[self warnWithFormat:
|
||||
@"unhandled or NULL value: %s (0x%.8x), childKey: %@",
|
||||
propName, propTag, childKey];
|
||||
// if ((propTag & 0x001F) == 0x001F)
|
||||
// {
|
||||
// stringValue = [NSString stringWithFormat: @"fake %s (0x.8x) value",
|
||||
// propName, propTag];
|
||||
// *data = [stringValue asUnicodeInMemCtx: memCtx];
|
||||
// rc = MAPI_E_SUCCESS;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
*data = NULL;
|
||||
rc = MAPI_E_NOT_FOUND;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateNotRestriction: (struct mapi_SNotRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr
|
||||
{
|
||||
MAPIRestrictionState state, subState;
|
||||
EONotQualifier *qualifier;
|
||||
EOQualifier *subQualifier;
|
||||
|
||||
subState = [self evaluateRestriction: (struct mapi_SRestriction *)&res->res
|
||||
intoQualifier: &subQualifier];
|
||||
if (subState == MAPIRestrictionStateAlwaysTrue)
|
||||
state = MAPIRestrictionStateAlwaysFalse;
|
||||
else if (subState == MAPIRestrictionStateAlwaysFalse)
|
||||
state = MAPIRestrictionStateAlwaysTrue;
|
||||
else
|
||||
{
|
||||
state = MAPIRestrictionStateNeedsEval;
|
||||
qualifier = [[EONotQualifier alloc] initWithQualifier: subQualifier];
|
||||
[qualifier autorelease];
|
||||
*qualifierPtr = qualifier;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateAndRestriction: (struct mapi_SAndRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr
|
||||
{
|
||||
MAPIRestrictionState state, subState;
|
||||
EOAndQualifier *qualifier;
|
||||
EOQualifier *subQualifier;
|
||||
NSMutableArray *subQualifiers;
|
||||
uint16_t count;
|
||||
|
||||
state = MAPIRestrictionStateNeedsEval;
|
||||
|
||||
subQualifiers = [NSMutableArray arrayWithCapacity: 8];
|
||||
for (count = 0;
|
||||
state == MAPIRestrictionStateNeedsEval && count < res->cRes;
|
||||
count++)
|
||||
{
|
||||
subState = [self evaluateRestriction: (struct mapi_SRestriction *) res->res + count
|
||||
intoQualifier: &subQualifier];
|
||||
if (subState == MAPIRestrictionStateNeedsEval)
|
||||
[subQualifiers addObject: subQualifier];
|
||||
else if (subState == MAPIRestrictionStateAlwaysFalse)
|
||||
state = MAPIRestrictionStateAlwaysFalse;
|
||||
}
|
||||
|
||||
if (state == MAPIRestrictionStateNeedsEval)
|
||||
{
|
||||
if ([subQualifiers count] == 0)
|
||||
state = MAPIRestrictionStateAlwaysTrue;
|
||||
else
|
||||
{
|
||||
qualifier = [[EOAndQualifier alloc]
|
||||
initWithQualifierArray: subQualifiers];
|
||||
[qualifier autorelease];
|
||||
*qualifierPtr = qualifier;
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateOrRestriction: (struct mapi_SOrRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifierPtr
|
||||
{
|
||||
MAPIRestrictionState state, subState;
|
||||
EOOrQualifier *qualifier;
|
||||
EOQualifier *subQualifier;
|
||||
NSMutableArray *subQualifiers;
|
||||
uint16_t count, falseCount;
|
||||
|
||||
state = MAPIRestrictionStateNeedsEval;
|
||||
|
||||
falseCount = 0;
|
||||
subQualifiers = [NSMutableArray arrayWithCapacity: 8];
|
||||
for (count = 0;
|
||||
state == MAPIRestrictionStateNeedsEval && count < res->cRes;
|
||||
count++)
|
||||
{
|
||||
subState = [self evaluateRestriction: (struct mapi_SRestriction *) res->res + count
|
||||
intoQualifier: &subQualifier];
|
||||
if (subState == MAPIRestrictionStateNeedsEval)
|
||||
[subQualifiers addObject: subQualifier];
|
||||
else if (subState == MAPIRestrictionStateAlwaysTrue)
|
||||
state = MAPIRestrictionStateAlwaysTrue;
|
||||
else
|
||||
falseCount++;
|
||||
}
|
||||
|
||||
if (falseCount == res->cRes)
|
||||
state = MAPIRestrictionStateAlwaysFalse;
|
||||
else if ([subQualifiers count] == 0)
|
||||
state = MAPIRestrictionStateAlwaysTrue;
|
||||
|
||||
if (state == MAPIRestrictionStateNeedsEval)
|
||||
{
|
||||
qualifier = [[EOOrQualifier alloc]
|
||||
initWithQualifierArray: subQualifiers];
|
||||
[qualifier autorelease];
|
||||
*qualifierPtr = qualifier;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) _warnUnhandledPropertyException: (enum MAPITAGS) property
|
||||
inFunction: (const char *) function
|
||||
{
|
||||
const char *propName;
|
||||
|
||||
propName = get_proptag_name (property);
|
||||
if (!propName)
|
||||
propName = "<unknown>";
|
||||
[self warnWithFormat:
|
||||
@"property %s (%.8x) has no matching field name (%@) in '%s'",
|
||||
propName, property, self, function];
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateContentRestriction: (struct mapi_SContentRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier
|
||||
{
|
||||
NSString *property;
|
||||
SEL operator;
|
||||
id value;
|
||||
MAPIRestrictionState rc;
|
||||
|
||||
property = [self backendIdentifierForProperty: res->ulPropTag];
|
||||
if (property)
|
||||
{
|
||||
value = NSObjectFromMAPISPropValue (&res->lpProp);
|
||||
if ([value isKindOfClass: NSDataK])
|
||||
{
|
||||
value = [[NSString alloc] initWithData: value
|
||||
encoding: NSUTF8StringEncoding];
|
||||
[value autorelease];
|
||||
}
|
||||
else if (![value isKindOfClass: NSStringK])
|
||||
[NSException raise: @"MAPIStoreTypeConversionException"
|
||||
format: @"unhandled content restriction for class '%@'",
|
||||
NSStringFromClass ([value class])];
|
||||
|
||||
switch (res->fuzzy & 0xf)
|
||||
{
|
||||
case 0:
|
||||
operator = EOQualifierOperatorEqual;
|
||||
break;
|
||||
case 1:
|
||||
operator = EOQualifierOperatorLike;
|
||||
value = [NSString stringWithFormat: @"%%%@%%", value];
|
||||
break;
|
||||
case 2:
|
||||
operator = EOQualifierOperatorEqual;
|
||||
value = [NSString stringWithFormat: @"%@%%", value];
|
||||
break;
|
||||
default: [NSException raise: @"MAPIStoreInvalidOperatorException"
|
||||
format: @"fuzzy operator value '%.4x' is invalid",
|
||||
res->fuzzy];
|
||||
}
|
||||
|
||||
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
|
||||
operatorSelector: EOQualifierOperatorCaseInsensitiveLike
|
||||
value: value];
|
||||
[*qualifier autorelease];
|
||||
|
||||
[self logWithFormat: @"%s: resulting qualifier: %@",
|
||||
__PRETTY_FUNCTION__, *qualifier];
|
||||
|
||||
rc = MAPIRestrictionStateNeedsEval;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _warnUnhandledPropertyException: res->ulPropTag
|
||||
inFunction: __FUNCTION__];
|
||||
|
||||
rc = MAPIRestrictionStateAlwaysFalse;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluatePropertyRestriction: (struct mapi_SPropertyRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier
|
||||
{
|
||||
static SEL operators[] = { EOQualifierOperatorLessThan,
|
||||
EOQualifierOperatorLessThanOrEqualTo,
|
||||
EOQualifierOperatorGreaterThan,
|
||||
EOQualifierOperatorGreaterThanOrEqualTo,
|
||||
EOQualifierOperatorEqual,
|
||||
EOQualifierOperatorNotEqual,
|
||||
EOQualifierOperatorContains };
|
||||
SEL operator;
|
||||
id value;
|
||||
NSString *property;
|
||||
MAPIRestrictionState rc;
|
||||
|
||||
property = [self backendIdentifierForProperty: res->ulPropTag];
|
||||
if (property)
|
||||
{
|
||||
if (res->relop >= 0 && res->relop < 7)
|
||||
operator = operators[res->relop];
|
||||
else
|
||||
{
|
||||
operator = NULL;
|
||||
[NSException raise: @"MAPIStoreRestrictionException"
|
||||
format: @"unhandled operator type number %d", res->relop];
|
||||
}
|
||||
|
||||
value = NSObjectFromMAPISPropValue (&res->lpProp);
|
||||
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
|
||||
operatorSelector: operator
|
||||
value: value];
|
||||
[*qualifier autorelease];
|
||||
|
||||
rc = MAPIRestrictionStateNeedsEval;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _warnUnhandledPropertyException: res->ulPropTag
|
||||
inFunction: __FUNCTION__];
|
||||
rc = MAPIRestrictionStateAlwaysFalse;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateBitmaskRestriction: (struct mapi_SBitmaskRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier
|
||||
{
|
||||
NSString *property;
|
||||
MAPIRestrictionState rc;
|
||||
|
||||
property = [self backendIdentifierForProperty: res->ulPropTag];
|
||||
if (property)
|
||||
{
|
||||
*qualifier = [[EOBitmaskQualifier alloc] initWithKey: property
|
||||
mask: res->ulMask
|
||||
isZero: (res->relMBR == BMR_EQZ)];
|
||||
[*qualifier autorelease];
|
||||
|
||||
rc = MAPIRestrictionStateNeedsEval;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _warnUnhandledPropertyException: res->ulPropTag
|
||||
inFunction: __FUNCTION__];
|
||||
rc = MAPIRestrictionStateAlwaysFalse;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateExistRestriction: (struct mapi_SExistRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier
|
||||
{
|
||||
NSString *property;
|
||||
MAPIRestrictionState rc;
|
||||
|
||||
property = [self backendIdentifierForProperty: res->ulPropTag];
|
||||
if (property)
|
||||
{
|
||||
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
|
||||
operatorSelector: EOQualifierOperatorNotEqual
|
||||
value: nil];
|
||||
[*qualifier autorelease];
|
||||
|
||||
rc = MAPIRestrictionStateNeedsEval;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _warnUnhandledPropertyException: res->ulPropTag
|
||||
inFunction: __FUNCTION__];
|
||||
rc = MAPIRestrictionStateAlwaysFalse;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
- (MAPIRestrictionState) evaluateRestriction: (struct mapi_SRestriction *) res
|
||||
intoQualifier: (EOQualifier **) qualifier
|
||||
{
|
||||
MAPIRestrictionState state;
|
||||
|
||||
switch (res->rt)
|
||||
{
|
||||
/* basic operators */
|
||||
case 0: state = [self evaluateAndRestriction: &res->res.resAnd
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
case 1: state = [self evaluateOrRestriction: &res->res.resOr
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
case 2: state = [self evaluateNotRestriction: &res->res.resNot
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
|
||||
/* content restrictions */
|
||||
case 3: state = [self evaluateContentRestriction: &res->res.resContent
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
case 4: state = [self evaluatePropertyRestriction: &res->res.resProperty
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
case 6: state = [self evaluateBitmaskRestriction: &res->res.resBitmask
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
case 8: state = [self evaluateExistRestriction: &res->res.resExist
|
||||
intoQualifier: qualifier];
|
||||
break;
|
||||
// case 5: MAPIStringForComparePropsRestriction(&resPtr->res.resCompareProps); break;
|
||||
// case 7: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// case 9: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
// case 10: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
|
||||
default:
|
||||
[NSException raise: @"MAPIStoreRestrictionException"
|
||||
format: @"unhandled restriction type"];
|
||||
state = MAPIRestrictionStateAlwaysTrue;
|
||||
}
|
||||
|
||||
// [self logRestriction: res withState: state];
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
- (NSArray *) childKeys
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *) restrictedChildKeys
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user