2014-01-10 20:12:53 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2014, Inverse inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
2014-01-13 17:46:32 +01:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the Inverse inc. nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
#import "iCalToDo+ActiveSync.h"
|
|
|
|
|
2014-01-12 01:31:39 +01:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSDate.h>
|
2014-01-10 20:12:53 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2014-01-12 01:31:39 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
|
2014-01-27 17:30:43 +01:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2014-02-17 16:01:44 +01:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2015-02-26 23:51:02 +01:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2014-02-17 16:01:44 +01:00
|
|
|
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2014-01-27 17:30:43 +01:00
|
|
|
|
2014-01-12 01:31:39 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalDateTime.h>
|
|
|
|
#import <NGCards/iCalTimeZone.h>
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
#include "NSDate+ActiveSync.h"
|
2014-01-12 01:31:39 +01:00
|
|
|
#include "NSString+ActiveSync.h"
|
2014-01-10 20:12:53 +01:00
|
|
|
|
2015-02-26 23:51:02 +01:00
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
@implementation iCalToDo (ActiveSync)
|
|
|
|
|
2014-02-17 16:01:44 +01:00
|
|
|
- (NSString *) activeSyncRepresentationInContext: (WOContext *) context
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
|
|
|
NSMutableString *s;
|
2014-12-16 19:27:01 +01:00
|
|
|
NSArray *categories;
|
2014-01-23 15:41:41 +01:00
|
|
|
id o;
|
|
|
|
|
2014-12-16 19:27:01 +01:00
|
|
|
int v, i;
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
s = [NSMutableString string];
|
|
|
|
|
|
|
|
// Complete
|
2015-02-26 23:51:02 +01:00
|
|
|
[s appendFormat: @"<Complete xmlns=\"Tasks:\">%d</Complete>", [[self status] isEqualToString: @"COMPLETED"] ? 1 : 0];
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
// DateCompleted
|
2015-02-26 23:51:02 +01:00
|
|
|
if ((o = [self completed]))
|
2014-02-17 16:01:44 +01:00
|
|
|
[s appendFormat: @"<DateCompleted xmlns=\"Tasks:\">%@</DateCompleted>", [o activeSyncRepresentationInContext: context]];
|
2014-01-23 15:41:41 +01:00
|
|
|
|
|
|
|
// Start date
|
|
|
|
if ((o = [self startDate]))
|
|
|
|
{
|
2014-02-17 16:01:44 +01:00
|
|
|
[s appendFormat: @"<StartDate xmlns=\"Tasks:\">%@</StartDate>", [o activeSyncRepresentationInContext: context]];
|
|
|
|
[s appendFormat: @"<UTCStartDate xmlns=\"Tasks:\">%@</UTCStartDate>", [o activeSyncRepresentationInContext: context]];
|
2014-01-23 15:41:41 +01:00
|
|
|
}
|
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
// Due date
|
2014-01-23 15:41:41 +01:00
|
|
|
if ((o = [self due]))
|
|
|
|
{
|
2014-02-17 16:01:44 +01:00
|
|
|
[s appendFormat: @"<DueDate xmlns=\"Tasks:\">%@</DueDate>", [o activeSyncRepresentationInContext: context]];
|
|
|
|
[s appendFormat: @"<UTCDueDate xmlns=\"Tasks:\">%@</UTCDueDate>", [o activeSyncRepresentationInContext: context]];
|
2014-01-23 15:41:41 +01:00
|
|
|
}
|
2014-01-10 20:12:53 +01:00
|
|
|
|
|
|
|
// Importance
|
2014-01-23 15:41:41 +01:00
|
|
|
o = [self priority];
|
|
|
|
if ([o isEqualToString: @"9"])
|
2014-01-10 20:12:53 +01:00
|
|
|
v = 0;
|
2014-01-23 15:41:41 +01:00
|
|
|
else if ([o isEqualToString: @"1"])
|
2014-01-10 20:12:53 +01:00
|
|
|
v = 2;
|
|
|
|
else
|
|
|
|
v = 1;
|
|
|
|
[s appendFormat: @"<Importance xmlns=\"Tasks:\">%d</Importance>", v];
|
|
|
|
|
|
|
|
// Reminder - FIXME
|
|
|
|
[s appendFormat: @"<ReminderSet xmlns=\"Tasks:\">%d</ReminderSet>", 0];
|
|
|
|
|
2015-02-26 23:51:02 +01:00
|
|
|
// Sensitivity
|
2014-12-16 19:27:01 +01:00
|
|
|
if ([[self accessClass] isEqualToString: @"PRIVATE"])
|
|
|
|
v = 2;
|
|
|
|
else if ([[self accessClass] isEqualToString: @"CONFIDENTIAL"])
|
|
|
|
v = 3;
|
|
|
|
else
|
|
|
|
v = 0;
|
|
|
|
|
2015-02-26 23:51:02 +01:00
|
|
|
[s appendFormat: @"<Sensitivity xmlns=\"Tasks:\">%d</Sensitivity>", v];
|
|
|
|
|
2014-12-16 19:27:01 +01:00
|
|
|
categories = [self categories];
|
|
|
|
|
|
|
|
if ([categories count])
|
|
|
|
{
|
|
|
|
[s appendFormat: @"<Categories xmlns=\"Tasks:\">"];
|
|
|
|
for (i = 0; i < [categories count]; i++)
|
|
|
|
{
|
|
|
|
[s appendFormat: @"<Category xmlns=\"Tasks:\">%@</Category>", [[categories objectAtIndex: i] activeSyncRepresentationInContext: context]];
|
|
|
|
}
|
|
|
|
[s appendFormat: @"</Categories>"];
|
|
|
|
}
|
|
|
|
|
2014-01-10 20:12:53 +01:00
|
|
|
// Subject
|
2014-01-27 17:30:43 +01:00
|
|
|
o = [self summary];
|
|
|
|
if ([o length])
|
2014-02-17 16:01:44 +01:00
|
|
|
[s appendFormat: @"<Subject xmlns=\"Tasks:\">%@</Subject>", [[self summary] activeSyncRepresentationInContext: context]];
|
2014-01-10 20:12:53 +01:00
|
|
|
|
2014-01-23 15:41:41 +01:00
|
|
|
if ((o = [self comment]))
|
|
|
|
{
|
2014-12-17 22:18:39 +01:00
|
|
|
// It is very important here to NOT set <Truncated>0</Truncated> in the response,
|
|
|
|
// otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details.
|
2014-02-17 16:01:44 +01:00
|
|
|
o = [o activeSyncRepresentationInContext: context];
|
2015-02-26 23:51:02 +01:00
|
|
|
|
|
|
|
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
|
|
|
|
{
|
|
|
|
[s appendFormat: @"<Body xmlns=\"Tasks:\">%@</Body>", o];
|
|
|
|
[s appendString: @"<BodyTruncated xmlns=\"Tasks:\">0</BodyTruncated>"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[s appendString: @"<Body xmlns=\"AirSyncBase:\">"];
|
|
|
|
[s appendFormat: @"<Type>%d</Type>", 1];
|
2015-11-05 18:29:26 +01:00
|
|
|
[s appendFormat: @"<EstimatedDataSize>%d</EstimatedDataSize>", (int)[o length]];
|
2015-02-26 23:51:02 +01:00
|
|
|
[s appendFormat: @"<Data>%@</Data>", o];
|
|
|
|
[s appendString: @"</Body>"];
|
|
|
|
}
|
2014-01-23 15:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2014-01-10 20:12:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) takeActiveSyncValues: (NSDictionary *) theValues
|
2014-02-17 16:01:44 +01:00
|
|
|
inContext: (WOContext *) context
|
2014-01-10 20:12:53 +01:00
|
|
|
{
|
2014-01-12 01:31:39 +01:00
|
|
|
NSTimeZone *userTimeZone;
|
|
|
|
iCalTimeZone *tz;
|
2014-01-10 20:12:53 +01:00
|
|
|
id o;
|
|
|
|
|
2014-02-17 16:01:44 +01:00
|
|
|
userTimeZone = [[[context activeUser] userDefaults] timeZone];
|
2014-01-12 01:31:39 +01:00
|
|
|
tz = [iCalTimeZone timeZoneForName: [userTimeZone name]];
|
|
|
|
[(iCalCalendar *) parent addTimeZone: tz];
|
|
|
|
|
|
|
|
// FIXME: merge with iCalEvent
|
2014-01-10 20:12:53 +01:00
|
|
|
if ((o = [theValues objectForKey: @"Subject"]))
|
|
|
|
[self setSummary: o];
|
2014-01-12 01:31:39 +01:00
|
|
|
|
|
|
|
// FIXME: merge with iCalEvent
|
2015-02-26 23:51:02 +01:00
|
|
|
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
|
|
|
|
{
|
|
|
|
if ((o = [theValues objectForKey: @"Body"]))
|
|
|
|
[self setComment: o];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((o = [[theValues objectForKey: @"Body"] objectForKey: @"Data"]))
|
|
|
|
[self setComment: o];
|
|
|
|
}
|
2014-01-12 01:31:39 +01:00
|
|
|
|
|
|
|
if ([[theValues objectForKey: @"Complete"] intValue] &&
|
|
|
|
((o = [theValues objectForKey: @"DateCompleted"])) )
|
|
|
|
{
|
|
|
|
iCalDateTime *completed;
|
|
|
|
|
|
|
|
o = [o calendarDate];
|
|
|
|
completed = (iCalDateTime *) [self uniqueChildWithTag: @"completed"];
|
|
|
|
[completed setDate: o];
|
|
|
|
[self setStatus: @"COMPLETED"];
|
|
|
|
}
|
2015-02-26 23:51:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setStatus: @"IN-PROCESS"];
|
|
|
|
[self setCompleted: nil];
|
|
|
|
}
|
2014-01-12 01:31:39 +01:00
|
|
|
|
|
|
|
if ((o = [theValues objectForKey: @"DueDate"]))
|
|
|
|
{
|
|
|
|
iCalDateTime *due;
|
|
|
|
|
|
|
|
o = [o calendarDate];
|
|
|
|
due = (iCalDateTime *) [self uniqueChildWithTag: @"due"];
|
|
|
|
[due setTimeZone: tz];
|
|
|
|
[due setDateTime: o];
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:51:02 +01:00
|
|
|
if ((o = [theValues objectForKey: @"StartDate"]))
|
|
|
|
{
|
|
|
|
iCalDateTime *due;
|
|
|
|
|
|
|
|
o = [o calendarDate];
|
|
|
|
due = (iCalDateTime *) [self uniqueChildWithTag: @"dtstart"];
|
|
|
|
[due setTimeZone: tz];
|
|
|
|
[due setDateTime: o];
|
|
|
|
}
|
|
|
|
|
2014-01-12 01:31:39 +01:00
|
|
|
// 2 == high, 1 == normal, 0 == low
|
|
|
|
if ((o = [theValues objectForKey: @"Importance"]))
|
|
|
|
{
|
|
|
|
if ([o intValue] == 2)
|
|
|
|
[self setPriority: @"1"];
|
|
|
|
else if ([o intValue] == 1)
|
|
|
|
[self setPriority: @"5"];
|
|
|
|
else
|
|
|
|
[self setPriority: @"9"];
|
|
|
|
}
|
|
|
|
|
2014-12-16 19:27:01 +01:00
|
|
|
//
|
|
|
|
// 0- normal, 1- personal, 2- private and 3-confidential
|
|
|
|
//
|
|
|
|
if ((o = [theValues objectForKey: @"Sensitivity"]))
|
|
|
|
{
|
|
|
|
switch ([o intValue])
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
[self setAccessClass: @"PRIVATE"];
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
[self setAccessClass: @"CONFIDENTIAL"];
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
[self setAccessClass: @"PUBLIC"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Categories
|
|
|
|
if ((o = [theValues objectForKey: @"Categories"]) && [o length])
|
|
|
|
[self setCategories: o];
|
2014-01-12 01:31:39 +01:00
|
|
|
|
|
|
|
if ((o = [theValues objectForKey: @"ReminderTime"]))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-01-10 20:12:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|