From 89400fe980515687a658e4f0a88885d9ba323df8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 21 Apr 2017 15:29:34 -0400 Subject: [PATCH] (feat) added photo support in GAL search ops --- ActiveSync/SOGoActiveSyncDispatcher.m | 62 +++++++++++++++++--- Documentation/SOGoInstallationGuide.asciidoc | 6 ++ SoObjects/SOGo/SOGoSystemDefaults.h | 1 + SoObjects/SOGo/SOGoSystemDefaults.m | 15 +++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index fc8a143a8..0094f8210 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -2785,7 +2785,7 @@ void handle_eas_terminate(int signum) inResponse: (WOResponse *) theResponse { SOGoContactSourceFolder *currentFolder; - NSArray *allKeys, *allContacts, *mails; + NSArray *allKeys, *allContacts, *mails, *a; NSDictionary *systemSources, *contact; SOGoContactFolders *contactFolders; NSString *current_mail, *query; @@ -2795,7 +2795,10 @@ void handle_eas_terminate(int signum) NSData *d; id o; - int i, j, total; + int i, j, t, v, total, minResult, maxResult, maxSize, maxPictures; + BOOL withPhoto; + + withPhoto = NO; query = [[(id)[theDocumentElement getElementsByTagName: @"Query"] lastObject] textValue]; @@ -2804,6 +2807,33 @@ void handle_eas_terminate(int signum) systemSources = [contactFolders systemSources]; allKeys = [systemSources allKeys]; + // We check for the maximum number of results to return. + a = [[[(id)[theDocumentElement getElementsByTagName: @"Range"] lastObject] textValue] componentsSeparatedByString: @"-"]; + minResult = [[a objectAtIndex: 0] intValue]; + maxResult = [[a objectAtIndex: 1] intValue]; + + if (maxResult == 0) + maxResult = 99; + + if ((o = [(id)[[(id)[theDocumentElement getElementsByTagName: @"Options"] lastObject] getElementsByTagName: @"Picture"] lastObject])) + { + withPhoto = YES; + + // We check for a MaxSize, default to 102400. + maxSize = [[[(id)[o getElementsByTagName: @"MaxSize"] lastObject] textValue] intValue]; + + // We check if we must overwrite the maxSize with a system preference. This can be useful + // if we don't want to have pictures in the response. + if ((v = [[SOGoSystemDefaults sharedSystemDefaults] maximumPictureSize])) + maxSize = v; + + // We check for a MaxPictures, default to 99. + maxPictures = [[[(id)[o getElementsByTagName: @"MaxPictures"] lastObject] textValue] intValue]; + + if (maxPictures == 0) + maxPictures = 99; + } + s = [NSMutableString string]; [s appendString: @""]; @@ -2825,7 +2855,7 @@ void handle_eas_terminate(int signum) ordering: NSOrderedAscending inDomain: [[context activeUser] domain]]; - for (j = 0; j < [allContacts count]; j++) + for (j = minResult; (j < [allContacts count] && j < maxResult) ; j++) { contact = [allContacts objectAtIndex: j]; @@ -2843,9 +2873,9 @@ void handle_eas_terminate(int signum) else mails = [NSArray arrayWithObjects: o ? o : @"", nil]; - for (total = 0; total < [mails count]; total++) + for (t = 0; t < [mails count]; t++) { - current_mail = [mails objectAtIndex: total]; + current_mail = [mails objectAtIndex: t]; [s appendString: @""]; [s appendString: @""]; @@ -2863,7 +2893,7 @@ void handle_eas_terminate(int signum) [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; if ([current_mail length] > 0) - [s appendFormat: @"%@", current_mail]; + [s appendFormat: @"%@", [current_mail activeSyncRepresentationInContext: context]]; if ((o = [contact objectForKey: @"telephonenumber"])) [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; @@ -2876,9 +2906,27 @@ void handle_eas_terminate(int signum) if ((o = [contact objectForKey: @"o"])) [s appendFormat: @"%@", [o activeSyncRepresentationInContext: context]]; - + + if ([[context objectForKey: @"ASProtocolVersion"] floatValue] >= 14.1 && withPhoto) + { + o = [contact objectForKey: @"photo"]; + if (o && [o length] <= maxSize && total < maxPictures) + { + [s appendString: @"1"]; + [s appendString: [o activeSyncRepresentationInContext: context]]; + [s appendString: @""]; + } + else if (!o) + [s appendString: @"173"]; + else if ([o length] > maxSize) + [s appendString: @"174"]; + else if (total >= maxPictures) + [s appendString: @"175"]; + } + [s appendString: @""]; [s appendString: @""]; + total++; } } } diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index 4f32b1d1f..7e8e11aa0 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -2545,6 +2545,12 @@ have unexpected behaviour with various ActiveSync clients. EAS command. Defaults to `NO`, which means no logging is performed. + +|S |SOGoMaximumPictureSize +|Parameter used to overwrite the maximum number of bytes returned in the picture +for EAS Search operations in the GAL. + +If not set, it defaults to `102400` bytes, or 100 KB. |======================================================================= Please be aware of the following limitations: diff --git a/SoObjects/SOGo/SOGoSystemDefaults.h b/SoObjects/SOGo/SOGoSystemDefaults.h index d6a2f7f22..5a9c8dff3 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.h +++ b/SoObjects/SOGo/SOGoSystemDefaults.h @@ -109,6 +109,7 @@ - (int) internalSyncInterval; - (int) maximumSyncWindowSize; - (int) maximumSyncResponseSize; +- (int) maximumPictureSize; @end diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index 5fee77b54..161083553 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -699,4 +699,19 @@ _injectConfigurationFromFile (NSMutableDictionary *defaultsDict, return v; } +// +// See https://msdn.microsoft.com/en-us/library/gg672032(v=exchg.80).aspx +// +- (int) maximumPictureSize +{ + int v; + + v = [self integerForKey: @"SOGoMaximumPictureSize"]; + + if (!v) + v = 102400; + + return v; +} + @end