diff --git a/OpenChange/MAPIStoreCalendarContext.m b/OpenChange/MAPIStoreCalendarContext.m index 957ee5648..6149e143c 100644 --- a/OpenChange/MAPIStoreCalendarContext.m +++ b/OpenChange/MAPIStoreCalendarContext.m @@ -42,6 +42,11 @@ @implementation MAPIStoreCalendarContext ++ (NSString *) MAPIModuleName +{ + return @"calendar"; +} + + (void) registerFixedMappings: (MAPIStoreMapping *) mapping { [mapping registerURL: @"sogo://openchange:openchange@calendar/personal" diff --git a/OpenChange/MAPIStoreContactsContext.m b/OpenChange/MAPIStoreContactsContext.m index ccd4b21ae..9f364f34d 100644 --- a/OpenChange/MAPIStoreContactsContext.m +++ b/OpenChange/MAPIStoreContactsContext.m @@ -44,6 +44,11 @@ @implementation MAPIStoreContactsContext ++ (NSString *) MAPIModuleName +{ + return @"contacts"; +} + + (void) registerFixedMappings: (MAPIStoreMapping *) mapping { [mapping registerURL: @"sogo://openchange:openchange@contacts/personal" diff --git a/OpenChange/MAPIStoreContext.h b/OpenChange/MAPIStoreContext.h index 746a507ae..0171c4a69 100644 --- a/OpenChange/MAPIStoreContext.h +++ b/OpenChange/MAPIStoreContext.h @@ -127,6 +127,7 @@ withFlags: (uint8_t) flags; /* subclass methods */ ++ (NSString *) MAPIModuleName; + (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping; - (NSArray *) getFolderMessageKeys: (SOGoFolder *) folder; diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index 1724ac6f8..65881f7f5 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -65,6 +65,8 @@ - (NSString *) davContentLength; - (void) setMAPIProperties: (NSDictionary *) properties; +- (void) MAPISave; +- (void) MAPISubmit; @end @@ -75,67 +77,67 @@ static Class SOGoObjectK, SOGoMailAccountK, SOGoMailFolderK; static Class NSArrayK; -static MAPIStoreMapping *mapping = nil; +static MAPIStoreMapping *mapping; +static NSMutableDictionary *contextClassMapping; + (void) initialize { + NSArray *classes; + Class currentClass; + NSUInteger count, max; + NSString *moduleName; + SOGoObjectK = [SOGoObject class]; SOGoMailAccountK = [SOGoMailAccount class]; SOGoMailFolderK = [SOGoMailFolder class]; NSArrayK = [NSArray class]; mapping = [MAPIStoreMapping sharedMapping]; + + contextClassMapping = [NSMutableDictionary new]; + classes = GSObjCAllSubclassesOfClass (self); + max = [classes count]; + for (count = 0; count < max; count++) + { + currentClass = [classes objectAtIndex: count]; + moduleName = [currentClass MAPIModuleName]; + NSLog (@" registered class '%@' as handler of '%@' contexts", + NSStringFromClass (currentClass), moduleName); + [contextClassMapping setObject: currentClass + forKey: moduleName]; + } +} + ++ (NSString *) MAPIModuleName +{ + [self subclassResponsibility: _cmd]; + + return nil; } + (void) registerFixedMappings: (MAPIStoreMapping *) storeMapping { } -static inline NSString * -_contextClassFromModule (NSString *module) -{ - NSString *contextClass; - - if ([module isEqualToString: @"mail"]) - contextClass = @"MAPIStoreMailContext"; - else if ([module isEqualToString: @"contacts"]) - contextClass = @"MAPIStoreContactsContext"; - else if ([module isEqualToString: @"calendar"]) - contextClass = @"MAPIStoreCalendarContext"; - else if ([module isEqualToString: @"tasks"]) - contextClass = @"MAPIStoreTasksContext"; - else if ([module isEqualToString: @"freebusy"]) - contextClass = @"MAPIStoreFreebusyContext"; - else - { - NSLog (@"ERROR: unrecognized module name '%@'", module); - contextClass = nil; - } - - return contextClass; -} - static inline MAPIStoreContext * _prepareContextClass (struct mapistore_context *newMemCtx, - NSString *contextClass, NSString *completeURLString, + Class contextClass, NSString *completeURLString, NSString *username, NSString *password) { MAPIStoreContext *context; MAPIStoreAuthenticator *authenticator; static NSMutableDictionary *registration = nil; - Class contextK; if (!registration) registration = [NSMutableDictionary new]; - contextK = NSClassFromString (contextClass); if (![registration objectForKey: contextClass]) { - [contextK registerFixedMappings: mapping]; + [contextClass registerFixedMappings: mapping]; [registration setObject: [NSNull null] forKey: contextClass]; } - context = [contextK new]; + context = [contextClass new]; [context setURI: completeURLString andMemCtx: newMemCtx]; [context autorelease]; @@ -156,7 +158,8 @@ _prepareContextClass (struct mapistore_context *newMemCtx, inMemCtx: (struct mapistore_context *) newMemCtx { MAPIStoreContext *context; - NSString *contextClass, *module, *completeURLString, *urlString; + Class contextClass; + NSString *module, *completeURLString, *urlString; NSURL *baseURL; NSLog (@"METHOD '%s' (%d) -- uri: '%s'", __FUNCTION__, __LINE__, newUri); @@ -173,13 +176,15 @@ _prepareContextClass (struct mapistore_context *newMemCtx, module = [baseURL host]; if (module) { - contextClass = _contextClassFromModule (module); + contextClass = [contextClassMapping objectForKey: module]; if (contextClass) context = _prepareContextClass (newMemCtx, contextClass, completeURLString, [baseURL user], [baseURL password]); + else + NSLog (@"ERROR: unrecognized module name '%@'", module); } } else @@ -980,21 +985,25 @@ _prepareContextClass (struct mapistore_context *newMemCtx, if (parentFolder) { message = [self createMessageInFolder: parentFolder]; - if (![folderURL hasSuffix: @"/"]) - folderURL = [NSString stringWithFormat: @"%@/", folderURL]; - messageURL = [NSString stringWithFormat: @"%@%@", folderURL, - [message nameInContainer]]; - [mapping registerURL: messageURL withID: mid]; + if (message) + { + if (![folderURL hasSuffix: @"/"]) + folderURL = [NSString stringWithFormat: @"%@/", folderURL]; + messageURL = [NSString stringWithFormat: @"%@%@", folderURL, + [message nameInContainer]]; + [mapping registerURL: messageURL withID: mid]; + } } } else - [self errorWithFormat: @"registered message without a valid fid"]; + [self errorWithFormat: @"registered message without a valid fid (%.16x)", fid]; return message; } -- (int) saveChangesInMessageWithMID: (uint64_t) mid - andFlags: (uint8_t) flags +- (int) _saveOrSubmitChangesInMessageWithMID: (uint64_t) mid + andFlags: (uint8_t) flags + save: (BOOL) isSave { int rc; id message; @@ -1018,6 +1027,10 @@ _prepareContextClass (struct mapistore_context *newMemCtx, if (message) { [message setMAPIProperties: messageProperties]; + if (isSave) + [message MAPISave]; + else + [message MAPISubmit]; rc = MAPISTORE_SUCCESS; } else @@ -1029,12 +1042,20 @@ _prepareContextClass (struct mapistore_context *newMemCtx, return rc; } +- (int) saveChangesInMessageWithMID: (uint64_t) mid + andFlags: (uint8_t) flags +{ + return [self _saveOrSubmitChangesInMessageWithMID: mid + andFlags: flags + save: YES]; +} + - (int) submitMessageWithMID: (uint64_t) mid andFlags: (uint8_t) flags { - [self logWithFormat: @"UNIMPLEMENTED METHOD '%s' (%d)", __FUNCTION__, __LINE__]; - - return MAPISTORE_ERROR; + return [self _saveOrSubmitChangesInMessageWithMID: mid + andFlags: flags + save: NO]; } - (int) getProperties: (struct SPropTagArray *) sPropTagArray diff --git a/OpenChange/SOGoAppointmentObject+MAPIStore.m b/OpenChange/SOGoAppointmentObject+MAPIStore.m index f21dad09e..b256aea35 100644 --- a/OpenChange/SOGoAppointmentObject+MAPIStore.m +++ b/OpenChange/SOGoAppointmentObject+MAPIStore.m @@ -124,8 +124,7 @@ } // MAPIStoreDumpMessageProperties (properties); - - [self saveContentString: [vCalendar versitString]]; + ASSIGN (content, [vCalendar versitString]); } @end diff --git a/OpenChange/SOGoContactGCSEntry+MAPIStore.m b/OpenChange/SOGoContactGCSEntry+MAPIStore.m index fce603d0c..38af14f12 100644 --- a/OpenChange/SOGoContactGCSEntry+MAPIStore.m +++ b/OpenChange/SOGoContactGCSEntry+MAPIStore.m @@ -70,7 +70,7 @@ if (value) [newCard addEmail: value types: nil]; - [self save]; + ASSIGN (content, [newCard versitString]); } @end diff --git a/OpenChange/SOGoContentObject+MAPIStore.h b/OpenChange/SOGoContentObject+MAPIStore.h new file mode 100644 index 000000000..d6a1d34c4 --- /dev/null +++ b/OpenChange/SOGoContentObject+MAPIStore.h @@ -0,0 +1,35 @@ +/* SOGoContentObject+MAPIStore.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 SOGOCONTENTOBJECT_MAPISTORE_H +#define SOGOCONTENTOBJECT_MAPISTORE_H + +#import + +@interface SOGoContentObject (MAPIStoreMessage) + +- (void) MAPISave; + +@end + + +#endif /* SOGOCONTENTOBJECT_MAPISTORE_H */ diff --git a/OpenChange/SOGoContentObject+MAPIStore.m b/OpenChange/SOGoContentObject+MAPIStore.m new file mode 100644 index 000000000..74310863e --- /dev/null +++ b/OpenChange/SOGoContentObject+MAPIStore.m @@ -0,0 +1,32 @@ +/* SOGoContentObject+MAPIStore.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 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 "SOGoContentObject+MAPIStore.h" + +@implementation SOGoContentObject (MAPIStoreMessage) + +- (void) MAPISave +{ + [self saveContentString: content]; +} + +@end diff --git a/OpenChange/SOGoTaskObject+MAPIStore.m b/OpenChange/SOGoTaskObject+MAPIStore.m index 9afe3e37a..cbd9e5658 100644 --- a/OpenChange/SOGoTaskObject+MAPIStore.m +++ b/OpenChange/SOGoTaskObject+MAPIStore.m @@ -209,7 +209,7 @@ // MAPIStoreDumpMessageProperties (properties); - [self saveContentString: [vCalendar versitString]]; + ASSIGN (content, [vCalendar versitString]); } @end