2011-02-24 21:30:01 +01:00
|
|
|
/* MAPIStoreCalendarMessage.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 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
|
2011-08-12 17:02:01 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2011-02-24 21:30:01 +01: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.
|
|
|
|
*/
|
|
|
|
|
2011-03-21 02:01:06 +01:00
|
|
|
/* TODO:
|
|
|
|
- merge common code with tasks
|
|
|
|
- take the tz definitions from Outlook */
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
#include <talloc.h>
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2011-05-30 23:12:56 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2011-03-21 02:01:06 +01:00
|
|
|
#import <Foundation/NSData.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2011-03-22 22:28:16 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <NGCards/iCalEvent.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
#import <NGCards/iCalDateTime.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
#import <NGCards/iCalTimeZone.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <Appointments/SOGoAppointmentObject.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
#import <Appointments/iCalEntityObject+SOGo.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
#import "MAPIStoreAppointmentWrapper.h"
|
2011-04-01 00:59:12 +02:00
|
|
|
#import "MAPIStoreCalendarAttachment.h"
|
2011-08-12 20:41:25 +02:00
|
|
|
#import "MAPIStoreCalendarFolder.h"
|
2011-02-24 21:30:01 +01:00
|
|
|
#import "MAPIStoreContext.h"
|
2011-04-01 00:59:12 +02:00
|
|
|
#import "MAPIStoreRecurrenceUtils.h"
|
2011-02-24 21:30:01 +01:00
|
|
|
#import "MAPIStoreTypes.h"
|
2011-05-30 23:12:56 +02:00
|
|
|
#import "NSDate+MAPIStore.h"
|
2011-03-21 02:01:06 +01:00
|
|
|
#import "NSData+MAPIStore.h"
|
2011-07-20 20:28:37 +02:00
|
|
|
#import "NSObject+MAPIStore.h"
|
2011-02-24 21:30:01 +01:00
|
|
|
#import "NSString+MAPIStore.h"
|
2011-04-01 00:59:12 +02:00
|
|
|
#import "NSValue+MAPIStore.h"
|
2011-02-24 21:30:01 +01:00
|
|
|
|
|
|
|
#import "MAPIStoreCalendarMessage.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <gen_ndr/exchange.h>
|
2011-03-21 02:01:06 +01:00
|
|
|
#include <gen_ndr/property.h>
|
|
|
|
#include <libmapi/libmapi.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#include <mapistore/mapistore.h>
|
2011-04-01 00:59:12 +02:00
|
|
|
#include <mapistore/mapistore_errors.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#include <mapistore/mapistore_nameid.h>
|
|
|
|
|
2011-03-22 22:28:16 +01:00
|
|
|
// extern void ndr_print_AppointmentRecurrencePattern(struct ndr_print *ndr, const char *name, const struct AppointmentRecurrencePattern *r);
|
|
|
|
|
2011-09-23 17:36:49 +02:00
|
|
|
@implementation SOGoAppointmentObject (MAPIStoreExtension)
|
|
|
|
|
|
|
|
- (Class) mapistoreMessageClass
|
|
|
|
{
|
|
|
|
return [MAPIStoreCalendarMessage class];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
@implementation MAPIStoreCalendarMessage
|
|
|
|
|
2011-03-22 22:28:16 +01:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
appointmentWrapper = nil;
|
2011-03-22 22:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[appointmentWrapper release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreAppointmentWrapper *) appointmentWrapper
|
2011-02-24 21:30:01 +01:00
|
|
|
{
|
2011-06-07 02:17:46 +02:00
|
|
|
iCalEvent *event;
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
if (!appointmentWrapper)
|
|
|
|
{
|
|
|
|
event = [sogoObject component: NO secure: NO];
|
|
|
|
ASSIGN (appointmentWrapper,
|
|
|
|
[MAPIStoreAppointmentWrapper wrapperWithICalEvent: event
|
|
|
|
inTimeZone: [self ownerTimeZone]]);
|
|
|
|
}
|
2011-04-13 21:59:04 +02:00
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
return appointmentWrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* getters */
|
|
|
|
- (int) getPrIconIndex: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
return [[self appointmentWrapper] getPrIconIndex: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrMessageClass: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrMessageClass: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
- (int) getPrOwnerApptId: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
return [[self appointmentWrapper] getPrOwnerApptId: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2011-04-13 21:59:04 +02:00
|
|
|
- (int) getPrStartDate: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrStartDate: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
- (int) getPidLidAppointmentStateFlags: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentStateFlags: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2011-04-13 21:59:04 +02:00
|
|
|
- (int) getPidLidAppointmentStartWhole: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentStartWhole: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidCommonStart: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidCommonStart: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrEndDate: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrEndDate: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidAppointmentEndWhole: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentEndWhole: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidCommonEnd: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidCommonEnd: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidAppointmentDuration: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentDuration: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidAppointmentSubType: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentSubType: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidBusyStatus: (void **) data // TODO
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidBusyStatus: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-04-13 21:59:04 +02:00
|
|
|
- (int) getPrSubject: (void **) data // SUMMARY
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrSubject: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidLocation: (void **) data // LOCATION
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidLocation: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidPrivate: (void **) data // private (bool), should depend on CLASS and permissions
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidPrivate: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrSensitivity: (void **) data // not implemented, depends on CLASS
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrSensitivity: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPrImportance: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPrImportance: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidIsRecurring: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidIsRecurring: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) getPidLidRecurring: (void **) data
|
2011-07-11 23:40:47 +02:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidRecurring: data inMemCtx: memCtx];
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
- (int) getPidLidAppointmentRecur: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-07-19 23:47:01 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidAppointmentRecur: data
|
|
|
|
inMemCtx: memCtx];
|
2011-07-19 23:47:01 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
- (int) getPidLidGlobalObjectId: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-07-19 23:47:01 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidGlobalObjectId: data
|
|
|
|
inMemCtx: memCtx];
|
2011-07-19 23:47:01 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
- (int) getPidLidCleanGlobalObjectId: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2011-07-21 17:05:17 +02:00
|
|
|
return [[self appointmentWrapper] getPidLidCleanGlobalObjectId: data
|
|
|
|
inMemCtx: memCtx];
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
|
|
|
|
2011-07-13 23:41:58 +02:00
|
|
|
- (void) getMessageData: (struct mapistore_message **) dataPtr
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-02-24 21:30:01 +01:00
|
|
|
{
|
2011-06-07 02:17:46 +02:00
|
|
|
NSString *text;
|
2011-02-24 21:30:01 +01:00
|
|
|
NSArray *attendees;
|
|
|
|
iCalPerson *person;
|
|
|
|
struct SRowSet *recipients;
|
|
|
|
int count, max;
|
2011-06-07 02:17:46 +02:00
|
|
|
iCalEvent *event;
|
2011-07-13 23:41:58 +02:00
|
|
|
struct mapistore_message *msgData;
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-07-13 23:41:58 +02:00
|
|
|
[super getMessageData: &msgData inMemCtx: memCtx];
|
2011-06-07 02:17:46 +02:00
|
|
|
|
|
|
|
event = [sogoObject component: NO secure: NO];
|
2011-02-24 21:30:01 +01:00
|
|
|
attendees = [event attendees];
|
|
|
|
max = [attendees count];
|
|
|
|
|
2011-07-13 23:41:58 +02:00
|
|
|
recipients = talloc_zero (msgData, struct SRowSet);
|
2011-02-24 21:30:01 +01:00
|
|
|
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,
|
2011-06-07 02:17:46 +02:00
|
|
|
4);
|
2011-02-24 21:30:01 +01:00
|
|
|
|
|
|
|
// TODO (0x01 = primary recipient)
|
2011-06-07 02:17:46 +02:00
|
|
|
set_SPropValue_proptag (recipients->aRow[count].lpProps,
|
2011-02-24 21:30:01 +01:00
|
|
|
PR_RECIPIENT_TYPE,
|
2011-06-07 02:17:46 +02:00
|
|
|
MAPILongValue (recipients->aRow[count].lpProps, 0x01));
|
|
|
|
|
|
|
|
set_SPropValue_proptag (recipients->aRow[count].lpProps + 1,
|
|
|
|
PR_ADDRTYPE_UNICODE,
|
|
|
|
[@"SMTP" asUnicodeInMemCtx: recipients->aRow]);
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
person = [attendees objectAtIndex: count];
|
2011-06-07 02:17:46 +02:00
|
|
|
text = [person rfc822Email];
|
|
|
|
if (!text)
|
|
|
|
text = @"";
|
|
|
|
set_SPropValue_proptag (recipients->aRow[count].lpProps + 2,
|
|
|
|
PR_EMAIL_ADDRESS_UNICODE,
|
|
|
|
[text asUnicodeInMemCtx: recipients->aRow]);
|
|
|
|
|
|
|
|
text = [person cn];
|
|
|
|
if ([text length] > 0)
|
|
|
|
{
|
|
|
|
recipients->aRow[count].cValues++;
|
|
|
|
set_SPropValue_proptag (recipients->aRow[count].lpProps + 3,
|
|
|
|
PR_DISPLAY_NAME_UNICODE,
|
|
|
|
[text asUnicodeInMemCtx: recipients->aRow]);
|
|
|
|
}
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
2011-07-13 23:41:58 +02:00
|
|
|
msgData->recipients = recipients;
|
|
|
|
*dataPtr = msgData;
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
|
|
|
|
2011-07-19 23:47:01 +02:00
|
|
|
- (void) _setupRecurrenceInCalendar: (iCalCalendar *) calendar
|
2011-09-23 20:16:46 +02:00
|
|
|
withEvent: (iCalEvent *) event
|
2011-07-19 23:47:01 +02:00
|
|
|
fromData: (NSData *) mapiRecurrenceData
|
|
|
|
{
|
|
|
|
struct Binary_r *blob;
|
|
|
|
struct AppointmentRecurrencePattern *pattern;
|
|
|
|
NSMutableArray *otherEvents;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
otherEvents = [[calendar events] mutableCopy];
|
|
|
|
[otherEvents removeObject: event];
|
|
|
|
[calendar removeChildren: otherEvents];
|
|
|
|
[otherEvents release];
|
|
|
|
|
|
|
|
blob = [mapiRecurrenceData asBinaryInMemCtx: NULL];
|
|
|
|
pattern = get_AppointmentRecurrencePattern (blob, blob);
|
|
|
|
[calendar setupRecurrenceWithMasterEntity: event
|
|
|
|
fromRecurrencePattern: &pattern->RecurrencePattern];
|
|
|
|
talloc_free (blob);
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
- (void) save
|
|
|
|
{
|
|
|
|
iCalCalendar *vCalendar;
|
|
|
|
iCalDateTime *start, *end;
|
2011-03-22 22:28:16 +01:00
|
|
|
iCalTimeZone *tz;
|
|
|
|
NSCalendarDate *now;
|
2011-09-20 01:33:48 +02:00
|
|
|
NSString *content, *tzName, *priority;
|
2011-04-13 21:59:04 +02:00
|
|
|
iCalEvent *newEvent;
|
2011-08-08 21:02:49 +02:00
|
|
|
iCalPerson *userPerson;
|
2011-07-21 17:05:17 +02:00
|
|
|
NSUInteger responseStatus = 0;
|
2011-08-08 21:02:49 +02:00
|
|
|
SOGoUser *activeUser;
|
2011-03-22 22:28:16 +01:00
|
|
|
id value;
|
2011-02-24 21:30:01 +01:00
|
|
|
|
|
|
|
[self logWithFormat: @"-save, event props:"];
|
|
|
|
// MAPIStoreDumpMessageProperties (newProperties);
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
now = [NSCalendarDate date];
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
content = [sogoObject contentAsString];
|
|
|
|
if (![content length])
|
|
|
|
{
|
2011-04-13 21:59:04 +02:00
|
|
|
newEvent = [sogoObject component: YES secure: NO];
|
2011-06-07 02:17:46 +02:00
|
|
|
vCalendar = [newEvent parent];
|
2011-02-24 21:30:01 +01:00
|
|
|
[vCalendar setProdID: @"-//Inverse inc.//OpenChange+SOGo//EN"];
|
|
|
|
content = [vCalendar versitString];
|
2011-08-08 21:02:49 +02:00
|
|
|
[newEvent setCreated: now];
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vCalendar = [iCalCalendar parseSingleFromSource: content];
|
2011-04-13 21:59:04 +02:00
|
|
|
newEvent = [[vCalendar events] objectAtIndex: 0];
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
activeUser = [[self context] activeUser];
|
|
|
|
userPerson = [newEvent userAsAttendee: activeUser];
|
|
|
|
[newEvent setTimeStampAsDate: now];
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
if (userPerson)
|
2011-02-24 21:30:01 +01:00
|
|
|
{
|
2011-08-08 21:02:49 +02:00
|
|
|
// iCalPersonPartStat newPartStat;
|
|
|
|
NSString *newPartStat;
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
value
|
|
|
|
= [newProperties objectForKey: MAPIPropertyKey (PidLidResponseStatus)];
|
|
|
|
if (value)
|
|
|
|
responseStatus = [value unsignedLongValue];
|
|
|
|
|
|
|
|
switch (responseStatus)
|
|
|
|
{
|
|
|
|
case 0x02: /* respTentative */
|
|
|
|
// newPartStat = iCalPersonPartStatTentative;
|
|
|
|
newPartStat = @"TENTATIVE";
|
|
|
|
break;
|
|
|
|
case 0x03: /* respAccepted */
|
|
|
|
// newPartStat = iCalPersonPartStatAccepted;
|
|
|
|
newPartStat = @"ACCEPTED";
|
|
|
|
break;
|
|
|
|
case 0x04: /* respDeclined */
|
|
|
|
// newPartStat = iCalPersonPartStatDeclined;
|
|
|
|
newPartStat = @"DECLINED";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newPartStat = nil;
|
|
|
|
}
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
if (newPartStat // != iCalPersonPartStatUndefined
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// iCalPerson *participant;
|
2011-07-21 17:05:17 +02:00
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
// participant = [newEvent userAsAttendee: activeUser];
|
|
|
|
// [participant setParticipationStatus: newPartStat];
|
|
|
|
// [sogoObject saveComponent: newEvent];
|
|
|
|
|
|
|
|
[sogoObject changeParticipationStatus: newPartStat
|
|
|
|
withDelegate: nil];
|
|
|
|
// [[self context] tearDownRequest];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-02-24 21:30:01 +01:00
|
|
|
{
|
2011-08-08 21:02:49 +02:00
|
|
|
[newEvent setLastModified: now];
|
|
|
|
|
|
|
|
// summary
|
|
|
|
value = [newProperties
|
|
|
|
objectForKey: MAPIPropertyKey (PR_NORMALIZED_SUBJECT_UNICODE)];
|
|
|
|
if (value)
|
|
|
|
[newEvent setSummary: value];
|
|
|
|
|
|
|
|
// Location
|
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey (PidLidLocation)];
|
|
|
|
if (value)
|
|
|
|
[newEvent setLocation: value];
|
|
|
|
|
|
|
|
tzName = [[self ownerTimeZone] name];
|
|
|
|
tz = [iCalTimeZone timeZoneForName: tzName];
|
|
|
|
[vCalendar addTimeZone: tz];
|
|
|
|
|
|
|
|
// start
|
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey (PR_START_DATE)];
|
|
|
|
if (!value)
|
|
|
|
value = [newProperties
|
|
|
|
objectForKey: MAPIPropertyKey (PidLidAppointmentStartWhole)];
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
start = (iCalDateTime *) [newEvent uniqueChildWithTag: @"dtstart"];
|
|
|
|
[start setTimeZone: tz];
|
|
|
|
[start setDateTime: value];
|
|
|
|
}
|
|
|
|
|
2011-09-20 01:33:48 +02:00
|
|
|
/* end */
|
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey(PR_END_DATE)];
|
2011-08-08 21:02:49 +02:00
|
|
|
if (!value)
|
2011-09-20 01:33:48 +02:00
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey(PidLidAppointmentEndWhole)];
|
2011-08-08 21:02:49 +02:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
end = (iCalDateTime *) [newEvent uniqueChildWithTag: @"dtend"];
|
|
|
|
[end setTimeZone: tz];
|
|
|
|
[end setDateTime: value];
|
|
|
|
}
|
|
|
|
|
2011-09-20 01:33:48 +02:00
|
|
|
/* priority */
|
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey(PR_IMPORTANCE)];
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
switch ([value intValue])
|
|
|
|
{
|
|
|
|
case 0: // IMPORTANCE_LOW
|
|
|
|
priority = @"9";
|
|
|
|
break;
|
|
|
|
case 2: // IMPORTANCE_HIGH
|
|
|
|
priority = @"1";
|
|
|
|
break;
|
|
|
|
default: // IMPORTANCE_NORMAL
|
|
|
|
priority = @"5";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priority = @"0"; // None
|
|
|
|
[newEvent setPriority: priority];
|
|
|
|
|
|
|
|
/* show time as free/busy/tentative/out of office. Possible values are:
|
|
|
|
0x00000000 - olFree
|
|
|
|
0x00000001 - olTentative
|
|
|
|
0x00000002 - olBusy
|
|
|
|
0x00000003 - olOutOfOffice */
|
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey(PidLidBusyStatus)];
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
switch ([value intValue])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
[newEvent setTransparency: @"TRANSPARENT"];
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
[newEvent setTransparency: @"OPAQUE"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
/* recurrence */
|
|
|
|
value = [newProperties
|
|
|
|
objectForKey: MAPIPropertyKey (PidLidAppointmentRecur)];
|
|
|
|
if (value)
|
|
|
|
[self _setupRecurrenceInCalendar: vCalendar
|
2011-09-23 20:16:46 +02:00
|
|
|
withEvent: newEvent
|
2011-08-08 21:02:49 +02:00
|
|
|
fromData: value];
|
|
|
|
|
|
|
|
// Organizer
|
2011-07-21 17:05:17 +02:00
|
|
|
value = [newProperties objectForKey: @"recipients"];
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
NSArray *recipients;
|
|
|
|
NSDictionary *dict;
|
|
|
|
iCalPerson *person;
|
|
|
|
int i;
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
dict = [activeUser primaryIdentity];
|
2011-07-21 17:05:17 +02:00
|
|
|
person = [iCalPerson new];
|
|
|
|
[person setCn: [dict objectForKey: @"fullName"]];
|
|
|
|
[person setEmail: [dict objectForKey: @"email"]];
|
|
|
|
[newEvent setOrganizer: person];
|
|
|
|
[person release];
|
|
|
|
|
|
|
|
recipients = [value objectForKey: @"to"];
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
for (i = 0; i < [recipients count]; i++)
|
|
|
|
{
|
|
|
|
dict = [recipients objectAtIndex: i];
|
|
|
|
person = [iCalPerson new];
|
|
|
|
|
|
|
|
[person setCn: [dict objectForKey: @"fullName"]];
|
|
|
|
[person setEmail: [dict objectForKey: @"email"]];
|
|
|
|
[person setParticipationStatus: iCalPersonPartStatNeedsAction];
|
|
|
|
[person setRsvp: @"TRUE"];
|
2011-09-20 21:37:03 +02:00
|
|
|
[person setRole: @"REQ-PARTICIPANT"];
|
2011-07-21 17:05:17 +02:00
|
|
|
|
|
|
|
// FIXME: We must NOT always rely on this
|
|
|
|
if (![newEvent isAttendee: [person rfc822Email]])
|
|
|
|
[newEvent addToAttendees: person];
|
2011-08-08 21:02:49 +02:00
|
|
|
|
2011-07-21 17:05:17 +02:00
|
|
|
[person release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 21:02:49 +02:00
|
|
|
[sogoObject saveComponent: newEvent];
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
2011-08-12 20:41:25 +02:00
|
|
|
[(MAPIStoreCalendarFolder *) container synchroniseCache];
|
2011-09-20 21:37:03 +02:00
|
|
|
value = [newProperties objectForKey: MAPIPropertyKey (PR_CHANGE_KEY)];
|
|
|
|
if (value)
|
|
|
|
[(MAPIStoreCalendarFolder *) container
|
|
|
|
setChangeKey: value forMessageWithKey: [self nameInContainer]];
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
|
|
|
|
2011-07-26 21:02:45 +02:00
|
|
|
- (id) lookupAttachment: (NSString *) childKey
|
2011-03-22 22:28:16 +01:00
|
|
|
{
|
|
|
|
return [attachmentParts objectForKey: childKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MAPIStoreAttachment *) createAttachment
|
|
|
|
{
|
2011-04-01 00:59:12 +02:00
|
|
|
MAPIStoreCalendarAttachment *newAttachment;
|
|
|
|
uint32_t newAid;
|
|
|
|
NSString *newKey;
|
|
|
|
|
2011-07-26 22:13:10 +02:00
|
|
|
newAid = [[self attachmentKeys] count];
|
2011-04-01 00:59:12 +02:00
|
|
|
|
|
|
|
newAttachment = [MAPIStoreCalendarAttachment
|
|
|
|
mapiStoreObjectWithSOGoObject: nil
|
|
|
|
inContainer: self];
|
|
|
|
[newAttachment setIsNew: YES];
|
|
|
|
[newAttachment setAID: newAid];
|
|
|
|
newKey = [NSString stringWithFormat: @"%ul", newAid];
|
2011-03-22 22:28:16 +01:00
|
|
|
[attachmentParts setObject: newAttachment
|
2011-04-01 00:59:12 +02:00
|
|
|
forKey: newKey];
|
2011-07-26 22:13:10 +02:00
|
|
|
[attachmentKeys release];
|
|
|
|
attachmentKeys = nil;
|
2011-03-22 22:28:16 +01:00
|
|
|
|
|
|
|
return newAttachment;
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
@end
|