2010-10-01 20:54:30 +02:00
|
|
|
/* MAPIStoreCalendarContext.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
|
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.
|
|
|
|
*/
|
|
|
|
|
2010-12-03 23:31:56 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
|
2010-10-05 15:50:03 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
2010-10-01 20:54:30 +02:00
|
|
|
#import <Appointments/SOGoAppointmentObject.h>
|
|
|
|
|
2011-02-04 04:50:21 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
#import "MAPIApplication.h"
|
|
|
|
#import "MAPIStoreAuthenticator.h"
|
2010-12-30 15:32:51 +01:00
|
|
|
#import "MAPIStoreCalendarMessageTable.h"
|
2010-11-22 17:03:30 +01:00
|
|
|
#import "MAPIStoreMapping.h"
|
2011-02-04 04:50:21 +01:00
|
|
|
#import "MAPIStoreTypes.h"
|
2010-10-01 23:24:15 +02:00
|
|
|
#import "SOGoGCSFolder+MAPIStore.h"
|
2010-10-01 20:54:30 +02:00
|
|
|
|
|
|
|
#import "MAPIStoreCalendarContext.h"
|
2011-02-04 04:50:21 +01:00
|
|
|
#import "NSString+MAPIStore.h"
|
2010-10-01 20:54:30 +02:00
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
2010-12-30 15:32:51 +01:00
|
|
|
#include <mapistore/mapistore_nameid.h>
|
2010-10-01 20:54:30 +02:00
|
|
|
|
|
|
|
@implementation MAPIStoreCalendarContext
|
|
|
|
|
2010-11-22 22:32:11 +01:00
|
|
|
+ (NSString *) MAPIModuleName
|
|
|
|
{
|
|
|
|
return @"calendar";
|
|
|
|
}
|
|
|
|
|
2010-11-22 17:03:30 +01:00
|
|
|
+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping
|
|
|
|
{
|
2010-12-30 15:32:51 +01:00
|
|
|
[mapping registerURL: @"sogo://openchange:openchange@calendar/"
|
2010-11-22 17:03:30 +01:00
|
|
|
withID: 0x190001];
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (void) setupModuleFolder
|
|
|
|
{
|
2010-12-30 15:32:51 +01:00
|
|
|
SOGoUserFolder *userFolder;
|
|
|
|
SOGoAppointmentFolders *parentFolder;
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-11-18 23:25:38 +01:00
|
|
|
userFolder = [SOGoUserFolder objectWithName: [authenticator username]
|
|
|
|
inContainer: MAPIApp];
|
2010-12-01 17:34:41 +01:00
|
|
|
[parentFoldersBag addObject: userFolder];
|
2010-10-01 22:35:29 +02:00
|
|
|
[woContext setClientObject: userFolder];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
parentFolder = [userFolder lookupName: @"Calendar"
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
|
|
|
[parentFoldersBag addObject: parentFolder];
|
|
|
|
[woContext setClientObject: parentFolder];
|
2010-10-01 22:35:29 +02:00
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
moduleFolder = [parentFolder lookupName: @"personal"
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
|
|
|
[moduleFolder retain];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
- (id) createMessageOfClass: (NSString *) messageClass
|
|
|
|
inFolderAtURL: (NSString *) folderURL;
|
2010-11-19 22:11:01 +01:00
|
|
|
{
|
2010-12-30 15:32:51 +01:00
|
|
|
SOGoAppointmentFolder *parentFolder;
|
2010-11-19 22:11:01 +01:00
|
|
|
SOGoAppointmentObject *newEntry;
|
|
|
|
NSString *name;
|
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
parentFolder = [self lookupObject: folderURL];
|
2010-11-19 22:11:01 +01:00
|
|
|
name = [NSString stringWithFormat: @"%@.ics",
|
|
|
|
[SOGoObject globallyUniqueObjectId]];
|
|
|
|
newEntry = [SOGoAppointmentObject objectWithName: name
|
2010-12-30 15:32:51 +01:00
|
|
|
inContainer: parentFolder];
|
2010-11-19 22:11:01 +01:00
|
|
|
[newEntry setIsNew: YES];
|
|
|
|
|
|
|
|
return newEntry;
|
|
|
|
}
|
|
|
|
|
2010-12-30 15:32:51 +01:00
|
|
|
- (Class) messageTableClass
|
2010-12-13 18:06:22 +01:00
|
|
|
{
|
2010-12-30 15:32:51 +01:00
|
|
|
return [MAPIStoreCalendarMessageTable class];
|
2010-12-03 23:31:56 +01:00
|
|
|
}
|
|
|
|
|
2011-02-04 04:50:21 +01:00
|
|
|
- (int) openMessage: (struct mapistore_message *) msg
|
|
|
|
forKey: (NSString *) childKey
|
|
|
|
inTable: (MAPIStoreTable *) table
|
|
|
|
{
|
|
|
|
NSString *name, *email;
|
|
|
|
NSArray *attendees;
|
|
|
|
iCalPerson *person;
|
|
|
|
id event;
|
|
|
|
struct SRowSet *recipients;
|
|
|
|
int count, max, rc;
|
|
|
|
|
|
|
|
rc = [super openMessage: msg forKey: childKey inTable: table];
|
|
|
|
|
|
|
|
if (rc == MAPI_E_SUCCESS && table == messageTable)
|
|
|
|
{
|
|
|
|
event = [[table lookupChild: childKey] component: NO secure: NO];
|
|
|
|
attendees = [event attendees];
|
|
|
|
max = [attendees count];
|
|
|
|
|
|
|
|
recipients = msg->recipients;
|
|
|
|
recipients->cRows = max;
|
|
|
|
recipients->aRow = talloc_array (recipients, struct SRow, max);
|
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
recipients->aRow[count].ulAdrEntryPad = 0;
|
|
|
|
recipients->aRow[count].cValues = 3;
|
|
|
|
recipients->aRow[count].lpProps = talloc_array (recipients->aRow,
|
|
|
|
struct SPropValue,
|
|
|
|
3);
|
|
|
|
|
|
|
|
// TODO (0x01 = primary recipient)
|
|
|
|
set_SPropValue_proptag (&(recipients->aRow[count].lpProps[0]),
|
|
|
|
PR_RECIPIENT_TYPE,
|
|
|
|
MAPILongValue (memCtx, 0x01));
|
|
|
|
|
|
|
|
person = [attendees objectAtIndex: count];
|
|
|
|
|
|
|
|
name = [person cn];
|
|
|
|
if (!name)
|
|
|
|
name = @"";
|
|
|
|
|
|
|
|
email = [person email];
|
|
|
|
if (!email)
|
|
|
|
email = @"";
|
|
|
|
|
|
|
|
set_SPropValue_proptag (&(recipients->aRow[count].lpProps[1]),
|
|
|
|
PR_DISPLAY_NAME,
|
|
|
|
[name asUnicodeInMemCtx: recipients->aRow[count].lpProps]);
|
|
|
|
set_SPropValue_proptag (&(recipients->aRow[count].lpProps[2]),
|
|
|
|
PR_EMAIL_ADDRESS,
|
|
|
|
[email asUnicodeInMemCtx: recipients->aRow[count].lpProps]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@end
|