@@ -47,9 +47,10 @@ @implementation NGVCard (ActiveSync)
4747
4848- (NSString *) activeSyncRepresentationInContext : (WOContext *) context
4949{
50+ NSArray *emails, *addresses, *categories, *elements;
5051 CardElement *n, *homeAdr, *workAdr;
51- NSArray *emails, *addresses;
5252 NSMutableString *s;
53+ NSString *url;
5354 id o;
5455
5556 int i;
@@ -65,10 +66,42 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
6566
6667 if ((o = [self workCompany ]))
6768 [s appendFormat: @" <CompanyName xmlns=\" Contacts:\" >%@ </CompanyName>" , [o activeSyncRepresentationInContext: context]];
69+
70+ if ((o = [[self org ] flattenedValueAtIndex: 1 forKey: @" " ]))
71+ [s appendFormat: @" <Department xmlns=\" Contacts:\" >%@ </Department>" , [o activeSyncRepresentationInContext: context]];
72+
73+ categories = [self categories ];
74+
75+ if ([categories count ])
76+ {
77+ [s appendFormat: @" <Categories xmlns=\" Contacts:\" >" ];
78+ for (i = 0 ; i < [categories count ]; i++)
79+ {
80+ [s appendFormat: @" <Category xmlns=\" Contacts:\" >%@ </Category>" , [[categories objectAtIndex: i] activeSyncRepresentationInContext: context]];
81+ }
82+ [s appendFormat: @" </Categories>" ];
83+ }
84+
85+ elements = [self childrenWithTag: @" url"
86+ andAttribute: @" type"
87+ havingValue: @" work" ];
88+ if ([elements count ] > 0 )
89+ {
90+ url = [[elements objectAtIndex: 0 ] flattenedValuesForKey: @" " ];
91+ [s appendFormat: @" <WebPage xmlns=\" Contacts:\" >%@ </WebPage>" , [url activeSyncRepresentationInContext: context]];
92+ }
93+
94+
95+ if ((o = [[self uniqueChildWithTag: @" x-aim" ] flattenedValuesForKey: @" " ]))
96+ [s appendFormat: @" <IMAddress xmlns=\" Contacts:\" >%@ </IMAddress>" , [o activeSyncRepresentationInContext: context]];
97+
98+ if ((o = [self nickname ]))
99+ [s appendFormat: @" <NickName xmlns=\" Contacts:\" >%@ </NickName>" , [o activeSyncRepresentationInContext: context]];
100+
68101
69102 if ((o = [self title ]))
70103 [s appendFormat: @" <JobTitle xmlns=\" Contacts:\" >%@ </JobTitle>" , [o activeSyncRepresentationInContext: context]];
71-
104+
72105 if ((o = [self preferredEMail ]))
73106 [s appendFormat: @" <Email1Address xmlns=\" Contacts:\" >%@ </Email1Address>" , o];
74107
@@ -154,7 +187,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
154187
155188 // Other, less important fields
156189 if ((o = [self birthday ]))
157- [s appendFormat: @" <Birthday xmlns=\" Contacts:\" >%@ </Birthday>" , [o activeSyncRepresentationWithoutSeparatorsInContext : context]];
190+ [s appendFormat: @" <Birthday xmlns=\" Contacts:\" >%@ </Birthday>" , [o activeSyncRepresentationInContext : context]];
158191
159192 if ((o = [self note ]))
160193 {
@@ -183,6 +216,10 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues
183216 if ((o = [[theValues objectForKey: @" Body" ] objectForKey: @" Data" ]))
184217 [self setNote: o];
185218
219+ // Categories
220+ if ((o = [theValues objectForKey: @" Categories" ]))
221+ [self setCategories: o];
222+
186223 // Birthday
187224 if ((o = [theValues objectForKey: @" Birthday" ]))
188225 {
@@ -238,24 +275,31 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues
238275
239276 // Company's name
240277 if ((o = [theValues objectForKey: @" CompanyName" ]))
241- {
242- [self setOrg: o units: nil ];
243- }
278+ [self setOrg: o units: nil ];
279+
280+ // Department
281+ if ((o = [theValues objectForKey: @" Department" ]))
282+ [self setOrg: nil units: [NSArray arrayWithObjects: o,nil ]];
244283
245284 // Email addresses
246285 if ((o = [theValues objectForKey: @" Email1Address" ]))
247286 {
248- [self addEmail: o types: [NSArray arrayWithObject: @" pref" ]];
287+ element = [self elementWithTag: @" email" ofType: @" work" ];
288+ [element setSingleValue: o forKey: @" " ];
249289 }
250290
251291 if ((o = [theValues objectForKey: @" Email2Address" ]))
252292 {
253- [self addEmail: o types: nil ];
293+ element = [self elementWithTag: @" email" ofType: @" home" ];
294+ [element setSingleValue: o forKey: @" " ];
254295 }
255296
297+ // SOGo currently only supports 2 email addresses ... but AS clients might send 3
298+ // FIXME: revise this when the GUI revamp is done in SOGo
256299 if ((o = [theValues objectForKey: @" Email3Address" ]))
257300 {
258- [self addEmail: o types: nil ];
301+ element = [self elementWithTag: @" email" ofType: @" three" ];
302+ [element setSingleValue: o forKey: @" " ];
259303 }
260304
261305 // Formatted name
@@ -293,16 +337,15 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues
293337
294338 // Job's title
295339 if ((o = [theValues objectForKey: @" JobTitle" ]))
296- {
297- [self setTitle: o];
298- }
340+ [self setTitle: o];
299341
300342 // WebPage (work)
301343 if ((o = [theValues objectForKey: @" WebPage" ]))
302- {
303- [[self elementWithTag: @" url" ofType: @" work" ]
344+ [[self elementWithTag: @" url" ofType: @" work" ]
304345 setSingleValue: o forKey: @" " ];
305- }
346+
347+ if ((o = [theValues objectForKey: @" NickName" ]))
348+ [self setNickname: o];
306349}
307350
308351@end
0 commit comments