1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
|
/* MAPIStoreTasksMessage.m - this file is part of SOGo
*
* Copyright (C) 2011-2012 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Ludovic Marcotte <lmarcotte@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
* the Free Software Foundation; either version 3, 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/NSArray.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTimeZone.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGExtensions/NSObject+Logs.h>
#import <NGCards/iCalCalendar.h>
#import <NGCards/iCalDateTime.h>
#import <NGCards/iCalTimeZone.h>
#import <NGCards/iCalToDo.h>
#import <NGCards/iCalPerson.h>
#import <SOGo/SOGoPermissions.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <Appointments/iCalEntityObject+SOGo.h>
#import <Appointments/SOGoTaskObject.h>
#import <Mailer/NSString+Mail.h>
#import "MAPIStoreContext.h"
#import "MAPIStoreTasksFolder.h"
#import "MAPIStoreTypes.h"
#import "MAPIStoreUserContext.h"
#import "NSDate+MAPIStore.h"
#import "NSObject+MAPIStore.h"
#import "NSString+MAPIStore.h"
#import "MAPIStoreTasksMessage.h"
#undef DEBUG
#include <stdbool.h>
#include <gen_ndr/exchange.h>
#include <mapistore/mapistore.h>
#include <mapistore/mapistore_errors.h>
#include <mapistore/mapistore_nameid.h>
@implementation SOGoTaskObject (MAPIStoreExtension)
- (Class) mapistoreMessageClass
{
return [MAPIStoreTasksMessage class];
}
@end
@implementation MAPIStoreTasksMessage
- (int) getPidTagIconIndex: (void **) data // TODO
inMemCtx: (TALLOC_CTX *) memCtx
{
/* see http://msdn.microsoft.com/en-us/library/cc815472.aspx */
// Unassigned recurring task 0x00000501
// Assignee's task 0x00000502
// Assigner's task 0x00000503
// Task request 0x00000504
// Task acceptance 0x00000505
// Task rejection 0x00000506
*data = MAPILongValue (memCtx, 0x00000500);
return MAPISTORE_SUCCESS;
}
- (int) getPidTagMessageClass: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
*data = talloc_strdup(memCtx, "IPM.Task");
return MAPISTORE_SUCCESS;
}
- (int) getPidTagNormalizedSubject: (void **) data // SUMMARY
inMemCtx: (TALLOC_CTX *) memCtx
{
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
*data = [[task summary] asUnicodeInMemCtx: memCtx];
return MAPISTORE_SUCCESS;
}
/* FIXME: Should be combined somehow with the code in MAPIStoreAppointmentWrapper.m */
- (int) getPidTagBody: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc = MAPISTORE_SUCCESS;
NSString *stringValue;
iCalToDo *task;
/* FIXME: there is a confusion in NGCards around "comment" and "description" */
task = [sogoObject component: NO secure: YES];
stringValue = [task comment];
if ([stringValue length] > 0)
*data = [stringValue asUnicodeInMemCtx: memCtx];
else
*data = [@"" asUnicodeInMemCtx: memCtx];
return rc;
}
/* FIXME: Should be combined somehow with the code in MAPIStoreAppointmentWrapper.m */
- (int) getPidLidPrivate: (void **) data // private (bool), should depend on CLASS and permissions
inMemCtx: (TALLOC_CTX *) memCtx
{
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
if ([task symbolicAccessClass] == iCalAccessPublic)
return [self getNo: data inMemCtx: memCtx];
return [self getYes: data inMemCtx: memCtx];
}
- (int) getPidTagImportance: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
uint32_t v;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
if ([[task priority] isEqualToString: @"9"])
v = 0x0;
else if ([[task priority] isEqualToString: @"1"])
v = 0x2;
else
v = 0x1;
*data = MAPILongValue (memCtx, v);
return MAPISTORE_SUCCESS;
}
- (int) getPidLidTaskComplete: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
*data = MAPIBoolValue (memCtx,
[[task status] isEqualToString: @"COMPLETED"]);
return MAPISTORE_SUCCESS;
}
- (int) getPidLidPercentComplete: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
double doubleValue;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
doubleValue = ((double) [[task percentComplete] intValue] / 100);
*data = MAPIDoubleValue (memCtx, doubleValue);
return MAPISTORE_SUCCESS;
}
- (int) getPidLidTaskDateCompleted: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc = MAPISTORE_SUCCESS;
NSCalendarDate *dateValue;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
dateValue = [task completed];
if (dateValue)
*data = [dateValue asFileTimeInMemCtx: memCtx];
else
rc = MAPISTORE_ERR_NOT_FOUND;
return rc;
}
- (int) getPidLidTaskState: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
*data = MAPILongValue (memCtx, 0x1); // not assigned
return MAPISTORE_SUCCESS;
}
- (int) getPidLidTaskMode: (void **) data // TODO
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getLongZero: data inMemCtx: memCtx];
}
- (int) getPidLidTaskFRecurring: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getNo: data inMemCtx: memCtx];
}
- (int) getPidLidTaskAccepted: (void **) data // TODO
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getNo: data inMemCtx: memCtx];
}
- (int) getPidLidTaskActualEffort: (void **) data // TODO
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getLongZero: data inMemCtx: memCtx];
}
- (int) getPidLidTaskEstimatedEffort: (void **) data // TODO
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getLongZero: data inMemCtx: memCtx];
}
- (int) getPidTagHasAttachments: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getNo: data inMemCtx: memCtx];
}
- (int) getPidLidTaskDueDate: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc = MAPISTORE_SUCCESS;
NSCalendarDate *dateValue;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
dateValue = [task due];
if (dateValue)
*data = [dateValue asFileTimeInMemCtx: memCtx];
else
rc = MAPISTORE_ERR_NOT_FOUND;
return rc;
}
- (int) getPidLidTaskStartDate: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
int rc = MAPISTORE_SUCCESS;
NSCalendarDate *dateValue;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
dateValue = [task startDate];
if (dateValue)
*data = [dateValue asFileTimeInMemCtx: memCtx];
else
rc = MAPISTORE_ERR_NOT_FOUND;
return rc;
}
- (int) getPidTagMessageDeliveryTime: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getPidTagLastModificationTime: data inMemCtx: memCtx];
}
- (int) getClientSubmitTime: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getPidTagLastModificationTime: data inMemCtx: memCtx];
}
- (int) getLocalCommitTime: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getPidTagLastModificationTime: data inMemCtx: memCtx];
}
- (int) getPidLidTaskStatus: (void **) data // status
inMemCtx: (TALLOC_CTX *) memCtx
{
NSString *status;
uint32_t longValue;
iCalToDo *task;
task = [sogoObject component: NO secure: YES];
status = [task status];
if (![status length]
|| [status isEqualToString: @"NEEDS-ACTION"])
longValue = 0;
else if ([status isEqualToString: @"IN-PROCESS"])
longValue = 1;
else if ([status isEqualToString: @"COMPLETED"])
longValue = 2;
else
longValue = 0xff;
*data = MAPILongValue (memCtx, longValue);
return MAPISTORE_SUCCESS;
}
- (int) getPidLidTaskOwner: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
NSString *owner;
owner = [sogoObject ownerInContext: nil];
*data = [owner asUnicodeInMemCtx: memCtx];
return MAPISTORE_SUCCESS;
}
- (int) getPidLidTaskOwnership: (void **) data
inMemCtx: (TALLOC_CTX *) memCtx
{
return [self getLongZero: data inMemCtx: memCtx];
}
- (BOOL) subscriberCanReadMessage
{
return ([[self activeUserRoles]
containsObject: SOGoCalendarRole_ComponentViewer]
|| [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;
}
- (void) save:(TALLOC_CTX *) memCtx
{
iCalCalendar *vCalendar;
iCalToDo *vToDo;
id value;
iCalDateTime *date;
iCalTimeZone *tz;
NSString *status, *priority, *tzName;
NSCalendarDate *now;
NSInteger tzOffset;
double doubleValue;
vToDo = [sogoObject component: YES secure: NO];
vCalendar = [vToDo parent];
[vCalendar setProdID: @"-//Inverse inc.//OpenChange+SOGo//EN"];
tzName = [[[self userContext] timeZone] name];
tz = [iCalTimeZone timeZoneForName: tzName];
[vCalendar addTimeZone: tz];
// summary
value = [properties
objectForKey: MAPIPropertyKey (PR_NORMALIZED_SUBJECT_UNICODE)];
if (value)
[vToDo setSummary: value];
// comment
value = [properties
objectForKey: MAPIPropertyKey (PR_BODY_UNICODE)];
if (!value)
{
value = [properties objectForKey: MAPIPropertyKey (PR_HTML)];
if (value)
{
value = [[NSString alloc] initWithData: value
encoding: NSUTF8StringEncoding];
[value autorelease];
value = [value htmlToText];
}
}
if (value)
{
if ([value length] == 0 || [value isEqualToString: @"\\n"])
value = nil;
[vToDo setComment: value];
}
// location
value = [properties objectForKey: MAPIPropertyKey (PidLidLocation)];
if (value)
[vToDo setLocation: value];
// created
value = [properties objectForKey: MAPIPropertyKey (PR_CREATION_TIME)];
if (value)
[vToDo setCreated: value];
// last-modified + dtstamp
value = [properties objectForKey: MAPIPropertyKey (PR_LAST_MODIFICATION_TIME)];
if (value)
{
[vToDo setLastModified: value];
[vToDo setTimeStampAsDate: value];
}
// start
value = [properties objectForKey: MAPIPropertyKey (PidLidTaskStartDate)];
if (value)
{
date = (iCalDateTime *) [vToDo uniqueChildWithTag: @"dtstart"];
[date setTimeZone: tz];
[date setDateTime: value];
}
// due
value = [properties objectForKey: MAPIPropertyKey (PidLidTaskDueDate)];
if (value)
{
date = (iCalDateTime *) [vToDo uniqueChildWithTag: @"due"];
[date setTimeZone: tz];
[date setDateTime: value];
}
// completed
value = [properties objectForKey: MAPIPropertyKey (PidLidTaskDateCompleted)];
if (value)
{
date = (iCalDateTime *) [vToDo uniqueChildWithTag: @"completed"];
tzOffset = [[value timeZone] secondsFromGMTForDate: value];
value = [value dateByAddingYears: 0 months: 0 days: 0
hours: 0 minutes: 0
seconds: -tzOffset];
[date setDate: value];
}
// status
value = [properties objectForKey: MAPIPropertyKey (PidLidTaskStatus)];
if (value)
{
switch ([value intValue])
{
case 1: status = @"IN-PROCESS"; break;
case 2: status = @"COMPLETED"; break;
default: status = @"NEEDS-ACTION";
}
[vToDo setStatus: status];
}
// priority
value = [properties 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";
}
[vToDo setPriority: priority];
}
// percent complete
// NOTE: this does not seem to work on Outlook 2003. PidLidPercentComplete's value
// is always set to 0, no matter what value is set in Outlook
value = [properties objectForKey: MAPIPropertyKey (PidLidPercentComplete)];
if (value)
{
doubleValue = [value doubleValue];
[vToDo setPercentComplete:
[NSString stringWithFormat: @"%d", (int) (doubleValue * 100)]];
}
/* privacy */
/* FIXME: this should be combined with the code found in iCalEvent+MAPIStore.m */
value = [properties objectForKey: MAPIPropertyKey(PidLidPrivate)];
if (value)
{
if ([value boolValue])
[vToDo setAccessClass: @"PRIVATE"];
else
[vToDo setAccessClass: @"PUBLIC"];
}
now = [NSCalendarDate date];
if ([sogoObject isNew])
{
[vToDo setCreated: now];
}
[vToDo setTimeStampAsDate: now];
[sogoObject saveComponent: vCalendar];
[self updateVersions];
}
@end
|