2011-02-24 21:30:01 +01:00
|
|
|
/* MAPIStoreCalendarMessage.m - this file is part of SOGo
|
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-02-24 21:30:01 +01:00
|
|
|
*
|
|
|
|
* 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-11-09 16:02:29 +01:00
|
|
|
#include <util/attr.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
|
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>
|
2012-08-16 23:05:16 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
#import <EOControl/EOFetchSpecification.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2012-08-16 23:05:16 +02:00
|
|
|
#import <GDLContentStore/GCSFolder.h>
|
2011-10-11 21:46:02 +02:00
|
|
|
#import <NGCards/iCalAlarm.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-10-11 21:46:02 +02:00
|
|
|
#import <NGCards/iCalTrigger.h>
|
2011-12-01 22:13:09 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2012-08-16 18:32:52 +02:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2011-10-03 22:55:02 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
#import <Appointments/SOGoAppointmentObject.h>
|
2011-07-21 17:05:17 +02:00
|
|
|
#import <Appointments/iCalEntityObject+SOGo.h>
|
2011-11-09 21:47:08 +01:00
|
|
|
#import <Mailer/NSString+Mail.h>
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
#import "iCalEvent+MAPIStore.h"
|
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-10-03 22:55:02 +02:00
|
|
|
#import "MAPIStoreMapping.h"
|
2011-04-01 00:59:12 +02:00
|
|
|
#import "MAPIStoreRecurrenceUtils.h"
|
2011-02-24 21:30:01 +01:00
|
|
|
#import "MAPIStoreTypes.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.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);
|
|
|
|
|
2015-02-15 18:39:43 +01:00
|
|
|
static Class NSArrayK, MAPIStoreAppointmentWrapperK;
|
2012-08-16 23:05:16 +02:00
|
|
|
|
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
|
|
|
|
|
2012-08-16 23:05:16 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSArrayK = [NSArray class];
|
2015-02-15 18:39:43 +01:00
|
|
|
MAPIStoreAppointmentWrapperK = [MAPIStoreAppointmentWrapper class];
|
2012-08-16 23:05:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 16:36:05 +02:00
|
|
|
+ (enum mapistore_error) getAvailableProperties: (struct SPropTagArray **) propertiesP
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
BOOL listedProperties[65536];
|
|
|
|
NSUInteger count;
|
2012-10-10 14:42:44 +02:00
|
|
|
uint16_t propId;
|
2012-07-20 16:36:05 +02:00
|
|
|
|
|
|
|
memset (listedProperties, NO, 65536 * sizeof (BOOL));
|
|
|
|
[super getAvailableProperties: propertiesP inMemCtx: memCtx];
|
|
|
|
for (count = 0; count < (*propertiesP)->cValues; count++)
|
2012-10-10 14:42:44 +02:00
|
|
|
{
|
|
|
|
propId = ((*propertiesP)->aulPropTag[count] >> 16) & 0xffff;
|
|
|
|
listedProperties[propId] = YES;
|
|
|
|
}
|
2012-07-20 16:36:05 +02:00
|
|
|
[MAPIStoreAppointmentWrapper fillAvailableProperties: *propertiesP
|
|
|
|
withExclusions: listedProperties];
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
calendar = nil;
|
|
|
|
masterEvent = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:44:25 +02:00
|
|
|
- (void) _setupAttachmentParts
|
|
|
|
{
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSArray *events;
|
|
|
|
NSString *newKey;
|
|
|
|
MAPIStoreCalendarAttachment *attachment;
|
|
|
|
NSUInteger aid;
|
2012-08-06 21:20:07 +02:00
|
|
|
iCalEvent *event;
|
2012-07-20 17:44:25 +02:00
|
|
|
|
|
|
|
events = [calendar events];
|
|
|
|
max = [events count];
|
|
|
|
for (count = 1; count < max; count++)
|
|
|
|
{
|
|
|
|
attachment = [MAPIStoreCalendarAttachment
|
|
|
|
mapiStoreObjectInContainer: self];
|
|
|
|
/* we now that there are no attachments yet, so we can assume that the
|
|
|
|
right AID is 0 from the start */
|
|
|
|
aid = count - 1;
|
|
|
|
[attachment setAID: aid];
|
2012-08-06 21:20:07 +02:00
|
|
|
event = [events objectAtIndex: count];
|
|
|
|
[attachment setEvent: event];
|
|
|
|
newKey = [[event uniqueChildWithTag: @"recurrence-id"]
|
|
|
|
flattenedValuesForKey: @""];
|
2012-07-20 17:44:25 +02:00
|
|
|
[attachmentParts setObject: attachment forKey: newKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:26:33 +02:00
|
|
|
- (id) initWithSOGoObject: (id) newSOGoObject
|
|
|
|
inContainer: (MAPIStoreObject *) newFolder
|
2011-02-24 21:30:01 +01:00
|
|
|
{
|
2011-11-17 17:15:38 +01:00
|
|
|
MAPIStoreContext *context;
|
2012-01-29 20:55:21 +01:00
|
|
|
MAPIStoreUserContext *userContext;
|
2012-07-20 17:42:52 +02:00
|
|
|
iCalCalendar *origCalendar;
|
2012-07-19 22:26:33 +02:00
|
|
|
MAPIStoreAppointmentWrapper *appointmentWrapper;
|
2012-07-20 17:42:52 +02:00
|
|
|
|
2012-07-19 22:26:33 +02:00
|
|
|
if ((self = [super initWithSOGoObject: newSOGoObject
|
|
|
|
inContainer: newFolder]))
|
2011-07-21 17:05:17 +02:00
|
|
|
{
|
2012-07-20 17:42:52 +02:00
|
|
|
if ([newSOGoObject isNew])
|
|
|
|
{
|
|
|
|
ASSIGN (calendar, [iCalCalendar groupWithTag: @"vcalendar"]);
|
|
|
|
[calendar setVersion: @"2.0"];
|
|
|
|
[calendar setProdID: @"-//Inverse inc.//OpenChange+SOGo//EN"];
|
|
|
|
masterEvent = [iCalEvent groupWithTag: @"vevent"];
|
|
|
|
[calendar addChild: masterEvent];
|
|
|
|
[masterEvent setCreated: [NSCalendarDate date]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
origCalendar = [sogoObject calendar: YES secure: YES];
|
2015-03-23 23:57:33 +01:00
|
|
|
if (!origCalendar)
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"Incorrect calendar event %@. Empty message is created",
|
|
|
|
[self url]];
|
|
|
|
return self;
|
|
|
|
}
|
2012-07-20 17:42:52 +02:00
|
|
|
calendar = [origCalendar mutableCopy];
|
|
|
|
masterEvent = [[calendar events] objectAtIndex: 0];
|
2012-07-20 17:44:25 +02:00
|
|
|
[self _setupAttachmentParts];
|
2012-07-20 17:42:52 +02:00
|
|
|
}
|
2011-11-17 17:15:38 +01:00
|
|
|
context = [self context];
|
2012-01-29 20:55:21 +01:00
|
|
|
userContext = [self userContext];
|
2012-07-19 22:26:33 +02:00
|
|
|
appointmentWrapper
|
2012-07-20 17:42:52 +02:00
|
|
|
= [MAPIStoreAppointmentWrapper wrapperWithICalEvent: masterEvent
|
2012-07-19 22:26:33 +02:00
|
|
|
andUser: [userContext sogoUser]
|
|
|
|
andSenderEmail: nil
|
|
|
|
withConnectionInfo: [context connectionInfo]];
|
|
|
|
[self addProxy: appointmentWrapper];
|
2011-07-21 17:05:17 +02:00
|
|
|
}
|
2012-07-20 17:42:52 +02:00
|
|
|
|
2012-07-19 22:26:33 +02:00
|
|
|
return self;
|
2011-07-21 17:05:17 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2013-03-13 20:04:11 +01:00
|
|
|
//NSLog(@"MAPIStoreCalendarMessage: -dealloc (%p)", self);
|
2012-07-20 17:42:52 +02:00
|
|
|
[calendar release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2015-02-15 18:39:43 +01:00
|
|
|
- (MAPIStoreAppointmentWrapper *) _appointmentWrapper
|
2011-10-03 22:55:02 +02:00
|
|
|
{
|
2015-02-15 18:39:43 +01:00
|
|
|
NSUInteger i, max;
|
|
|
|
id proxy;
|
|
|
|
max = [proxies count];
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
proxy = [proxies objectAtIndex: i];
|
|
|
|
if ([proxy isKindOfClass: MAPIStoreAppointmentWrapperK])
|
|
|
|
{
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
2011-10-03 22:55:02 +02:00
|
|
|
}
|
|
|
|
|
2015-02-15 18:39:43 +01:00
|
|
|
|
|
|
|
/* getters */
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagMessageClass: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-13 21:59:04 +02:00
|
|
|
{
|
2012-09-06 21:09:05 +02:00
|
|
|
SOGoUser *owner;
|
2012-08-17 22:12:50 +02:00
|
|
|
|
2012-09-06 21:09:05 +02:00
|
|
|
owner = [[self userContext] sogoUser];
|
|
|
|
if ([masterEvent userAsAttendee: owner])
|
|
|
|
*data = talloc_strdup (memCtx, "IPM.Schedule.Meeting.Request");
|
|
|
|
else
|
2012-08-17 22:12:50 +02:00
|
|
|
*data = talloc_strdup (memCtx, "IPM.Appointment");
|
2011-10-03 22:55:02 +02:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
2011-04-13 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
- (int) getPidLidSideEffects: (void **) data // TODO
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
*data = MAPILongValue (memCtx,
|
|
|
|
seOpenToDelete | seOpenToCopy | seOpenToMove
|
|
|
|
| seCoerceToInbox | seOpenForCtxMenu);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagProcessed: (void **) data inMemCtx: (TALLOC_CTX *) memCtx
|
2011-10-03 22:55:02 +02:00
|
|
|
{
|
|
|
|
return [self getYes: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-08-16 18:32:52 +02:00
|
|
|
static NSString *recTypes[] = {@"orig", @"to", @"cc", @"bcc"};
|
|
|
|
static NSInteger recTypesValue[] = {MAPI_ORIG, MAPI_TO, MAPI_CC, MAPI_BCC};
|
2011-07-13 23:41:58 +02:00
|
|
|
struct mapistore_message *msgData;
|
2012-08-16 18:32:52 +02:00
|
|
|
NSDictionary *recipients, *contactInfos;
|
|
|
|
NSString *email;
|
|
|
|
NSArray *attendees;
|
|
|
|
NSDictionary *attendee;
|
|
|
|
SOGoUserManager *mgr;
|
|
|
|
struct mapistore_message_recipient *recipient;
|
|
|
|
NSUInteger nRecType, maxRecTypes, count, max, propCount;
|
|
|
|
NSObject *currentValue;
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-07-13 23:41:58 +02:00
|
|
|
[super getMessageData: &msgData inMemCtx: memCtx];
|
2012-08-16 18:32:52 +02:00
|
|
|
|
|
|
|
/* The presence of the "recipients" meta-property means that our most recent
|
|
|
|
list of recipients has not been saved yet and that we must return that
|
|
|
|
one instead of the one stored in the event. */
|
|
|
|
recipients = [properties objectForKey: @"recipients"];
|
|
|
|
if (recipients)
|
|
|
|
{
|
|
|
|
mgr = [SOGoUserManager sharedUserManager];
|
|
|
|
|
|
|
|
/* TODO: this code might need to be moved into MAPIStoreMessage */
|
|
|
|
msgData->columns = set_SPropTagArray (msgData, 9,
|
|
|
|
PR_OBJECT_TYPE,
|
|
|
|
PR_DISPLAY_TYPE,
|
|
|
|
PR_7BIT_DISPLAY_NAME_UNICODE,
|
|
|
|
PR_SMTP_ADDRESS_UNICODE,
|
|
|
|
PR_SEND_INTERNET_ENCODING,
|
|
|
|
PR_RECIPIENT_DISPLAY_NAME_UNICODE,
|
|
|
|
PR_RECIPIENT_FLAGS,
|
|
|
|
PR_RECIPIENT_ENTRYID,
|
|
|
|
PR_RECIPIENT_TRACKSTATUS);
|
|
|
|
|
|
|
|
maxRecTypes = sizeof(recTypes) / sizeof(recTypes[0]);
|
|
|
|
for (nRecType = 0; nRecType < maxRecTypes; nRecType++)
|
|
|
|
{
|
|
|
|
attendees = [recipients objectForKey: recTypes[nRecType]];
|
|
|
|
max = [attendees count];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
msgData->recipients_count += max;
|
|
|
|
msgData->recipients = talloc_realloc(msgData,
|
|
|
|
msgData->recipients, struct
|
|
|
|
mapistore_message_recipient, msgData->recipients_count);
|
|
|
|
recipient = msgData->recipients;
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
attendee = [attendees objectAtIndex: count];
|
|
|
|
recipient->type = recTypesValue[nRecType];
|
|
|
|
email = [attendee objectForKey: @"email"];
|
|
|
|
if (email)
|
|
|
|
{
|
|
|
|
contactInfos
|
|
|
|
= [mgr contactInfosForUserWithUIDorEmail: email];
|
|
|
|
recipient->username = [[contactInfos
|
|
|
|
objectForKey: @"c_uid"]
|
|
|
|
asUnicodeInMemCtx: msgData];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
recipient->username = NULL;
|
|
|
|
|
|
|
|
recipient->data = talloc_array(msgData, void *,
|
|
|
|
msgData->columns->cValues);
|
|
|
|
for (propCount = 0;
|
|
|
|
propCount < msgData->columns->cValues;
|
|
|
|
propCount++)
|
|
|
|
{
|
|
|
|
currentValue = [attendee objectForKey: MAPIPropertyKey (msgData->columns->aulPropTag[propCount])];
|
|
|
|
[currentValue getValue: recipient->data + propCount
|
|
|
|
forTag: msgData->columns->aulPropTag[propCount]
|
|
|
|
inMemCtx: msgData];
|
|
|
|
}
|
|
|
|
recipient++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-15 18:39:43 +01:00
|
|
|
[[self _appointmentWrapper] fillMessageData: msgData
|
|
|
|
inMemCtx: memCtx];
|
2012-08-16 18:32:52 +02:00
|
|
|
}
|
2012-07-20 17:42:52 +02:00
|
|
|
|
2011-07-13 23:41:58 +02:00
|
|
|
*dataPtr = msgData;
|
2011-02-24 21:30:01 +01:00
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagResponseRequested: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-10-03 22:55:02 +02:00
|
|
|
{
|
|
|
|
return [self getYes: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2015-02-15 18:41:03 +01:00
|
|
|
/* This three methods: getPidTagNormalizedSubject,
|
|
|
|
getPidTagSensitivity and getPidTagImportance are implemented in
|
|
|
|
MAPIStoreMessage base class, then the proxy method is not reached
|
|
|
|
(see MAPIStoreObject).
|
|
|
|
*/
|
|
|
|
- (int) getPidTagNormalizedSubject: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
MAPIStoreAppointmentWrapper *appointmentWrapper;
|
|
|
|
|
|
|
|
appointmentWrapper = [self _appointmentWrapper];
|
|
|
|
if (appointmentWrapper)
|
|
|
|
return [appointmentWrapper getPidTagNormalizedSubject: data inMemCtx: memCtx];
|
|
|
|
|
|
|
|
return MAPISTORE_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2015-02-15 18:44:47 +01:00
|
|
|
- (int) getPidTagSensitivity: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
MAPIStoreAppointmentWrapper *appointmentWrapper;
|
|
|
|
|
|
|
|
appointmentWrapper = [self _appointmentWrapper];
|
|
|
|
if (appointmentWrapper)
|
|
|
|
return [appointmentWrapper getPidTagSensitivity: data inMemCtx: memCtx];
|
|
|
|
|
|
|
|
return [self getLongZero: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2015-02-15 18:41:03 +01:00
|
|
|
- (int) getPidTagImportance: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
MAPIStoreAppointmentWrapper *appointmentWrapper;
|
|
|
|
|
|
|
|
appointmentWrapper = [self _appointmentWrapper];
|
|
|
|
if (appointmentWrapper)
|
|
|
|
return [appointmentWrapper getPidTagImportance: data inMemCtx: memCtx];
|
|
|
|
|
|
|
|
*data = MAPILongValue (memCtx, 1);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 20:04:11 +01:00
|
|
|
- (NSString *) _uidFromGlobalObjectId: (TALLOC_CTX *) memCtx
|
2011-10-03 22:55:02 +02:00
|
|
|
{
|
|
|
|
NSData *objectId;
|
|
|
|
NSString *uid = nil;
|
|
|
|
char *bytesDup, *uidStart;
|
|
|
|
NSUInteger length;
|
|
|
|
|
|
|
|
/* NOTE: we only handle the generic case at the moment, see
|
|
|
|
MAPIStoreAppointmentWrapper */
|
2012-07-20 17:42:52 +02:00
|
|
|
objectId = [properties
|
|
|
|
objectForKey: MAPIPropertyKey (PidLidGlobalObjectId)];
|
2011-10-03 22:55:02 +02:00
|
|
|
if (objectId)
|
|
|
|
{
|
|
|
|
length = [objectId length];
|
2013-03-13 20:04:11 +01:00
|
|
|
bytesDup = talloc_array (memCtx, char, length + 1);
|
2011-10-03 22:55:02 +02:00
|
|
|
memcpy (bytesDup, [objectId bytes], length);
|
|
|
|
bytesDup[length] = 0;
|
|
|
|
uidStart = bytesDup + length - 1;
|
|
|
|
while (uidStart != bytesDup && *(uidStart - 1))
|
|
|
|
uidStart--;
|
|
|
|
if (uidStart > bytesDup && *uidStart)
|
|
|
|
uid = [NSString stringWithUTF8String: uidStart];
|
|
|
|
talloc_free (bytesDup);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
2012-08-16 23:05:16 +02:00
|
|
|
- (SOGoAppointmentObject *) _resurrectRecord: (NSString *) cname
|
|
|
|
fromFolder: (SOGoAppointmentFolder *) folder
|
|
|
|
{
|
|
|
|
NSArray *records;
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
EOFetchSpecification *fs;
|
|
|
|
GCSFolder *ocsFolder;
|
|
|
|
SOGoAppointmentObject *newObject;
|
|
|
|
NSMutableDictionary *newRecord;
|
|
|
|
static NSArray *childRecordFields = nil;
|
|
|
|
|
|
|
|
if (!childRecordFields)
|
|
|
|
{
|
|
|
|
childRecordFields = [NSArray arrayWithObjects: @"c_name",
|
|
|
|
@"c_creationdate", @"c_lastmodified",
|
|
|
|
@"c_content", nil];
|
|
|
|
[childRecordFields retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
ocsFolder = [folder ocsFolder];
|
|
|
|
|
|
|
|
qualifier
|
|
|
|
= [EOQualifier qualifierWithQualifierFormat:
|
|
|
|
[NSString stringWithFormat: @"c_name='%@'", cname]];
|
|
|
|
fs = [EOFetchSpecification fetchSpecificationWithEntityName: [ocsFolder folderName]
|
|
|
|
qualifier: qualifier
|
|
|
|
sortOrderings: nil];
|
|
|
|
records = [ocsFolder fetchFields: childRecordFields
|
|
|
|
fetchSpecification: fs
|
|
|
|
ignoreDeleted: NO];
|
|
|
|
if ([records isKindOfClass: NSArrayK] && [records count])
|
|
|
|
{
|
|
|
|
newRecord = [[records objectAtIndex: 0] mutableCopy];
|
|
|
|
[newRecord setObject: [NSNumber numberWithInt: 0]
|
|
|
|
forKey: @"c_version"];
|
|
|
|
newObject = [SOGoAppointmentObject objectWithRecord: newRecord
|
|
|
|
inContainer: folder];
|
|
|
|
[newRecord autorelease];
|
|
|
|
[newObject setIsNew: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newObject = nil;
|
|
|
|
|
|
|
|
|
|
|
|
return newObject;
|
|
|
|
}
|
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
- (void) _fixupAppointmentObjectWithUID: (NSString *) uid
|
2011-10-03 22:55:02 +02:00
|
|
|
{
|
2012-03-12 01:06:06 +01:00
|
|
|
NSString *cname, *url;
|
2011-10-03 22:55:02 +02:00
|
|
|
MAPIStoreMapping *mapping;
|
|
|
|
uint64_t objectId;
|
2012-08-16 23:05:16 +02:00
|
|
|
WOContext *woContext;
|
2012-03-12 01:06:06 +01:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
SOGoAppointmentObject *newObject;
|
2011-10-03 22:55:02 +02:00
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
cname = [[container sogoObject] resourceNameForEventUID: uid];
|
|
|
|
if (cname)
|
|
|
|
isNew = NO;
|
|
|
|
else
|
|
|
|
cname = [NSString stringWithFormat: @"%@.ics", uid];
|
2011-10-03 22:55:02 +02:00
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
mapping = [self mapping];
|
|
|
|
|
|
|
|
url = [NSString stringWithFormat: @"%@%@", [container url], cname];
|
2012-08-16 23:05:16 +02:00
|
|
|
folder = [sogoObject container];
|
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
/* reinstantiate the old sogo object and attach it to self */
|
2015-07-14 17:17:51 +02:00
|
|
|
[[self userContext] activate];
|
2012-03-12 01:06:06 +01:00
|
|
|
woContext = [[self userContext] woContext];
|
|
|
|
if (isNew)
|
2012-08-16 18:32:52 +02:00
|
|
|
{
|
2012-08-16 23:05:16 +02:00
|
|
|
/* event could have been deleted, let's try to resurrect it */
|
|
|
|
newObject = [self _resurrectRecord: cname fromFolder: folder];
|
|
|
|
if (!newObject)
|
|
|
|
{
|
|
|
|
newObject = [SOGoAppointmentObject objectWithName: cname
|
|
|
|
inContainer: folder];
|
|
|
|
[newObject setIsNew: YES];
|
|
|
|
}
|
2012-08-16 18:32:52 +02:00
|
|
|
}
|
2012-03-12 01:06:06 +01:00
|
|
|
else
|
|
|
|
{
|
2011-10-04 01:13:00 +02:00
|
|
|
/* dissociate the object url from the old object's id */
|
2012-03-12 01:06:06 +01:00
|
|
|
objectId = [mapping idFromURL: url];
|
2011-10-03 22:55:02 +02:00
|
|
|
[mapping unregisterURLWithID: objectId];
|
2012-03-12 01:06:06 +01:00
|
|
|
newObject = [folder lookupName: cname
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
|
|
|
}
|
2011-10-03 22:55:02 +02:00
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
/* dissociate the object url associated with this object, as we want to
|
|
|
|
discard it */
|
|
|
|
objectId = [self objectId];
|
|
|
|
[mapping unregisterURLWithID: objectId];
|
2011-10-04 01:13:00 +02:00
|
|
|
|
2012-03-12 01:06:06 +01:00
|
|
|
/* associate the new object url with this object id */
|
|
|
|
[mapping registerURL: url withID: objectId];
|
|
|
|
|
|
|
|
[newObject setContext: woContext];
|
|
|
|
ASSIGN (sogoObject, newObject);
|
2011-10-03 22:55:02 +02:00
|
|
|
}
|
|
|
|
|
2011-12-01 22:13:09 +01:00
|
|
|
- (BOOL) subscriberCanReadMessage
|
|
|
|
{
|
2012-02-14 15:33:17 +01:00
|
|
|
NSArray *roles;
|
|
|
|
|
|
|
|
roles = [self activeUserRoles];
|
|
|
|
|
|
|
|
return ([roles containsObject: SOGoCalendarRole_ComponentViewer]
|
|
|
|
|| [roles containsObject: SOGoCalendarRole_ComponentDAndTViewer]
|
2011-12-01 22:13:09 +01:00
|
|
|
|| [self subscriberCanModifyMessage]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) subscriberCanModifyMessage
|
|
|
|
{
|
|
|
|
BOOL rc;
|
|
|
|
NSArray *roles = [self activeUserRoles];
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
rc = [roles containsObject: SOGoRole_ObjectCreator];
|
|
|
|
else
|
|
|
|
rc = ([roles containsObject: SOGoCalendarRole_ComponentModifier]
|
|
|
|
|| [roles containsObject: SOGoCalendarRole_ComponentResponder]);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:44:25 +02:00
|
|
|
- (void) _updateAttachedEvents
|
|
|
|
{
|
|
|
|
NSArray *allAttachments;
|
|
|
|
NSUInteger count, max;
|
2012-08-06 21:20:07 +02:00
|
|
|
NSString *uid, *summary;
|
|
|
|
iCalEvent *event;
|
|
|
|
MAPIStoreCalendarAttachment *attachment;
|
2012-07-20 17:44:25 +02:00
|
|
|
|
2012-08-06 21:20:07 +02:00
|
|
|
/* ensure that all exception events have the same UID as the master */
|
2012-07-20 17:44:25 +02:00
|
|
|
uid = [masterEvent uid];
|
2012-08-06 21:20:07 +02:00
|
|
|
summary = [masterEvent summary];
|
2012-07-20 17:44:25 +02:00
|
|
|
|
|
|
|
allAttachments = [attachmentParts allValues];
|
|
|
|
max = [allAttachments count];
|
|
|
|
for (count = 0; count < max; count++)
|
2012-08-06 21:20:07 +02:00
|
|
|
{
|
|
|
|
attachment = [allAttachments objectAtIndex: count];
|
|
|
|
event = [attachment event];
|
|
|
|
if ([[event summary] length] == 0)
|
|
|
|
[event setSummary: summary];
|
|
|
|
[event setUid: uid];
|
|
|
|
}
|
2012-07-20 17:44:25 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 16:31:28 +02:00
|
|
|
- (void) save: (TALLOC_CTX *) memCtx
|
2012-07-20 17:44:25 +02:00
|
|
|
{
|
|
|
|
// iCalCalendar *vCalendar;
|
|
|
|
// NSCalendarDate *now;
|
2012-08-08 21:10:28 +02:00
|
|
|
NSString *uid, *nameInContainer;
|
2012-07-20 17:44:25 +02:00
|
|
|
// iCalEvent *newEvent;
|
2012-03-12 01:06:06 +01:00
|
|
|
// iCalPerson *userPerson;
|
2012-07-20 17:44:25 +02:00
|
|
|
SOGoUser *activeUser;
|
2012-08-08 21:10:28 +02:00
|
|
|
NSRange rangeOfDot;
|
2011-02-24 21:30:01 +01:00
|
|
|
|
2011-10-03 22:55:02 +02:00
|
|
|
if (isNew)
|
|
|
|
{
|
2013-03-13 20:04:11 +01:00
|
|
|
uid = [self _uidFromGlobalObjectId: memCtx];
|
2012-03-12 01:06:06 +01:00
|
|
|
if (uid)
|
|
|
|
{
|
|
|
|
/* Hack required because of what's explained in oxocal 3.1.4.7.1:
|
2012-07-20 17:42:52 +02:00
|
|
|
basically, Outlook creates a copy of the event and then removes
|
|
|
|
the old instance. We perform a trickery to avoid performing those
|
|
|
|
operations in the backend, in a way that enables us to recover
|
|
|
|
the initial instance and act solely on it. */
|
2012-03-12 01:06:06 +01:00
|
|
|
[self _fixupAppointmentObjectWithUID: uid];
|
|
|
|
}
|
|
|
|
else
|
2012-08-08 21:10:28 +02:00
|
|
|
{
|
|
|
|
/* We create a UID from the nameInContainer, or the reverse if the
|
|
|
|
latter is already set... */
|
|
|
|
nameInContainer = [sogoObject nameInContainer];
|
|
|
|
if (nameInContainer)
|
|
|
|
{
|
|
|
|
rangeOfDot = [nameInContainer rangeOfString: @"."
|
|
|
|
options: NSBackwardsSearch];
|
|
|
|
if (rangeOfDot.location == NSNotFound)
|
|
|
|
uid = nameInContainer;
|
|
|
|
else
|
|
|
|
uid = [nameInContainer substringToIndex: rangeOfDot.location];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uid = [SOGoObject globallyUniqueObjectId];
|
|
|
|
nameInContainer = [NSString stringWithFormat: @"%@.ics", uid];
|
|
|
|
[sogoObject setNameInContainer: nameInContainer];
|
|
|
|
}
|
|
|
|
}
|
2012-07-20 17:42:52 +02:00
|
|
|
[masterEvent setUid: uid];
|
2011-10-03 22:55:02 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
// [self logWithFormat: @"-save, event props:"];
|
2011-02-24 21:30:01 +01:00
|
|
|
// MAPIStoreDumpMessageProperties (newProperties);
|
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
// now = [NSCalendarDate date];
|
2011-08-08 21:02:49 +02:00
|
|
|
|
2012-07-20 17:42:52 +02:00
|
|
|
activeUser = [[self context] activeUser];
|
|
|
|
[masterEvent updateFromMAPIProperties: properties
|
|
|
|
inUserContext: [self userContext]
|
2013-03-13 20:04:11 +01:00
|
|
|
withActiveUser: activeUser
|
|
|
|
inMemCtx: memCtx];
|
2012-07-20 17:44:25 +02:00
|
|
|
[self _updateAttachedEvents];
|
2015-07-14 16:31:28 +02:00
|
|
|
[[self userContext] activate];
|
2012-07-20 17:42:52 +02:00
|
|
|
[sogoObject updateContentWithCalendar: calendar
|
|
|
|
fromRequest: nil];
|
2012-03-16 22:05:41 +01:00
|
|
|
[self updateVersions];
|
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;
|
2012-08-06 21:20:07 +02:00
|
|
|
iCalEvent *newEvent;
|
2011-04-01 00:59:12 +02:00
|
|
|
|
2011-07-26 22:13:10 +02:00
|
|
|
newAid = [[self attachmentKeys] count];
|
2011-04-01 00:59:12 +02:00
|
|
|
|
|
|
|
newAttachment = [MAPIStoreCalendarAttachment
|
2012-06-29 19:59:38 +02:00
|
|
|
mapiStoreObjectInContainer: self];
|
2011-04-01 00:59:12 +02:00
|
|
|
[newAttachment setAID: newAid];
|
2012-08-06 21:20:07 +02:00
|
|
|
newEvent = [iCalEvent groupWithTag: @"vevent"];
|
|
|
|
[newAttachment setEvent: newEvent];
|
|
|
|
[calendar addToEvents: newEvent];
|
|
|
|
|
2011-04-01 00:59:12 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-04 16:15:05 +02:00
|
|
|
- (enum mapistore_error) setReadFlag: (uint8_t) flag
|
2011-11-01 15:30:20 +01:00
|
|
|
{
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-02-24 21:30:01 +01:00
|
|
|
@end
|