2007-11-13 23:38:05 +01:00
|
|
|
/* UIxMailPartICalActions.m - this file is part of SOGo
|
|
|
|
*
|
2014-07-30 20:51:00 +02:00
|
|
|
* Copyright (C) 2007-2014 Inverse inc.
|
2007-11-13 23:38:05 +01:00
|
|
|
*
|
|
|
|
* 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/NSCalendarDate.h>
|
2009-03-24 16:34:15 +01:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
|
2009-09-10 20:31:20 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2009-09-10 20:31:20 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2008-02-05 23:26:39 +01:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <NGCards/iCalEvent.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
|
|
|
|
#import <UI/Common/WODirectAction+SOGo.h>
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
|
|
|
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Appointments/iCalEvent+SOGo.h>
|
|
|
|
#import <Appointments/iCalPerson+SOGo.h>
|
|
|
|
#import <Appointments/SOGoAppointmentObject.h>
|
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
|
|
|
#import <Mailer/SOGoMailObject.h>
|
|
|
|
#import <SOGo/SOGoParentFolder.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2017-01-06 20:32:45 +01:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2015-11-03 20:59:40 +01:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Mailer/SOGoMailBodyPart.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
#import "UIxMailPartICalActions.h"
|
|
|
|
|
|
|
|
@implementation UIxMailPartICalActions
|
|
|
|
|
|
|
|
- (iCalEvent *) _emailEvent
|
|
|
|
{
|
|
|
|
iCalCalendar *emailCalendar;
|
2009-10-28 15:18:27 +01:00
|
|
|
NSString *eventString;
|
|
|
|
NSData *content;
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
content = [[self clientObject] fetchBLOB];
|
|
|
|
eventString = [[NSString alloc] initWithData: content
|
|
|
|
encoding: NSUTF8StringEncoding];
|
|
|
|
if (!eventString)
|
|
|
|
eventString = [[NSString alloc] initWithData: content
|
|
|
|
encoding: NSISOLatin1StringEncoding];
|
2009-10-28 15:18:27 +01:00
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
emailCalendar = [iCalCalendar parseSingleFromSource: eventString];
|
2009-10-10 20:37:10 +02:00
|
|
|
[eventString release];
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
return (iCalEvent *) [emailCalendar firstChildWithTag: @"vevent"];
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:24:25 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2007-11-13 23:38:05 +01:00
|
|
|
- (SOGoAppointmentObject *) _eventObjectWithUID: (NSString *) uid
|
2007-11-18 11:16:25 +01:00
|
|
|
forUser: (SOGoUser *) user
|
2007-11-13 23:38:05 +01:00
|
|
|
{
|
2009-03-24 16:34:15 +01:00
|
|
|
SOGoAppointmentFolder *folder;
|
2007-11-13 23:38:05 +01:00
|
|
|
SOGoAppointmentObject *eventObject;
|
2009-03-24 16:34:15 +01:00
|
|
|
NSArray *folders;
|
|
|
|
NSEnumerator *e;
|
2010-04-07 17:06:07 +02:00
|
|
|
NSString *cname, *userLogin;
|
2007-11-19 16:39:44 +01:00
|
|
|
|
|
|
|
eventObject = nil;
|
2007-11-13 23:38:05 +01:00
|
|
|
|
2010-04-07 17:06:07 +02:00
|
|
|
userLogin = [user login];
|
|
|
|
|
2009-03-24 16:34:15 +01:00
|
|
|
folders = [[user calendarsFolderInContext: context] subFolders];
|
|
|
|
e = [folders objectEnumerator];
|
2010-04-07 17:06:07 +02:00
|
|
|
while (eventObject == nil && (folder = [e nextObject]))
|
2007-11-19 16:39:44 +01:00
|
|
|
{
|
2010-04-07 17:06:07 +02:00
|
|
|
if ([[folder ownerInContext: nil] isEqualToString: userLogin])
|
|
|
|
{
|
|
|
|
cname = [folder resourceNameForEventUID: uid];
|
|
|
|
if (cname)
|
|
|
|
{
|
|
|
|
eventObject = [folder lookupName: cname inContext: context
|
|
|
|
acquire: NO];
|
2010-04-09 23:00:00 +02:00
|
|
|
if ([eventObject isKindOfClass: [NSException class]])
|
2010-04-07 17:06:07 +02:00
|
|
|
eventObject = nil;
|
|
|
|
}
|
|
|
|
}
|
2007-11-19 16:39:44 +01:00
|
|
|
}
|
2010-04-07 17:06:07 +02:00
|
|
|
|
2007-11-19 16:39:44 +01:00
|
|
|
if (!eventObject)
|
2008-08-09 10:17:13 +02:00
|
|
|
{
|
2009-03-24 16:50:50 +01:00
|
|
|
folder = [user personalCalendarFolderInContext: context];
|
2008-08-09 10:17:13 +02:00
|
|
|
eventObject = [SOGoAppointmentObject objectWithName: uid
|
2009-03-24 16:34:15 +01:00
|
|
|
inContainer: folder];
|
2008-08-09 10:17:13 +02:00
|
|
|
[eventObject setIsNew: YES];
|
|
|
|
}
|
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
return eventObject;
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:24:25 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2007-11-18 11:16:25 +01:00
|
|
|
- (SOGoAppointmentObject *) _eventObjectWithUID: (NSString *) uid
|
|
|
|
{
|
2009-10-28 15:18:27 +01:00
|
|
|
#warning this will not work if Bob reads emails of Alice and accepts events for her
|
2007-11-18 11:16:25 +01:00
|
|
|
return [self _eventObjectWithUID: uid forUser: [context activeUser]];
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:24:25 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2008-02-05 23:26:39 +01:00
|
|
|
- (void) _fixOrganizerInEvent: (iCalEvent *) brokenEvent
|
|
|
|
{
|
|
|
|
iCalPerson *organizer;
|
|
|
|
SOGoMailObject *mail;
|
|
|
|
NSArray *addresses;
|
|
|
|
NGImap4EnvelopeAddress *from;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
organizer = nil;
|
|
|
|
|
|
|
|
mail = [[self clientObject] mailObject];
|
|
|
|
|
|
|
|
addresses = [mail replyToEnvelopeAddresses];
|
|
|
|
if (![addresses count])
|
|
|
|
addresses = [mail fromEnvelopeAddresses];
|
|
|
|
if ([addresses count] > 0)
|
|
|
|
{
|
|
|
|
from = [addresses objectAtIndex: 0];
|
|
|
|
value = [from baseEMail];
|
|
|
|
if ([value isNotNull])
|
|
|
|
{
|
|
|
|
organizer = [iCalPerson elementWithTag: @"organizer"];
|
|
|
|
[organizer setEmail: value];
|
|
|
|
value = [from personalName];
|
|
|
|
if ([value isNotNull])
|
|
|
|
[organizer setCn: value];
|
|
|
|
[brokenEvent setOrganizer: organizer];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!organizer)
|
|
|
|
[self errorWithFormat: @"no organizer could be found, SOGo will crash"
|
|
|
|
@" if the user replies"];
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:24:25 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
- (iCalEvent *) _setupChosenEventAndEventObject: (SOGoAppointmentObject **) eventObject
|
2007-11-13 23:38:05 +01:00
|
|
|
{
|
|
|
|
iCalEvent *emailEvent, *calendarEvent, *chosenEvent;
|
2008-02-05 23:26:39 +01:00
|
|
|
iCalPerson *organizer;
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
emailEvent = [self _emailEvent];
|
|
|
|
if (emailEvent)
|
|
|
|
{
|
|
|
|
*eventObject = [self _eventObjectWithUID: [emailEvent uid]];
|
|
|
|
if ([*eventObject isNew])
|
2009-10-28 15:18:27 +01:00
|
|
|
{
|
|
|
|
chosenEvent = emailEvent;
|
2014-07-30 20:51:00 +02:00
|
|
|
[*eventObject saveCalendar: [emailEvent parent]];
|
2009-10-28 15:18:27 +01:00
|
|
|
}
|
2007-11-13 23:38:05 +01:00
|
|
|
else
|
|
|
|
{
|
2008-12-03 17:18:12 +01:00
|
|
|
if ([emailEvent recurrenceId])
|
|
|
|
{
|
2009-10-28 15:18:27 +01:00
|
|
|
// Event attached to email is not complete -- retrieve it
|
2008-12-03 17:18:12 +01:00
|
|
|
// from the database.
|
|
|
|
NSString *recurrenceTime;
|
|
|
|
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f",
|
|
|
|
[[emailEvent recurrenceId] timeIntervalSince1970]];
|
2012-07-13 23:03:50 +02:00
|
|
|
calendarEvent = (iCalEvent *)[*eventObject lookupOccurrence: recurrenceTime];
|
2008-12-03 17:18:12 +01:00
|
|
|
}
|
|
|
|
else
|
2011-07-05 15:24:25 +02:00
|
|
|
calendarEvent = (iCalEvent *) [*eventObject component: NO secure: NO];
|
2008-12-03 17:18:12 +01:00
|
|
|
|
|
|
|
if (calendarEvent != nil)
|
|
|
|
{
|
|
|
|
// Calendar event still exists -- verify which of the calendar
|
2011-07-05 15:24:25 +02:00
|
|
|
// and email events is the most recent. We must also update
|
|
|
|
// the event (or recurrence-id) with the email's content, otherwise
|
|
|
|
// we would never get major properties updates
|
2008-12-03 17:18:12 +01:00
|
|
|
if ([calendarEvent compare: emailEvent] == NSOrderedAscending)
|
2011-07-05 15:24:25 +02:00
|
|
|
{
|
|
|
|
iCalCalendar *parent;
|
|
|
|
|
|
|
|
parent = [calendarEvent parent];
|
|
|
|
[parent removeChild: calendarEvent];
|
|
|
|
[parent addChild: emailEvent];
|
2014-07-30 20:51:00 +02:00
|
|
|
[*eventObject saveCalendar: parent];
|
2011-07-05 15:24:25 +02:00
|
|
|
[*eventObject flush];
|
|
|
|
chosenEvent = emailEvent;
|
|
|
|
}
|
2008-12-03 17:18:12 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
chosenEvent = calendarEvent;
|
|
|
|
if (![[[chosenEvent parent] method] length])
|
|
|
|
[[chosenEvent parent] setMethod: [[emailEvent parent] method]];
|
|
|
|
}
|
|
|
|
}
|
2007-11-13 23:38:05 +01:00
|
|
|
else
|
2008-12-03 17:18:12 +01:00
|
|
|
chosenEvent = emailEvent;
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
2008-02-05 23:26:39 +01:00
|
|
|
|
|
|
|
organizer = [chosenEvent organizer];
|
|
|
|
if (![[organizer rfc822Email] length])
|
|
|
|
[self _fixOrganizerInEvent: chosenEvent];
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
chosenEvent = nil;
|
2008-12-03 17:18:12 +01:00
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
return chosenEvent;
|
|
|
|
}
|
|
|
|
|
2011-07-05 15:24:25 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2007-11-13 23:38:05 +01:00
|
|
|
- (WOResponse *) _changePartStatusAction: (NSString *) newStatus
|
2009-09-10 20:31:20 +02:00
|
|
|
withDelegate: (iCalPerson *) delegate
|
2007-11-13 23:38:05 +01:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
SOGoAppointmentObject *eventObject;
|
|
|
|
iCalEvent *chosenEvent;
|
2009-09-10 20:31:20 +02:00
|
|
|
//NSException *ex;
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
chosenEvent = [self _setupChosenEventAndEventObject: &eventObject];
|
|
|
|
if (chosenEvent)
|
|
|
|
{
|
2009-09-10 20:31:20 +02:00
|
|
|
response = (WOResponse*)[eventObject changeParticipationStatus: newStatus
|
|
|
|
withDelegate: delegate
|
2014-12-16 15:20:27 +01:00
|
|
|
alarm: nil
|
2009-09-10 20:31:20 +02:00
|
|
|
forRecurrenceId: [chosenEvent recurrenceId]];
|
|
|
|
// if (ex)
|
|
|
|
// response = ex; //[self responseWithStatus: 500];
|
|
|
|
// else
|
|
|
|
if (!response)
|
|
|
|
response = [self responseWith204];
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 409];
|
|
|
|
}
|
2009-09-10 20:31:20 +02:00
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) acceptAction
|
|
|
|
{
|
2009-09-10 20:31:20 +02:00
|
|
|
return [self _changePartStatusAction: @"ACCEPTED"
|
|
|
|
withDelegate: nil];
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) declineAction
|
|
|
|
{
|
2009-09-10 20:31:20 +02:00
|
|
|
return [self _changePartStatusAction: @"DECLINED"
|
|
|
|
withDelegate: nil];
|
|
|
|
}
|
|
|
|
|
2010-05-05 16:40:53 +02:00
|
|
|
- (WOResponse *) tentativeAction
|
|
|
|
{
|
|
|
|
return [self _changePartStatusAction: @"TENTATIVE"
|
|
|
|
withDelegate: nil];
|
|
|
|
}
|
|
|
|
|
2009-09-10 20:31:20 +02:00
|
|
|
- (WOResponse *) delegateAction
|
|
|
|
{
|
|
|
|
// BOOL receiveUpdates;
|
|
|
|
NSString *delegatedEmail, *delegatedUid;
|
|
|
|
iCalPerson *delegatedAttendee;
|
|
|
|
SOGoUser *user;
|
|
|
|
WORequest *request;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
delegatedEmail = [request formValueForKey: @"to"];
|
|
|
|
if ([delegatedEmail length])
|
|
|
|
{
|
|
|
|
user = [context activeUser];
|
|
|
|
delegatedAttendee = [iCalPerson new];
|
2009-10-13 23:40:18 +02:00
|
|
|
[delegatedAttendee autorelease];
|
2009-09-10 20:31:20 +02:00
|
|
|
[delegatedAttendee setEmail: delegatedEmail];
|
2015-07-22 22:45:42 +02:00
|
|
|
delegatedUid = [delegatedAttendee uidInDomain: [user domain]];
|
2009-09-10 20:31:20 +02:00
|
|
|
if (delegatedUid)
|
|
|
|
{
|
|
|
|
SOGoUser *delegatedUser;
|
|
|
|
delegatedUser = [SOGoUser userWithLogin: delegatedUid];
|
|
|
|
[delegatedAttendee setCn: [delegatedUser cn]];
|
|
|
|
}
|
|
|
|
[delegatedAttendee setRole: @"REQ-PARTICIPANT"];
|
|
|
|
[delegatedAttendee setRsvp: @"TRUE"];
|
|
|
|
[delegatedAttendee setParticipationStatus: iCalPersonPartStatNeedsAction];
|
|
|
|
[delegatedAttendee setDelegatedFrom:
|
|
|
|
[NSString stringWithFormat: @"mailto:%@", [[user allEmails] objectAtIndex: 0]]];
|
|
|
|
|
|
|
|
// receiveUpdates = [[request formValueForKey: @"receiveUpdates"] boolValue];
|
|
|
|
// if (receiveUpdates)
|
|
|
|
// [delegatedAttendee setRole: @"NON-PARTICIPANT"];
|
|
|
|
|
|
|
|
response = [self _changePartStatusAction: @"DELEGATED"
|
|
|
|
withDelegate: delegatedAttendee];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'to' parameter"];
|
|
|
|
|
|
|
|
return response;
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
|
2009-06-30 21:20:10 +02:00
|
|
|
- (WOResponse *) addToCalendarAction
|
|
|
|
{
|
|
|
|
iCalEvent *emailEvent;
|
|
|
|
SOGoAppointmentObject *eventObject;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
emailEvent = [self _emailEvent];
|
|
|
|
if (emailEvent)
|
|
|
|
{
|
|
|
|
eventObject = [self _eventObjectWithUID: [emailEvent uid]];
|
|
|
|
if ([eventObject isNew])
|
|
|
|
{
|
2014-07-30 20:51:00 +02:00
|
|
|
[eventObject saveCalendar: [emailEvent parent]];
|
2009-06-30 21:20:10 +02:00
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [self responseWithStatus: 409];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 409];
|
|
|
|
response = [self responseWithStatus: 404];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (WOResponse *) deleteFromCalendarAction
|
|
|
|
{
|
|
|
|
iCalEvent *emailEvent;
|
|
|
|
SOGoAppointmentObject *eventObject;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
emailEvent = [self _emailEvent];
|
|
|
|
if (emailEvent)
|
|
|
|
{
|
|
|
|
eventObject = [self _eventObjectWithUID: [emailEvent uid]];
|
2007-11-19 16:39:44 +01:00
|
|
|
[eventObject delete];
|
2007-11-18 11:16:25 +01:00
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 409];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalPerson *) _emailParticipantWithEvent: (iCalEvent *) event
|
|
|
|
{
|
|
|
|
NGImap4EnvelopeAddress *address;
|
2017-01-06 20:32:45 +01:00
|
|
|
SOGoMailObject *mailObject;
|
|
|
|
NSString *emailFrom;
|
|
|
|
iCalPerson *p;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
mailObject = [[self clientObject] mailObject];
|
|
|
|
address = [[mailObject fromEnvelopeAddresses] objectAtIndex: 0];
|
|
|
|
emailFrom = [address baseEMail];
|
2017-01-06 20:32:45 +01:00
|
|
|
p = [event findAttendeeWithEmail: emailFrom];
|
|
|
|
|
|
|
|
// We haven't found it yet, let's look in the identities
|
|
|
|
// associated to this user
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
SOGoUserManager *sm;
|
|
|
|
NSString *uid;
|
|
|
|
|
|
|
|
sm = [SOGoUserManager sharedUserManager];
|
|
|
|
uid = [sm getUIDForEmail: emailFrom];
|
|
|
|
|
|
|
|
if (uid)
|
|
|
|
{
|
|
|
|
NSArray *allEmails;
|
|
|
|
NSString *email;
|
|
|
|
SOGoUser *u;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
u = [SOGoUser userWithLogin: uid];
|
|
|
|
allEmails = [u allEmails];
|
|
|
|
for (i = 0; i < [allEmails count]; i++)
|
|
|
|
{
|
|
|
|
email = [allEmails objectAtIndex: i];
|
|
|
|
if ([email caseInsensitiveCompare: emailFrom] == NSOrderedSame)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = [event findAttendeeWithEmail: email];
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2017-01-06 20:32:45 +01:00
|
|
|
return p;
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _updateParticipantStatusInEvent: (iCalEvent *) calendarEvent
|
|
|
|
fromEvent: (iCalEvent *) emailEvent
|
|
|
|
inObject: (SOGoAppointmentObject *) eventObject
|
|
|
|
{
|
|
|
|
iCalPerson *calendarParticipant, *mailParticipant;
|
|
|
|
NSString *partStat;
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
calendarParticipant = [self _emailParticipantWithEvent: calendarEvent];
|
|
|
|
mailParticipant = [self _emailParticipantWithEvent: emailEvent];
|
|
|
|
if (calendarParticipant && mailParticipant)
|
|
|
|
{
|
|
|
|
result = YES;
|
|
|
|
partStat = [mailParticipant partStat];
|
|
|
|
if ([partStat caseInsensitiveCompare: [calendarParticipant partStat]]
|
|
|
|
!= NSOrderedSame)
|
|
|
|
{
|
|
|
|
[calendarParticipant setPartStat: [partStat uppercaseString]];
|
|
|
|
[eventObject saveComponent: calendarEvent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = NO;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) updateUserStatusAction
|
|
|
|
{
|
|
|
|
iCalEvent *emailEvent, *calendarEvent;
|
|
|
|
SOGoAppointmentObject *eventObject;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = nil;
|
|
|
|
|
|
|
|
emailEvent = [self _emailEvent];
|
|
|
|
if (emailEvent)
|
|
|
|
{
|
|
|
|
eventObject = [self _eventObjectWithUID: [emailEvent uid]];
|
|
|
|
calendarEvent = [eventObject component: NO secure: NO];
|
2010-04-09 23:00:00 +02:00
|
|
|
if (calendarEvent)
|
|
|
|
{
|
|
|
|
if (([[emailEvent sequence] compare: [calendarEvent sequence]]
|
|
|
|
!= NSOrderedAscending)
|
|
|
|
&& ([self _updateParticipantStatusInEvent: calendarEvent
|
|
|
|
fromEvent: emailEvent
|
|
|
|
inObject: eventObject]))
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 404
|
|
|
|
andString: @"Local event not found."];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!response)
|
|
|
|
{
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 409];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
@end
|