From 2784627633fcf5b5a79a9388f4bb7b125ac5c586 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 18 Nov 2010 22:33:44 +0000 Subject: [PATCH] Monotone-Parent: 1421370cce1a786f84922080b2292644feea05d3 Monotone-Revision: d02118b14fd882876d771035790fa70933bbab96 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-11-18T22:33:44 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 + OpenChange/SOGoContactGCSEntry+MAPIStore.h | 34 ++++++++ OpenChange/SOGoContactGCSEntry+MAPIStore.m | 94 ++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 OpenChange/SOGoContactGCSEntry+MAPIStore.h create mode 100644 OpenChange/SOGoContactGCSEntry+MAPIStore.m diff --git a/ChangeLog b/ChangeLog index cff7a77be..4c1e165af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-11-18 Wolfgang Sourdeau + * OpenChange/SOGoContactGCSEntry+MAPIStore.m: new category module. + (setMAPIProperties:) new method that resets the properties on the + current object and update the corresponding record in the database. + * OpenChange/MAPIStoreContext.m (-setPropertiesOfMessage:fromRow:): check the size of the integers on the build platform to invoke the right constructor of NSNumber. diff --git a/OpenChange/SOGoContactGCSEntry+MAPIStore.h b/OpenChange/SOGoContactGCSEntry+MAPIStore.h new file mode 100644 index 000000000..145e455aa --- /dev/null +++ b/OpenChange/SOGoContactGCSEntry+MAPIStore.h @@ -0,0 +1,34 @@ +/* SOGoContactGCSEntry+MAPIStore.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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. + */ + +#ifndef SOGOCONTACTGCSENTRY_MAPISTORE_H +#define SOGOCONTACTGCSENTRY_MAPISTORE_H + +#import + +@interface SOGoContactGCSEntry (MAPIStoreMessage) + +- (void) setMAPIProperties: (NSDictionary *) properties; + +@end + +#endif /* SOGOCONTACTGCSENTRY_MAPISTORE_H */ diff --git a/OpenChange/SOGoContactGCSEntry+MAPIStore.m b/OpenChange/SOGoContactGCSEntry+MAPIStore.m new file mode 100644 index 000000000..2d73e9910 --- /dev/null +++ b/OpenChange/SOGoContactGCSEntry+MAPIStore.m @@ -0,0 +1,94 @@ +/* SOGoContactGCSEntry+MAPIStore.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 +#import +#import + +#import +#import + +#import "SOGoContactGCSEntry+MAPIStore.h" + +#undef DEBUG +#include +#include + +@implementation SOGoContactGCSEntry (MAPIStoreMessage) + +#if (GS_SIZEOF_LONG == 4) +static inline NSNumber * +MAPIPropertyNumber (unsigned long propTag) +{ + return [NSNumber numberWithUnsignedLong: propTag]; +} +#elif (GS_SIZEOF_INT == 4) +static inline NSNumber * +MAPIPropertyNumber (unsigned int propTag) +{ + return [NSNumber numberWithUnsignedInt: propTag]; +} +#else +#error No suitable type for 4 bytes integers +#endif + +- (void) setMAPIProperties: (NSDictionary *) properties +{ + NGVCard *newCard, *oldCard; + id value; + + [self logWithFormat: @"setMAPIProperties: %@", properties]; + + oldCard = [self vCard]; + if (isNew) + newCard = oldCard; + else + { + newCard = [NGVCard new]; + [newCard setUid: [oldCard uid]]; + ASSIGN (card, newCard); + [newCard release]; + } + [newCard setTag: @"vcard"]; + [newCard setVersion: @"3.0"]; + [newCard setProdID: @"-//Inverse inc.//OpenChange+SOGo//EN"]; + [newCard setProfile: @"vCard"]; + + value = [properties + objectForKey: MAPIPropertyNumber (PR_DISPLAY_NAME_UNICODE)]; + if (!value) + value = [properties + objectForKey: MAPIPropertyNumber (PR_DISPLAY_NAME)]; + if (!value) + value = [properties + objectForKey: MAPIPropertyNumber (PR_DISPLAY_NAME)]; + if (value) + [newCard setFn: value]; + + value = [properties objectForKey: MAPIPropertyNumber (0x81b0001f)]; + if (value) + [newCard addEmail: value types: nil]; + + [self save]; +} + +@end